|
|
@ -17,9 +17,13 @@ class Direction(enum.Enum): |
|
|
|
STAY = None |
|
|
|
|
|
|
|
def combine(self, other) -> Direction: |
|
|
|
return Direction((self.value + other.value)%4) |
|
|
|
"""Rotate by another direction.""" |
|
|
|
|
|
|
|
return Direction((self.value + other.value) % 4) |
|
|
|
|
|
|
|
def invert(self) -> Direction: |
|
|
|
"""Get the opposite direction.""" |
|
|
|
|
|
|
|
if self == Direction.STAY: |
|
|
|
return self |
|
|
|
return self.combine(Direction.DOWN) |
|
|
@ -29,7 +33,7 @@ class Direction(enum.Enum): |
|
|
|
|
|
|
|
|
|
|
|
class Team: |
|
|
|
home: 'Field' |
|
|
|
home: Field |
|
|
|
|
|
|
|
def __init__(self, id: int, is_me: bool) -> None: |
|
|
|
self.id: int = id |
|
|
@ -74,6 +78,8 @@ class Field: |
|
|
|
return hash((self.i, self.j)) |
|
|
|
|
|
|
|
def get_neighbour_field(self, action: Direction) -> Field: |
|
|
|
"""Get the next field in the given direction.""" |
|
|
|
|
|
|
|
if action == Direction.UP: |
|
|
|
neighbour_i = self.i - 1 |
|
|
|
neighbour_j = self.j |
|
|
@ -95,7 +101,7 @@ class Field: |
|
|
|
return state.world[neighbour_i][neighbour_j] |
|
|
|
|
|
|
|
def is_accessible(self, team: Team) -> bool: |
|
|
|
"""If this field is accessible for the given team.""" |
|
|
|
"""Jestli daný tým může vstoupit na políčko.""" |
|
|
|
|
|
|
|
if self.hill: |
|
|
|
return False |
|
|
@ -104,11 +110,16 @@ class Field: |
|
|
|
return False |
|
|
|
return True |
|
|
|
|
|
|
|
# Celý stav hry včetně parsování a vypisování |
|
|
|
|
|
|
|
class State: |
|
|
|
"""The entire game state. |
|
|
|
|
|
|
|
Also contains methods for parsing and actions submission. |
|
|
|
""" |
|
|
|
|
|
|
|
def __init__(self, state: dict) -> None: |
|
|
|
self.teams = [Team(i, i==state["team_id"]) for i in range(state["teams_count"])] |
|
|
|
self.teams = [Team(i, i == state["team_id"]) |
|
|
|
for i in range(state["teams_count"])] |
|
|
|
self.world = self._parse_world(state["state"]["world"]) |
|
|
|
self.my_team: Team = self.teams[state["team_id"]] |
|
|
|
self.round_number: int = state["round"] |
|
|
@ -150,8 +161,9 @@ class State: |
|
|
|
fields.append(fields_row) |
|
|
|
return fields |
|
|
|
|
|
|
|
|
|
|
|
def build_turn(self) -> dict: |
|
|
|
"""Build a dictionary with member actions.""" |
|
|
|
|
|
|
|
for team in self.teams: |
|
|
|
if not team.is_me: |
|
|
|
for member in team.members: |
|
|
@ -164,10 +176,12 @@ class State: |
|
|
|
] |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
state: State |
|
|
|
|
|
|
|
# Algoritmy |
|
|
|
|
|
|
|
|
|
|
|
def find_fields(predicate: Callable[[Field], bool]) -> List[Field]: |
|
|
|
"""Find all fields that satisfy the given predicate.""" |
|
|
|
|
|
|
@ -203,18 +217,21 @@ def pathfind(member: Member, goal: Field) -> Direction: |
|
|
|
explored.add(neighbour) |
|
|
|
return Direction.STAY |
|
|
|
|
|
|
|
# main (zde doplňte kód) |
|
|
|
|
|
|
|
# Strategie |
|
|
|
|
|
|
|
|
|
|
|
def main() -> None: |
|
|
|
global state |
|
|
|
state = State(json.loads(sys.stdin.read())) |
|
|
|
|
|
|
|
# TODO: set actions for all yours members |
|
|
|
# example: all members go up |
|
|
|
for member in state.teams[1].members: |
|
|
|
# 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: |
|
|
|
member.action = Direction.UP |
|
|
|
|
|
|
|
print(json.dumps(state.build_turn())) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
main() |
|
|
|