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

pawn

The pawn that the action operates on

Type:

Pawn

position

Optionally, a position the pawn should move to

Type:

Position

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.

card

The card that is being played by this move

Type:

Card

actions

List of actions to execute

Type:

List[Action]

side_effects

List of side effects that occurred as a result of the actions

Type:

List[Action]

id

Identifier for this move, which must be unique among all legal moves this move is grouped with

Type:

str

card: apologies.game.Card
actions: List[Action]
side_effects: List[Action]
id: str
class apologies.rules.BoardRules

Rules related to the way the board works.

Return the set of legal moves for a pawn using a card, possibly empty.

card

Card to be played

Type:

Card

pawn

Pawn that the card will be applied to

Type:

Pawn

all_pawns

All pawns on the board, including the one to be played

Type:

List[Pawn]

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

The game mode

Type:

GameMode

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

Return the set of all legal moves for a player and its opponents.

view

Player-specific view of the game

Type:

PlayerView

card

The card to play, or None if move should come from player’s hand

Type:

Card, optional

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.

Parameters:
  • game (Game) – Game to operate on

  • player (Player) – Color of the player associated with the move

  • move (Move) – Move to validate

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:
Returns:

The new state after executing the move.

Return type:

PlayerView