Strategická: Lepší enum akcí
This commit is contained in:
parent
626f29f7fd
commit
1808d89e14
1 changed files with 13 additions and 8 deletions
|
@ -1,18 +1,18 @@
|
|||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
from enum import Enum
|
||||
from typing import Callable, Iterable, Optional, List, Set
|
||||
import collections
|
||||
import enum
|
||||
import json
|
||||
import sys
|
||||
|
||||
|
||||
class Action(Enum):
|
||||
UP = "up"
|
||||
DOWN = "down"
|
||||
LEFT = "left"
|
||||
RIGHT = "right"
|
||||
STAY = None
|
||||
class Action(enum.Enum):
|
||||
UP = enum.auto()
|
||||
DOWN = enum.auto()
|
||||
LEFT = enum.auto()
|
||||
RIGHT = enum.auto()
|
||||
STAY = enum.auto()
|
||||
|
||||
def invert(self) -> Action:
|
||||
if self == Action.UP:
|
||||
|
@ -25,6 +25,11 @@ class Action(Enum):
|
|||
return Action.LEFT
|
||||
return Action.STAY
|
||||
|
||||
def to_json(self) -> Optional[str]:
|
||||
if self == Action.STAY:
|
||||
return None
|
||||
return self.name.lower()
|
||||
|
||||
|
||||
class State:
|
||||
def __init__(self, state: dict) -> None:
|
||||
|
@ -157,7 +162,7 @@ def pathfind(member: Member, goal: Field) -> Action:
|
|||
def build_turn(members: Iterable[Member]) -> dict:
|
||||
return {
|
||||
"members": [
|
||||
{"id": member.id, "action": member.action}
|
||||
{"id": member.id, "action": member.action.to_json()}
|
||||
for member in members
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue