From e0d4db6dab50789d2622c7f1dd59b3c8d120811c Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Sat, 17 Sep 2022 20:57:58 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20V=C3=ADc=20informac=C3=AD?= =?UTF-8?q?=20v=20objektech?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klient/play.py | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/klient/play.py b/klient/play.py index 85e00a0..47b4b0f 100755 --- a/klient/play.py +++ b/klient/play.py @@ -4,9 +4,6 @@ import sys from typing import Callable, Iterable, List, Optional, Tuple -Coords = Tuple[int, int] - - class State: def __init__(self, state: dict) -> None: self.world = parse_world(state["state"]["world"]) @@ -14,25 +11,27 @@ class State: self.round_number: int = state["round"] +state: State = None + + class Member: - def __init__(self, team: int, id: int, remaining_rounds: int): + def __init__(self, field: 'Field', team: int, id: int): + self.field = field, self.team = team self.id = id - self.remaining_rounds = remaining_rounds self.action: Optional[str] = None class Field: - def __init__(self, home_for_team: Optional[int], - occupied_by_team: Optional[int], - hill: bool, members: List[Member]): + def __init__(self, i: int, j: int, hill: bool, + home_for_team: Optional[int], + occupied_by_team: Optional[int]): + self.i = i + self.j = j + self.hill = hill self.home_for_team = home_for_team self.occupied_by_team = occupied_by_team - self.hill = hill - self.members = members - - -state: State = None + self.members: List[Member] = None def main() -> None: @@ -50,7 +49,7 @@ def main() -> None: def find_fields( predicate: Callable[[Field], bool] -) -> List[Tuple[Field, Coords]]: +) -> List[Tuple[Field]]: """Find all fields that satisfy the given predicate.""" result = [] @@ -84,22 +83,26 @@ def build_turn(members: Iterable[Member]) -> dict: def parse_world(world: dict) -> List[List[Field]]: fields = [] - for row in world: + for i, row in enumerate(world): fields_row = [] - for field in row: + for j, field in enumerate(row): + parsed_field = Field( + i, j, + field["hill"], + field["home_for_team"], + field["occupied_by_team"], + members + ) + fields.append(parsed_field) members = [] for member in field["members"]: members.append(Member( + parsed_field, member["team"], member["id"], - member["remaining_rounds"] )) - fields_row.append(Field( - field["home_for_team"], - field["occupied_by_team"], - field["hill"], - members - )) + parsed_field.members = members + fields.append(fields_row) return fields