apologies.game
¶
Classes that track game state.
Note that these classes track game state, but do not implement game rules. The only validations are to prevent changes that literally cannot be represented in game state, such as selecting an invalid square. All other rules (such as the restriction that only one pawn can occupy a space, or the act of sliding down a slider, etc.) are implemented in the rules module, using the methods available on these classes.
In many cases, private attributes are accessible in the constructor to support serialization and deserialization. In general, callers should not pass in optional constructor arguments and should not modify public attributes if an alternate method is available for use.
- apologies.game.DECK_COUNTS¶
Dictionary from card name to number of cards in a standard deck
- apologies.game.CIRCLE¶
The position of the start circle for each color
- Type:
Dict[PlayerColor, Position]
- apologies.game.TURN¶
The position of the turn square for each color, where forward movement turns into safe zone
- Type:
Dict[PlayerColor, Position()
- apologies.game.SLIDE¶
The slide start/end squares for each color
- Type:
Dict[PlayerColor, Tuple(int, int)
Module Contents¶
- apologies.game.MIN_PLAYERS = 2¶
- apologies.game.MAX_PLAYERS = 4¶
- apologies.game.PAWNS = 4¶
- apologies.game.SAFE_SQUARES = 5¶
- apologies.game.BOARD_SQUARES = 60¶
- class apologies.game.GameMode¶
Bases:
enum.Enum
Available game play modes.
- STANDARD = 'Standard'¶
- ADULT = 'Adult'¶
- class apologies.game.PlayerColor¶
Bases:
enum.Enum
Enumeration of all player colors, listed in order of use.
- RED = 'Red'¶
- YELLOW = 'Yellow'¶
- GREEN = 'Green'¶
- BLUE = 'Blue'¶
- class apologies.game.CardType¶
Bases:
enum.Enum
All legal types of cards.
The “A” card (CARD_APOLOGIES) is like the “Sorry” card in the original game.
- CARD_1 = '1'¶
- CARD_2 = '2'¶
- CARD_3 = '3'¶
- CARD_4 = '4'¶
- CARD_5 = '5'¶
- CARD_7 = '7'¶
- CARD_8 = '8'¶
- CARD_10 = '10'¶
- CARD_11 = '11'¶
- CARD_12 = '12'¶
- CARD_APOLOGIES = 'A'¶
- apologies.game.ADULT_HAND = 5¶
- apologies.game.DECK_COUNTS¶
- apologies.game.DECK_SIZE¶
- apologies.game.DRAW_AGAIN¶
- class apologies.game.Card¶
A card in a deck or in a player’s hand.
- class apologies.game.Deck¶
The deck of cards associated with a game.
Callers should not pass in constructor arguments. These are accessible to support serialization and deserialization.
- class apologies.game.Position¶
The position of a pawn on the board.
Callers should not pass in or directly modify the start, home, safe, or square attributes. These are accessible to support serialization and deserialization. Instead, use the provided methods to safely modify the object in-place.
- start¶
Whether this pawn resides in its start area
- Type:
boolean
- home¶
Whether this pawn resides in its home area
- Type:
boolean
- move_to_position(position: Position) Position ¶
Move the pawn to a specific position on the board.
- Returns:
A reference to the position, for chaining
- Return type:
- Raises:
ValueError – If the position is invalid
- move_to_start() Position ¶
Move the pawn back to its start area.
- Returns:
A reference to the position, for chaining
- Return type:
- Raises:
ValueError – If the position is invalid
- move_to_home() Position ¶
Move the pawn to its home area.
- Returns:
A reference to the position, for chaining
- Return type:
- Raises:
ValueError – If the position is invalid
- move_to_safe(square: int) Position ¶
Move the pawn to a square in its safe area.
- Parameters:
square (int) – Zero-based index of the square in the safe area
- Returns:
A reference to the position, for chaining
- Return type:
- Raises:
ValueError – If the square is not valid
- class apologies.game.Pawn¶
A pawn on the board, belonging to a player.
Callers should not pass in the position attribute. This is accessible to support serialization and deserialization. Instead, use the provided methods to safely modify the position in-place.
- color: PlayerColor¶
- class apologies.game.Player¶
A player, which has a color and a set of pawns.
Callers should not pass in the hand and pawns constructor arguments. These are accessible to support serialization and deserialization.
- color: PlayerColor¶
- class apologies.game.History¶
Tracks an action taken during the game.
- color¶
Color of the player associated with the action
- Type:
Optional[PlayerColor]
- timestamp¶
Timestamp tied to the action (defaults to current time)
- Type:
DateTime
- color: PlayerColor | None¶
- timestamp: pendulum.datetime.DateTime¶
- class apologies.game.PlayerView¶
A player-specific view of the game, showing only the information a player would have available on their turn.
- opponents¶
The player’s opponents, with private information stripped
- Type:
Dict[PlayerColor, Player]
- opponents: Dict[PlayerColor, Player]¶
- copy() PlayerView ¶
Return a fully-independent copy of the player view.
- class apologies.game.Game¶
The game, consisting of state for a set of players.
Callers should not pass in optional constructor arguments. These are accessible to support serialization and deserialization.
- players¶
All players in the game
- Type:
Dict[PlayerColor, Player]
- players: Dict[PlayerColor, Player]¶
- track(action: str, player: Player | None = None, card: Card | None = None) None ¶
Tracks an action taken during the game.
- create_player_view(color: PlayerColor) PlayerView ¶
Return a player-specific view of the game, showing only the information a player would have available on their turn.
- apologies.game.CIRCLE¶
- apologies.game.TURN¶
- apologies.game.SLIDE¶