Game State
GameState is an immutable class used to hold all the information of a moment
of a game.
__eq__ and __hash__ are implemented so that any two game states with the
equivalent content are equal to each other and have the same hash.
from dgisim import GameState
- class GameState(mode: Mode, phase: Phase, round: int, active_player_id: Pid, player1: PlayerState, player2: PlayerState, effect_stack: EffectStack)
The class which represents a moment or a state of the game, containing all information required to proceed to the next game state.
To proceed when the game doesn’t require a player action at the moment, run step(), otherwise run action_step(player_action).
To tell if a player action is required, run waiting_for().
- __init__(mode: Mode, phase: Phase, round: int, active_player_id: Pid, player1: PlayerState, player2: PlayerState, effect_stack: EffectStack)
- Parameters:
mode – game mode.
phase – game phase of game mode.
round – current round number.
active_player_id – the active player which should take action first.
player1 – player 1, which normally is the first to act at the beginning of the game.
player2 – player 2, the opponent of player1.
effect_stack – pending effects to be executed by the game.
- factory() GameStateFactory
- Returns:
a factory for the current game state.
The factory allows modifications to the existing a copy of the origial game state to produce a new one.
You may call
.<attribute-name>(new_val)to replace the current value.Or call
.f_<attribute-name>(<function>)to make modifications based on the current value.e.g.
game_state.factory().f_round(lambda r: r + 1).active_player_id(Pid.P1).build()returns a new game state with incremented round and active player as Pid.P1.
- action_generator(pid: Pid) None | ActionGenerator
- Returns:
an action generator for player pid under this game state. None is returned if the player cannot take any action at the moment.
- action_step(pid: Pid, action: PlayerAction) GameState | None
- Returns:
the next state of a state-transition from the current one with a player action from pid. None is returned if the action is illegal in the context.
- card_checker() CardChecker
- Returns:
a validity checker for playing cards.
- death_swapping(player_id: None | Pid = None) bool
- Returns:
if the player with player_id or any player (if player_id is None) is undergoing death swapping.
- elem_tuning_checker() ElementalTuningChecker
- Returns:
a validity checker for performing elemental tuning.
- classmethod from_decks(mode: md.Mode, p1_deck: Deck, p2_deck: Deck) Self
- Returns:
the initial game state of mode with two decks for each player.
- classmethod from_default() Self
- Returns:
a random initial game state with default mode and random decks for both players.
- classmethod from_players(mode: Mode, player1: PlayerState, player2: PlayerState) Self
- Returns:
the initial game state of mode with player1 and player2.
- get_active_player_id() Pid
- Returns:
the current active player which should be the first player to take actions.
- get_character_target(target: StaticTarget) None | Character
- Returns:
the character target that target specifies.
- get_effect_stack() EffectStack
- Returns:
the stack of pending effects to be executed.
- get_other_player(player_id: Pid) PlayerState
- Returns:
the player with the other of player_id.
- get_pid(player: PlayerState) Pid
- Parameters:
player – a player that is in this game state.
- Returns:
the Pid of the given player.
- get_player(player_id: Pid) PlayerState
- Returns:
the player with player_id.
- get_player1() PlayerState
- Returns:
all information about player 1.
- get_player2() PlayerState
- Returns:
all information about player 2.
- get_target(target: StaticTarget) None | Character | Summon | Support
- Returns:
the target that target specifies.
- get_winner() Pid | None
- Returns:
the winner’s Pid or None if the game is a drawn.
There’ll be an assertion error if the game hasn’t ended yet.
- prespective_view(pid: Pid) GameState
- Returns:
a new GameState that is in the perspective of player pid, hiding their opponent’s cards and dice.
Note the current version of the game only hides the cards, but not dice. Cards are hidden by replacing all with OmniCard, a special type of card.
- skill_checker() SkillChecker
- Returns:
a validity checker for casting character skills.
- step() GameState
- Returns:
the next state of a state-transition from the current one without any player action.
- swap_checker() SwapChecker
- Returns:
a validity checker for performing character swaps.