|
@ -4,9 +4,6 @@ import sys |
|
|
from typing import Callable, Iterable, List, Optional, Tuple |
|
|
from typing import Callable, Iterable, List, Optional, Tuple |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Coords = Tuple[int, int] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class State: |
|
|
class State: |
|
|
def __init__(self, state: dict) -> None: |
|
|
def __init__(self, state: dict) -> None: |
|
|
self.world = parse_world(state["state"]["world"]) |
|
|
self.world = parse_world(state["state"]["world"]) |
|
@ -14,25 +11,27 @@ class State: |
|
|
self.round_number: int = state["round"] |
|
|
self.round_number: int = state["round"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state: State = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Member: |
|
|
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.team = team |
|
|
self.id = id |
|
|
self.id = id |
|
|
self.remaining_rounds = remaining_rounds |
|
|
|
|
|
self.action: Optional[str] = None |
|
|
self.action: Optional[str] = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Field: |
|
|
class Field: |
|
|
def __init__(self, home_for_team: Optional[int], |
|
|
def __init__(self, i: int, j: int, hill: bool, |
|
|
occupied_by_team: Optional[int], |
|
|
home_for_team: Optional[int], |
|
|
hill: bool, members: List[Member]): |
|
|
occupied_by_team: Optional[int]): |
|
|
|
|
|
self.i = i |
|
|
|
|
|
self.j = j |
|
|
|
|
|
self.hill = hill |
|
|
self.home_for_team = home_for_team |
|
|
self.home_for_team = home_for_team |
|
|
self.occupied_by_team = occupied_by_team |
|
|
self.occupied_by_team = occupied_by_team |
|
|
self.hill = hill |
|
|
self.members: List[Member] = None |
|
|
self.members = members |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state: State = None |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main() -> None: |
|
|
def main() -> None: |
|
@ -50,7 +49,7 @@ def main() -> None: |
|
|
|
|
|
|
|
|
def find_fields( |
|
|
def find_fields( |
|
|
predicate: Callable[[Field], bool] |
|
|
predicate: Callable[[Field], bool] |
|
|
) -> List[Tuple[Field, Coords]]: |
|
|
) -> List[Tuple[Field]]: |
|
|
"""Find all fields that satisfy the given predicate.""" |
|
|
"""Find all fields that satisfy the given predicate.""" |
|
|
|
|
|
|
|
|
result = [] |
|
|
result = [] |
|
@ -84,22 +83,26 @@ def build_turn(members: Iterable[Member]) -> dict: |
|
|
|
|
|
|
|
|
def parse_world(world: dict) -> List[List[Field]]: |
|
|
def parse_world(world: dict) -> List[List[Field]]: |
|
|
fields = [] |
|
|
fields = [] |
|
|
for row in world: |
|
|
for i, row in enumerate(world): |
|
|
fields_row = [] |
|
|
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 = [] |
|
|
members = [] |
|
|
for member in field["members"]: |
|
|
for member in field["members"]: |
|
|
members.append(Member( |
|
|
members.append(Member( |
|
|
|
|
|
parsed_field, |
|
|
member["team"], |
|
|
member["team"], |
|
|
member["id"], |
|
|
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) |
|
|
fields.append(fields_row) |
|
|
return fields |
|
|
return fields |
|
|
|
|
|
|
|
|