Browse Source

Strategická: stay místo None

master
David Klement 2 years ago
parent
commit
443d1b99fe
  1. 24
      klient/play.py
  2. 2
      server/hra/game.py

24
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
return self._inversions[self]
def to_json(self) -> Optional[str]:
if self == Action.STAY:
return None
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
]
}

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

Loading…
Cancel
Save