Action Generator
from dgisim import ActionGenerator
ActionGenerator is a class used to helper agents generate valid actions.
An example use flow typically looks like this:
from dgisim import ActionGenerator, GameState, Pid
# get some game state waiting for an action
game_state: GameState = ...
assert game_state.waiting_for() is Pid.P1
# get initial action generator
act_gen: ActionGenerator | None = game_state.action_generator(Pid.P1)
assert act_gen is not None
# fill in the action generator until it is full
while not act_gen.filled():
choices = act_gen.choices()
choice = ... # make a choice based on choices
act_gen = act_gen.choose(choice)
# As each ActionGenerator object is immutable, you can easily construct all
# valid actions with the use of recursion or a queue.
- class ActionGenerator(*, game_state: GameState, pid: Pid, action: None | PlayerAction = None, instruction: None | Instruction = None, _choices_helper: Callable[[Self], GivenChoiceType] = <function _dummy_choices_helper>, _fill_helper: Callable[[Self, DecidedChoiceType], Self] = <function _dummy_fill_helper>)
ActionGenerator is a class recording a state of choices made so far.
If both action and instruction is None, then this action generator is used to generate other ActionGenerators that may eventually generate some action.
- choices() GivenChoiceType
- Returns:
the choices to make a decision from.
If return value is a tuple, choose one value from the tuple.
If return value is ActualDice, choose some dice based on the context.
If return value is AbstractDice, choose some dice of ActualDice that can satisfy the AbstractDice.
If return value is Cards, choose some cards from it based on the context.
- choose(choice: DecidedChoiceType) ActionGenerator
- Parameters:
choice – the choice that the user makes for this stage.
- Returns:
a new ActionGenerator representing the next stage of choices.
- dice_available() ActualDice
- Returns:
the dice the player holds.
A shortcut method to quickly get the player’s dice.
- generate_action() PlayerAction
- Returns:
the final PlayerAction.
Precondition: .filled() is True.