endplay.types.deal

Classes:

Deal([pbn, first, trump, complete_deal])

Class representing a bridge deal.

class endplay.types.deal.Deal(pbn: Optional[str] = None, first: Player = Player.north, trump: Denom = Denom.nt, *, complete_deal: bool = False)

Bases: object

Class representing a bridge deal. The class keeps track of the four hands at the table, as well as

  • The player on initial lead to the current trick in Deal.first

  • The trump suit the deal is played in in Deal.trump

  • The cards played to the current trick in Deal.curtrick

Methods:

clear()

Clear all hands and the cards in the current trick

compare(other[, hands_only])

complete_deal()

If there is a player with no cards, deal any cards which do not appear in anyone else's hand to that player

copy()

Return a new copy of this deal

from_json(json)

from_lin(lin[, complete_deal])

Construct a deal from a LIN format deal string.

from_pbn(pbn)

Clear all hands and the current trick, and replace with the cards in a PBN string

play(card[, fromHand])

Play a card to the current trick.

pprint([board_no, exclude, stream, vul, dealer])

Print the deal in a hand diagram format.

rotate(n)

Rotate clockwise by n quarter-turns, e.g.

swap(player_a, player_b)

Swap the specified hands

to_LaTeX([board_no, exclude, ddtable])

Return a LaTeX representation of the hand

to_hand()

Return a new hand containing the contents of all four hands in the deal

to_json([indent])

Encode the data as a JSON string

to_lin([dealer, complete_deal])

Convert a deal to LIN representation as used by BBO

to_pbn()

Return a PBN string representation of the deal

unplay([toHand])

Unplay the last card played to the current trick.

Attributes:

curhand

The hand of the curplayer

curplayer

The player to play the next card to the current trick

curtrick

Return a list of cards played to the current trick

east

The east hand

first

The player to lead the first card to the current trick

north

The north hand

south

The south hand

trump

The trump suit the deal is being played in

west

The west hand

clear() None

Clear all hands and the cards in the current trick

compare(other: Deal, hands_only: bool = False) bool
complete_deal() None

If there is a player with no cards, deal any cards which do not appear in anyone else’s hand to that player

copy() Deal

Return a new copy of this deal

property curhand: Hand

The hand of the curplayer

property curplayer: Player

The player to play the next card to the current trick

property curtrick: list[endplay.types.card.Card]

Return a list of cards played to the current trick

property east: Hand

The east hand

property first: Player

The player to lead the first card to the current trick

static from_json(json: Union[str, dict])
static from_lin(lin: str, complete_deal: bool = True)

Construct a deal from a LIN format deal string.

Parameters:

complete_deal – If True, then add remaining cards to the last hand if it is omitted from the input string (which is done by default for files downloaded from BBO)

static from_pbn(pbn: str) Deal

Clear all hands and the current trick, and replace with the cards in a PBN string

Parameters:

pbn – A PBN string, e.g. “N:974.AJ3.63.AK963 K83.K9752.7.8752 AQJ5.T864.KJ94.4 T62.Q.AQT852.QJT”

property north: Hand

The north hand

play(card: Card, fromHand: bool = True) None

Play a card to the current trick. If the played card completes the trick then the entire trick is cleared and first is set to the played who won the trick using trump as the trumps suit

Parameters:
  • card – The cad to be played

  • fromHand – If true then the card will be removed from the hand of the player who is to play to the trick next and throw a RuntimeError if they do not hold this card.

pprint(board_no: ~typing.Optional[int] = None, exclude: list[endplay.types.player.Player] = [], stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, *, vul: ~typing.Optional[~endplay.types.vul.Vul] = None, dealer: ~typing.Optional[~endplay.types.player.Player] = None) None

Print the deal in a hand diagram format.

Parameters:

board_no – If provided, the hand diagram will display the board number, vulnerability and dealer in the top-left corner

rotate(n: int) None

Rotate clockwise by n quarter-turns, e.g. with n=1 NESW -> WNES

property south: Hand

The south hand

swap(player_a: Player, player_b: Player) None

Swap the specified hands

to_LaTeX(board_no: Optional[int] = None, exclude: Iterable[Player] = [], ddtable: bool = False) str

Return a LaTeX representation of the hand

to_hand() Hand

Return a new hand containing the contents of all four hands in the deal

to_json(indent: Optional[int] = None) str

Encode the data as a JSON string

to_lin(dealer: Optional[Player] = None, complete_deal: bool = False) str

Convert a deal to LIN representation as used by BBO

Parameters:
  • dealer – If provided, append the dealer (in LIN format) to the returned string

  • complete_deal – If False, omit the last hand from the string. This is the default for files created by BBO.

to_pbn() str

Return a PBN string representation of the deal

property trump: Denom

The trump suit the deal is being played in

unplay(toHand: bool = True) Card

Unplay the last card played to the current trick. Throws a RuntimeError if the current trick is empty

Parameters:

toHand – If true then the card is returned to the hand of the player who played it to the trick

Returns:

The card that was picked up

property west: Hand

The west hand