|
@ -1,18 +1,18 @@ |
|
|
#!/usr/bin/env python3 |
|
|
#!/usr/bin/env python3 |
|
|
from __future__ import annotations |
|
|
from __future__ import annotations |
|
|
from enum import Enum |
|
|
|
|
|
from typing import Callable, Iterable, Optional, List, Set |
|
|
from typing import Callable, Iterable, Optional, List, Set |
|
|
import collections |
|
|
import collections |
|
|
|
|
|
import enum |
|
|
import json |
|
|
import json |
|
|
import sys |
|
|
import sys |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Action(Enum): |
|
|
class Action(enum.Enum): |
|
|
UP = "up" |
|
|
UP = enum.auto() |
|
|
DOWN = "down" |
|
|
DOWN = enum.auto() |
|
|
LEFT = "left" |
|
|
LEFT = enum.auto() |
|
|
RIGHT = "right" |
|
|
RIGHT = enum.auto() |
|
|
STAY = None |
|
|
STAY = enum.auto() |
|
|
|
|
|
|
|
|
def invert(self) -> Action: |
|
|
def invert(self) -> Action: |
|
|
if self == Action.UP: |
|
|
if self == Action.UP: |
|
@ -25,6 +25,11 @@ class Action(Enum): |
|
|
return Action.LEFT |
|
|
return Action.LEFT |
|
|
return Action.STAY |
|
|
return Action.STAY |
|
|
|
|
|
|
|
|
|
|
|
def to_json(self) -> Optional[str]: |
|
|
|
|
|
if self == Action.STAY: |
|
|
|
|
|
return None |
|
|
|
|
|
return self.name.lower() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class State: |
|
|
class State: |
|
|
def __init__(self, state: dict) -> None: |
|
|
def __init__(self, state: dict) -> None: |
|
@ -157,7 +162,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} |
|
|
{"id": member.id, "action": member.action.to_json()} |
|
|
for member in members |
|
|
for member in members |
|
|
] |
|
|
] |
|
|
} |
|
|
} |
|
|