|
|
@ -14,20 +14,18 @@ class Action(enum.Enum): |
|
|
|
RIGHT = enum.auto() |
|
|
|
STAY = enum.auto() |
|
|
|
|
|
|
|
_inversions = { |
|
|
|
UP: DOWN, |
|
|
|
DOWN: UP, |
|
|
|
LEFT: RIGHT, |
|
|
|
RIGHT: LEFT, |
|
|
|
STAY: STAY, |
|
|
|
} |
|
|
|
|
|
|
|
def invert(self) -> Action: |
|
|
|
if self == Action.UP: |
|
|
|
return Action.DOWN |
|
|
|
if self == Action.DOWN: |
|
|
|
return Action.UP |
|
|
|
if self == Action.LEFT: |
|
|
|
return Action.RIGHT |
|
|
|
if self == Action.RIGHT: |
|
|
|
return Action.LEFT |
|
|
|
return Action.STAY |
|
|
|
|
|
|
|
def to_json(self) -> Optional[str]: |
|
|
|
if self == Action.STAY: |
|
|
|
return None |
|
|
|
return self._inversions[self] |
|
|
|
|
|
|
|
def __str__(self) -> str: |
|
|
|
return self.name.lower() |
|
|
|
|
|
|
|
|
|
|
@ -165,7 +163,7 @@ def pathfind(member: Member, goal: Field) -> Action: |
|
|
|
def build_turn(members: Iterable[Member]) -> dict: |
|
|
|
return { |
|
|
|
"members": [ |
|
|
|
{"id": member.id, "action": member.action.to_json()} |
|
|
|
{"id": member.id, "action": str(member.action)} |
|
|
|
for member in members |
|
|
|
] |
|
|
|
} |
|
|
|