apologies.rules
¶
Implements rules related to game play.
Module Contents¶
- class apologies.rules.ActionType¶
Bases:
enum.Enum
Enumeration of all actions that a character can take.
- MOVE_TO_START = 'Move to start'¶
- MOVE_TO_POSITION = 'Move to position'¶
- class apologies.rules.Action¶
An action that can be taken as part of a move.
- actiontype¶
The type of action
- Type:
- actiontype: ActionType¶
- pawn: apologies.game.Pawn¶
- position: apologies.game.Position | None¶
- class apologies.rules.Move¶
A player’s move on the board, which consists of one or more actions.
Note that the actions associated with a move include both the immediate actions that the player chose (such as moving a pawn from start or swapping places with a different pawn), but also any side-effects (such as pawns that are bumped back to start because of a slide). As a result, executing a move becomes very easy and no validation is required. All of the work is done up-front.
- id¶
Identifier for this move, which must be unique among all legal moves this move is grouped with
- Type:
- card: apologies.game.Card¶
- class apologies.rules.BoardRules¶
Rules related to the way the board works.
- construct_legal_moves(color: apologies.game.PlayerColor, card: apologies.game.Card, pawn: apologies.game.Pawn, all_pawns: List[apologies.game.Pawn]) List[Move] ¶
Return the set of legal moves for a pawn using a card, possibly empty.
- Returns:
Set of legal moves for the pawn using the card.
- static distance_to_home(pawn: apologies.game.Pawn) int ¶
Return the distance to home for this pawn, a number of squares when moving forward.
- class apologies.rules.Rules¶
Implements rules related to game play.
- mode: apologies.game.GameMode¶
- draw_again(card: apologies.game.Card) bool ¶
Whether the player gets to draw again based on the passed-in card.
- start_game(game: apologies.game.Game) None ¶
Start the game.
- Parameters:
game (Game) – Game to operate on
- construct_legal_moves(view: apologies.game.PlayerView, card: apologies.game.Card | None = None) List[Move] ¶
Return the set of all legal moves for a player and its opponents.
- view¶
Player-specific view of the game
- Type:
- Returns:
Set of legal moves for the player, as described above.
- Return type:
List[Move]
- execute_move(game: apologies.game.Game, player: apologies.game.Player, move: Move) None ¶
Execute a player’s move, updating game state.
- static evaluate_move(view: apologies.game.PlayerView, move: Move) apologies.game.PlayerView ¶
Construct the new player view that results from executing the passed-in move.
This is equivalent to execute_move() but has no permanent effect on the game. It’s intended for use by a character, to evaluate the results of each legal move.
- Parameters:
view (PlayerView) –
move (Move) –
- Returns:
The new state after executing the move.
- Return type: