42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from diceplayer.config.player_config import PlayerConfig
|
|
from diceplayer.logger import logger
|
|
from diceplayer.state.state_handler import StateHandler
|
|
from diceplayer.state.state_model import StateModel
|
|
|
|
from typing_extensions import TypedDict, Unpack
|
|
|
|
|
|
class PlayerFlags(TypedDict):
|
|
continuation: bool
|
|
force: bool
|
|
|
|
|
|
class Player:
|
|
def __init__(self, config: PlayerConfig):
|
|
self.config = config
|
|
|
|
def play(self, **flags: Unpack[PlayerFlags]):
|
|
state_handler = StateHandler(self.config.simulation_dir)
|
|
|
|
if not flags["continuation"]:
|
|
logger.info(
|
|
"Continuation flag is not set. Starting a new simulation and deleting any existing state."
|
|
)
|
|
state_handler.delete()
|
|
|
|
state = state_handler.get(self.config, force=flags["force"])
|
|
|
|
if state is None:
|
|
state = StateModel.from_config(self.config)
|
|
else:
|
|
logger.info("Resuming from existing state.")
|
|
|
|
while state.current_cycle < self.config.max_cyc:
|
|
logger.info(
|
|
f"Starting cycle {state.current_cycle + 1} of {self.config.max_cyc}."
|
|
)
|
|
state.current_cycle += 1
|
|
state_handler.save(state)
|
|
|
|
logger.info("Reached maximum number of cycles. Simulation complete.")
|