|
|
@ -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 |
|
|
|
] |
|
|
|
} |
|
|
|