|
|
@ -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 |
|
|
|
|
|
|
|