Game State Machine
from dgisim import GameStateMachine
- class GameStateMachine(game_state: GameState, agent1: PlayerAgent, agent2: PlayerAgent)
This is a class used to control the flow of a linear game.
It stores a list of past game states, from the oldest to the latest, and append new game states to the end of the list on call.
When player interaction is required, GameStateMachine asks the corresponding player agent for action in order to make state transitions.
(A linear game is the game where once decisions are made, other branches of possibilities are no longer available to explore (via this class).)
- auto_step(observe=False) None
- Parameters:
observe – set to True if you want every intermediate state to be printed. (requires enter to continue each transition)
Keeps making state transitions until a player action is required.
- get_action_history() tuple[dgisim.state.game_state.GameState, ...]
- Returns:
the history of past game states that are just before action making in chronological order.
- get_history() tuple[dgisim.state.game_state.GameState, ...]
- Returns:
the complete history of past game states in chronological order.
- one_step(observe=False) None
- Parameters:
observe – set to True if you want every intermediate state to be printed. (requires enter to continue each transition)
Make a single state transition to the latest game state.
- player_agent(id: Pid) PlayerAgent
- Returns:
the player agent for id
- player_step(observe=False) None
- Parameters:
observe – set to True if you want every intermediate state to be printed. (requires enter to continue each transition)
Keeps making state transitions until a player action is required, and then make one additional state transition (to perform a player action).
- run() Pid | None
- Returns:
the Pid of the winner or None if the game is a drawn.
Keeps making state transitions until the game ends.
- step_until_holds(predicate: Callable[[GameState], bool], observe=False) None
- Parameters:
observe – set to True if you want every intermediate state to be printed. (requires enter to continue each transition)
Keeps making state transitions until predicate holds for the latest game state.
- step_until_next_phase(observe=False) None
- Parameters:
observe – set to True if you want every intermediate state to be printed. (requires enter to continue each transition)
Keeps making state transitions until next phase is reached.
- step_until_phase(phase: type[dgisim.phase.phase.Phase] | Phase, observe=False) None
- Parameters:
observe – set to True if you want every intermediate state to be printed. (requires enter to continue each transition)
Keeps making state transitions until the current phase is phase.