Skip to content

Commit bfea897

Browse files
authored
Python Starter bot - приведение к int для map_size (#6)
* Python bot init talks with server * Python talk with server up to started match * Python starter bot client done * - Fixed socket read buffer - Named tuple XY and BotInfo * - Revert back to dataclasses (faster) * - Socket - skip server round data to stay in sync * - README - bot comments - optimized Socket performance * - more Type annotations * - fixed map size XY type (str -> int) * better str -> int type conversion
1 parent 5444357 commit bfea897

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

starter-bot-python/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class Bot(BotBase):
1212
# Старт
13-
def on_match_start(self, match_info: MatchStarted):
13+
def on_match_start(self, match_info: MatchStarted) -> None:
1414
# Правила матча
1515
self.match_info = match_info
1616
self.id = match_info.your_id

starter-bot-python/client/bot_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class BotBase:
1616
match_info: MatchStarted = field(init=False)
1717
id: int = field(init=False)
1818

19-
def on_match_start(self, match_info: MatchStarted):
19+
def on_match_start(self, match_info: MatchStarted) -> None:
2020
raise NotImplementedError
2121

2222
def on_update(self, update: Update) -> tuple[int, int]:

starter-bot-python/client/message/extra_types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ class XY:
1212
x: int
1313
y: int
1414

15+
def __post_init__(self):
16+
self.x = int(self.x)
17+
self.y = int(self.y)
18+
1519

1620
@dataclass
1721
class BotInfo(XY):
1822
coins: int
1923
id: int
24+
25+
def __post_init__(self):
26+
super().__post_init__()
27+
self.coins = int(self.coins)
28+
self.id = int(self.id)

starter-bot-python/client/message/factory.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def load(cls, data: list[str]) -> Message:
3838
if container is None:
3939
params[name] = real_type(*value)
4040
elif container is list:
41-
# map(int, ) assumes that all nested types has only int fields
42-
params[name].append(real_type(*map(int, value)))
41+
params[name].append(real_type(*value))
4342
else:
4443
raise Exception(f'cannot handle {command}:{name}:{container}')
4544

starter-bot-python/client/socket_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def read(self) -> list[str]:
2929

3030
return data.decode().split('\n')
3131

32-
def _find_end_index(self):
32+
def _find_end_index(self) -> int:
3333
return self.buffer.find(b'end\n', len(self.buffer) - self._buffer_size)
3434

3535
def write(self, data: str) -> None:

0 commit comments

Comments
 (0)