endplay.interact.commandobject

Exceptions:

CommandError

Exception raised if an error occurred whilst trying to perform a command.

Classes:

CommandObject([deal])

CommandObject provides an interface for interacting with a deal using actions which are pushed onto an internal history allowing them to be undone and redone.

exception endplay.interact.commandobject.CommandError

Bases: RuntimeError

Exception raised if an error occurred whilst trying to perform a command.

class endplay.interact.commandobject.CommandObject(deal: Deal | None = None)

Bases: object

CommandObject provides an interface for interacting with a deal using actions which are pushed onto an internal history allowing them to be undone and redone. The cmd_ methods can be called normally, or dispatch can be called with a shell like argument list to invoke one of the cmd_ methods.

Methods:

apply_action(action)

cmd_board([board])

Displays the board number, and optionally changes the board number to the argument if given.

cmd_checkpoint()

Removes all past actions in the history.

cmd_deal(pbn)

Deals the given pbn string to the players

cmd_exit()

Exits the program.

cmd_fastforward()

Fast-forwards to the end of the history.

cmd_first([player])

Displays the player on lead to the first card of the current trick, or changes the player on lead if the argument is given.

cmd_hand(player[, hand])

Displays the hand of the given player, or changes the player's hand to a PBN string if the hand argument is given.

cmd_hcp(player)

Displays the number of high card points in the given player's hand.

cmd_help([cmd_name])

Displays all available commands.

cmd_history()

Displays the undo and redo history.

cmd_play(card, *cards)

Plays the specified sequence of cards to the current trick.

cmd_redo()

Redoes the next action.

cmd_rewind()

Rewinds to the beginning of the history.

cmd_shuffle(*constraints)

Shuffles the deal according to the given constraints which should be given in dealer format.

cmd_trump([denom])

Displays the trump suit, and optionally changes the trump suit to the argument if given.

cmd_undo()

Undoes the last action.

cmd_unplay()

Unplays the last card played to the trick.

dispatch(cmdline)

apply_action(action: Action) None
cmd_board(board: int | None = None) int

Displays the board number, and optionally changes the board number to the argument if given.

cmd_checkpoint() None

Removes all past actions in the history.

cmd_deal(pbn: str) Deal

Deals the given pbn string to the players

cmd_exit() None

Exits the program.

cmd_fastforward() None

Fast-forwards to the end of the history.

cmd_first(player: Player | None = None) Player

Displays the player on lead to the first card of the current trick, or changes the player on lead if the argument is given.

cmd_hand(player: Player, hand: Hand | None = None) Hand

Displays the hand of the given player, or changes the player’s hand to a PBN string if the hand argument is given.

cmd_hcp(player: Player) float

Displays the number of high card points in the given player’s hand.

cmd_help(cmd_name: str | None = None) str

Displays all available commands. If cmd_name is given, provide help about that command.

Example 1: help Example 2: help shuffle

cmd_history() str

Displays the undo and redo history. An asterisk is displayed in front of the action which would be applied if redo is called.

cmd_play(card: Card, *cards: Card) None

Plays the specified sequence of cards to the current trick.

cmd_redo() None

Redoes the next action.

cmd_rewind() None

Rewinds to the beginning of the history.

cmd_shuffle(*constraints: str) Deal

Shuffles the deal according to the given constraints which should be given in dealer format. Ensure constrains are surrounded by quotes to avoid being split by whitespace.

cmd_trump(denom: Denom | None = None) Denom

Displays the trump suit, and optionally changes the trump suit to the argument if given.

cmd_undo() None

Undoes the last action.

cmd_unplay() None

Unplays the last card played to the trick.

dispatch(cmdline: list[str]) str | None