From b9ebbbcc303c9df0a06eeecf54eb3af3bb19c55e Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Fri, 23 Sep 2022 10:50:31 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Vy=C5=99e=C5=A1it=20mypy=20?= =?UTF-8?q?chyby?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klient/client.py | 5 ++--- klient/play.py | 27 ++++++++++++++++----------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/klient/client.py b/klient/client.py index 8982c06..d80002e 100755 --- a/klient/client.py +++ b/klient/client.py @@ -31,9 +31,8 @@ logger = logging.getLogger("client") def main(args: argparse.Namespace) -> None: logger.setLevel(args.log_level.upper()) min_round = 0 - program = None if args.save_state is None: - program = get_command(args) + command = get_command(args) while True: state = get_state(min_round, args) @@ -49,7 +48,7 @@ def main(args: argparse.Namespace) -> None: return turn_json = run_subprocess( - program, json.dumps(state), state["time_to_response"] + command, json.dumps(state), state["time_to_response"] ) if turn_json is None: continue diff --git a/klient/play.py b/klient/play.py index d462ada..ce22b3c 100755 --- a/klient/play.py +++ b/klient/play.py @@ -36,13 +36,15 @@ class Team: home: Field def __init__(self, id: int, is_me: bool) -> None: - self.id: int = id + self.id = id self.is_me = is_me self.protected_fields: List[Field] = [] self.occupied: List[Field] = [] self.members: List[Member] = [] - def __eq__(self, other: Field) -> bool: + def __eq__(self, other: object) -> bool: + if not isinstance(other, Team): + return NotImplemented return (self.id) == (other.id) def __hash__(self) -> int: @@ -50,7 +52,7 @@ class Team: class Member: - def __init__(self, field: Field, team: int, id: int) -> None: + def __init__(self, field: Field, team: Team, id: int) -> None: self.field = field self.team = team self.id = id @@ -64,14 +66,16 @@ class Field: home_for_team: Optional[Team], occupied_by_team: Optional[Team], protected_for_team: Optional[Team],) -> None: - self.i: int = i - self.j: int = j - self.hill: bool = hill + self.i = i + self.j = j + self.hill = hill self.home_for_team: Optional[Team] = home_for_team self.occupied_by_team: Optional[Team] = occupied_by_team self.protected_for_team: Optional[Team] = protected_for_team - def __eq__(self, other: Field) -> bool: + def __eq__(self, other: object) -> bool: + if not isinstance(other, Field): + return NotImplemented return (self.i, self.j) == (other.i, other.j) def __hash__(self) -> int: @@ -126,7 +130,7 @@ class State: self.time_to_response: Optional[int] = state["time_to_response"] def _parse_world(self, world: dict) -> List[List[Field]]: - def get_team(team_id): + def get_team(team_id: int) -> Optional[Team]: return None if team_id is None else self.teams[team_id] fields = [] @@ -148,13 +152,14 @@ class State: parsed_field.protected_for_team.protected_fields.append(parsed_field) members = [] for member in field["members"]: + member_team = self.teams[member["team_id"]] m = Member( parsed_field, - self.teams[member["team"]], + member_team, member["id"], ) members.append(m) - m.team.members.append(m) + member_team.members.append(m) parsed_field.members = members fields_row.append(parsed_field) @@ -227,7 +232,7 @@ def main() -> None: # TODO: zde doplňte svou herní strategii # příklad: všechny vojáky posílám nahoru - for member in state.teams[state.my_team].members: + for member in state.my_team.members: member.action = Direction.UP print(json.dumps(state.build_turn()))