Strategická: Akce
This commit is contained in:
parent
3e9fa79305
commit
f4f6ffd021
1 changed files with 49 additions and 10 deletions
|
@ -1,7 +1,17 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from typing import Callable, Iterable, List, Optional, Tuple
|
from __future__ import annotations
|
||||||
|
from enum import Enum
|
||||||
|
from typing import Callable, Iterable, List, Optional
|
||||||
|
|
||||||
|
|
||||||
|
class Action(Enum):
|
||||||
|
UP = "up"
|
||||||
|
DOWN = "down"
|
||||||
|
LEFT = "left"
|
||||||
|
RIGHT = "right"
|
||||||
|
STAY = None
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
|
@ -11,18 +21,20 @@ class State:
|
||||||
self.round_number: int = state["round"]
|
self.round_number: int = state["round"]
|
||||||
|
|
||||||
|
|
||||||
state: State = None
|
state: State
|
||||||
|
|
||||||
|
|
||||||
class Member:
|
class Member:
|
||||||
def __init__(self, field: 'Field', team: int, id: int):
|
def __init__(self, field: Field, team: int, id: int):
|
||||||
self.field = field,
|
self.field = field,
|
||||||
self.team = team
|
self.team = team
|
||||||
self.id = id
|
self.id = id
|
||||||
self.action: Optional[str] = None
|
self.action = Action.STAY
|
||||||
|
|
||||||
|
|
||||||
class Field:
|
class Field:
|
||||||
|
members: List[Member]
|
||||||
|
|
||||||
def __init__(self, i: int, j: int, hill: bool,
|
def __init__(self, i: int, j: int, hill: bool,
|
||||||
home_for_team: Optional[int],
|
home_for_team: Optional[int],
|
||||||
occupied_by_team: Optional[int]):
|
occupied_by_team: Optional[int]):
|
||||||
|
@ -31,7 +43,36 @@ class Field:
|
||||||
self.hill = hill
|
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.members: List[Member] = None
|
|
||||||
|
def get_neighbour_field(self, action: Action) -> Field:
|
||||||
|
if action == Action.UP:
|
||||||
|
neighbour_i = self.i - 1
|
||||||
|
neighbour_j = self.j
|
||||||
|
elif action == Action.DOWN:
|
||||||
|
neighbour_i = self.i + 1
|
||||||
|
neighbour_j = self.j
|
||||||
|
elif action == Action.LEFT:
|
||||||
|
neighbour_i = self.i
|
||||||
|
neighbour_j = self.j - 1
|
||||||
|
elif action == Action.RIGHT:
|
||||||
|
neighbour_i = self.i
|
||||||
|
neighbour_j = self.j + 1
|
||||||
|
else:
|
||||||
|
neighbour_i = self.i
|
||||||
|
neighbour_j = self.j
|
||||||
|
# ensure coords are in bounds
|
||||||
|
neighbour_i %= len(state.world),
|
||||||
|
neighbour_j %= len(state.world[0])
|
||||||
|
return state.world[neighbour_i][neighbour_j]
|
||||||
|
|
||||||
|
def is_accessible(self, team: int) -> bool:
|
||||||
|
"""If this field is accessible for the given team."""
|
||||||
|
|
||||||
|
if self.hill:
|
||||||
|
return False
|
||||||
|
if self.home_for_team is not None and self.home_for_team != team:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
@ -42,14 +83,12 @@ def main() -> None:
|
||||||
# TODO: set actions for all members
|
# TODO: set actions for all members
|
||||||
# example: all members go up
|
# example: all members go up
|
||||||
for member in my_members:
|
for member in my_members:
|
||||||
member.action = "up"
|
member.action = Action.UP
|
||||||
|
|
||||||
print(json.dumps(build_turn(my_members)))
|
print(json.dumps(build_turn(my_members)))
|
||||||
|
|
||||||
|
|
||||||
def find_fields(
|
def find_fields(predicate: Callable[[Field], bool]) -> List[Field]:
|
||||||
predicate: Callable[[Field], bool]
|
|
||||||
) -> List[Tuple[Field]]:
|
|
||||||
"""Find all fields that satisfy the given predicate."""
|
"""Find all fields that satisfy the given predicate."""
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
@ -60,7 +99,7 @@ def find_fields(
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def find_team_members(team_id: int) -> List[Tuple[Member]]:
|
def find_team_members(team_id: int) -> List[Member]:
|
||||||
"""Find all members that belong to the given team."""
|
"""Find all members that belong to the given team."""
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
|
Loading…
Reference in a new issue