apologies.engine
¶
Game engine that coordinates character actions to play a game.
Module Contents¶
- class apologies.engine.Character¶
A character that plays a game, which could be a person or could be computer-driven.
- source¶
The character input source from which moves are taken
- Type:
- choose_move(mode: apologies.game.GameMode, view: apologies.game.PlayerView, legal_moves: List[apologies.rules.Move], evaluator: Callable[[apologies.game.PlayerView, apologies.rules.Move], apologies.game.PlayerView]) apologies.rules.Move ¶
Choose the next move for a character via the user input source.
- Parameters:
mode (GameMode) – Game mode
view (PlayerView) – Player-specific view of the game
legal_moves (Set[Move]) – The set of legal moves
evaluator (Callable[[PlayerView, Move], PlayerView]) – Function to evaluate a move, returning new state
- Returns:
The character’s next as chosen by the configured source
- Return type:
- class apologies.engine.Engine¶
Game engine that coordinates character actions in a game.
Normally, playing a game via an engine is as simple as:
engine.start_game() while not engine.completed: state = engine.play_next()
This synchronously plays a turn for each player, one after another, until the game is complete. Other, more fine-grained methods exist if you need to structure game play differently for your purposes (for instance, to train a machine learning model or to play the game in an asynchronous event-driven environment).
- first¶
The first player, chosen randomly by default
- Type:
- property game: apologies.game.Game¶
A reference to the underlying game.
- property colors: Dict[apologies.game.PlayerColor, Character]¶
- mode: apologies.game.GameMode¶
- first: apologies.game.PlayerColor¶
- winner() Tuple[Character, apologies.game.Player] | None ¶
Return the winner of the game, as a tuple of (Character, Player)
- reset() apologies.game.Game ¶
Reset game state.
- start_game() apologies.game.Game ¶
Start the game, returning game state.
- Returns:
Current state of the game.
- Return type:
- next_turn() Tuple[apologies.game.PlayerColor, Character] ¶
Get the color and character for the next turn This will give you a different player each time you call it.
- play_next() apologies.game.Game ¶
Play the next turn of the game, returning game state as of the end of the turn.
- Returns:
Current state of the game.
- Return type:
- draw() apologies.game.Card ¶
Draw a random card from the game’s draw pile.
- discard(card: apologies.game.Card) None ¶
Discard back to the game’s discard pile.
- construct_legal_moves(view: apologies.game.PlayerView, card: apologies.game.Card | None = None) Tuple[apologies.game.Card | None, List[apologies.rules.Move]] ¶
Construct the legal moves based on a player view, using the passed-in card if provided.
- choose_next_move(character: Character, view: apologies.game.PlayerView) apologies.rules.Move ¶
Choose the next move for a character based on a player view.
- execute_move(color: apologies.game.PlayerColor, move: apologies.rules.Move) bool ¶
Execute a move for a player, returning True if the player’s turn is done.