Strategická: stay místo None

This commit is contained in:
David Klement 2022-09-18 15:08:55 +02:00
parent 67cd40a3f0
commit 443d1b99fe
2 changed files with 13 additions and 15 deletions

View file

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

View file

@ -27,7 +27,7 @@ class Logic:
@add_logic @add_logic
class Occupy(Logic): class Occupy(Logic):
MOVE_VECTORS = { MOVE_VECTORS = {
None: (0, 0), "stay": (0, 0),
"left": (0, -1), "left": (0, -1),
"right": (0, 1), "right": (0, 1),
"up": (-1, 0), "up": (-1, 0),