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()
STAY = enum.auto()
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
_inversions = {
UP: DOWN,
DOWN: UP,
LEFT: RIGHT,
RIGHT: LEFT,
STAY: STAY,
}
def to_json(self) -> Optional[str]:
if self == Action.STAY:
return None
def invert(self) -> Action:
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
]
}

View file

@ -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),