diff --git a/klient/play.py b/klient/play.py index 576ad3e..b1667b9 100755 --- a/klient/play.py +++ b/klient/play.py @@ -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 ] } diff --git a/server/hra/game.py b/server/hra/game.py index d4e5bf1..c4358a1 100644 --- a/server/hra/game.py +++ b/server/hra/game.py @@ -27,7 +27,7 @@ class Logic: @add_logic class Occupy(Logic): MOVE_VECTORS = { - None: (0, 0), + "stay": (0, 0), "left": (0, -1), "right": (0, 1), "up": (-1, 0),