Browse Source

Strategická: Dodělání abstraktní třídy pro herní logiku

master
Jiří Kalvoda 2 years ago
parent
commit
3cb438254b
  1. 27
      server/hra/game.py

27
server/hra/game.py

@ -1,13 +1,28 @@
from typing import Any, List, Tuple, Union, Optional
class Logic():
def __init__(self, teams_count, configuration):
pass
logic_by_mode = {}
def add_logic(cls):
logic_by_mode[cls.__name__.lower()] = cls
class Logic:
def __init__(self, teams_count: int, configuration: Any):
self.teams_count = teams_count
self.configuration = configuration
def zero_state(self):
def zero_state(self) -> Any:
return {}
def step(self, actions):
def step(self, state: Any, actions: List[Optional[Any]], round_id: int) -> Tuple[Any, List[int]]:
return {}, [0] * teams_count # new_state, add_points for each team
def validate_step(self, state: Any, team_id: int, action: Any, round_id: int) -> Union[None, Any]:
return None # Bez chyby
# return {"status": "warning", ... } # Drobná chyba, ale tah provedu
# throw Exception("Chybí povinná ...") # Zásadní chyba, tah neuznán
# Když používají našeho klienta, tak by se toto nemělo stát
@add_logic
class Occupy(Logic):
pass
logic_by_mode = {"base": Logic}

Loading…
Cancel
Save