From 1808d89e14612e5b82f55bb407a581b12c7e4ea8 Mon Sep 17 00:00:00 2001 From: kulisak12 Date: Sun, 18 Sep 2022 11:51:05 +0200 Subject: [PATCH] =?UTF-8?q?Strategick=C3=A1:=20Lep=C5=A1=C3=AD=20enum=20ak?= =?UTF-8?q?c=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- klient/play.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/klient/play.py b/klient/play.py index 4b12aba..5ebbbd7 100755 --- a/klient/play.py +++ b/klient/play.py @@ -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 ] }