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, common_effect_stack: EffectStack, dmg_effect_stack: EffectStack, lethal_dmg_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, common_effect_stack: EffectStack, dmg_effect_stack: EffectStack, lethal_dmg_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.
common_effect_stack – common effects queued during effect-group execution.
dmg_effect_stack – pending damage effects to be executed by the game.
lethal_dmg_effect_stack – pending lethal damage 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, seed: int | float | None = None) None | GameState
- 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.
- property active_player_id: Pid
- Returns:
the current active player which should be the first player to take actions.
- auto_step(seed: int | float | None = None) GameState
Same as step, but automatically step until a player action is required.
- property card_checker: CardChecker
- Returns:
a validity checker for playing cards.
- property common_effect_stack: EffectStack
- Returns:
the stack of pending common effects to be executed.
- 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.
- property dmg_effect_stack: EffectStack
- Returns:
the stack of pending dmg effects to be executed.
- property effect_stack: EffectStack
- Returns:
the stack of pending effects to be executed.
- property elem_tuning_checker: ElementalTuningChecker
- Returns:
a validity checker for performing elemental tuning.
- encoding(encoding_plan: EncodingPlan, perspective: Pid = Pid.P1) list[int]
Encode the game state into a list of integers.
- 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(mode: ~dgisim.mode.Mode = <dgisim.mode.DefaultMode object>) 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_character_target(target: StaticTarget) None | Character
- Returns:
the character target that target specifies.
- 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_target(target: StaticTarget) None | Character | Status | 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.
- property lethal_dmg_effect_stack: EffectStack
- Returns:
the stack of pending lethal dmg effects to be executed.
- perspective_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.
- property player1: PlayerState
- Returns:
all information about player 1.
- property player2: PlayerState
- Returns:
all information about player 2.
- property skill_checker: SkillChecker
- Returns:
a validity checker for casting character skills.
- step(seed: int | float | None = None) GameState
- Parameters:
seed – the seed for internal random number generation. Applying the same seed to the same game state will always result in the same next state.
- Returns:
the next state of a state-transition from the current one without any player action.
- property swap_checker: SwapChecker
- Returns:
a validity checker for performing character swaps.