endplay.types
- endplay.types.bid
- endplay.types.board
- endplay.types.card
- endplay.types.contract
- endplay.types.deal
Deal
Deal.clear()
Deal.compare()
Deal.complete_deal()
Deal.copy()
Deal.curhand
Deal.curplayer
Deal.curtrick
Deal.east
Deal.first
Deal.from_json()
Deal.from_lin()
Deal.from_pbn()
Deal.north
Deal.play()
Deal.pprint()
Deal.rotate()
Deal.south
Deal.swap()
Deal.to_LaTeX()
Deal.to_hand()
Deal.to_json()
Deal.to_lin()
Deal.to_pbn()
Deal.trump
Deal.unplay()
Deal.west
- endplay.types.denom
- endplay.types.hand
- endplay.types.penalty
- endplay.types.player
- endplay.types.rank
- endplay.types.suitholding
- endplay.types.vul
Collection of bridge-related types based on the binary format used by Bo Haglund’s DDS library but with a more Pythonic interface. These types are used by all the submodules in the endplay library.
Classes:
|
Encodes the rank of a suit using the values 2-14. |
|
Base class representing an auction call. |
|
Class representing a deal along with the play, auction and other table information |
|
Immutabale class representing a card with suit and rank read-only attributes |
|
Class representing a specific contract |
|
Class representing a call that names a contract, i.e. has a level and strain. |
|
Class representing a bridge deal. |
|
Encoding for suits and contract denomination |
|
Class allowing manipulations of cards in the hand of a single player |
|
Encodes a penalty |
|
Class representing a call that does not name a contract, i.e. pass, double or redouble. |
|
Encoding for player seat |
|
Encodes the rank of a suit. |
|
|
|
Encodes the vulnerability |
- class endplay.types.AlternateRank(value)
Bases:
IntEnum
Encodes the rank of a suit using the values 2-14. Used for internal functions, for APIs use the Rank class.
Attributes:
Methods:
find
(value)- R2 = 2
- R3 = 3
- R4 = 4
- R5 = 5
- R6 = 6
- R7 = 7
- R8 = 8
- R9 = 9
- RA = 14
- RJ = 11
- RK = 13
- RQ = 12
- RT = 10
- property abbr: str
- static find(value: str) AlternateRank
- class endplay.types.Bid(name: str, alertable: bool = False, announcement: Optional[str] = None)
Bases:
object
Base class representing an auction call. This class provides a convenience constructor from a string, but upon construction will automatically donwcast its type to one of
ContractBid
orPenaltyBid
depending on the type of the call.- Variables:
alertable (bool) – Flag indicating whether the bid is alertable
announcement (Optional[str]) – String transcription of the announcement for this bid
- class endplay.types.Board(deal: Optional[Deal] = None, auction: Optional[Iterable[Bid]] = None, play: Optional[Iterable[Card]] = None, board_num: Optional[int] = None, *, vul: Optional[Vul] = None, dealer: Optional[Player] = None, contract: Optional[Contract] = None, claimed: bool = False, **kwargs)
Bases:
object
Class representing a deal along with the play, auction and other table information
- Variables:
deal (Deal) – The deal at the table
auction (list[Bid]) – The auction at the table
contract (Contract) – The contract at the table
play (list[Card]) – The play history at the table
board_num (int) – The board number of this deal
vul (Vul) – The board vulnerability. If this isn’t defined (i.e. set to None) then it is deduced from board_num
dealer (Player) – The board dealer. Similarly to vul this can be deduced from board_num
claimed (bool) – Flag indicating whether the play ended as a result of a claim
info –
A dictionary which contains arbitrary extra information about the board. The dictionary type used provided case-insensitive dot-access as a convenience (i.e. board.info.event and board.info.Event refer to the same object, but board.info[“event”] and board.info[“Event”] would be considered different). Tabular data can be stored here, any key ending with (but not equal to) table is treated as a table and its value should be a dictionary containing two keys: headers with a list of column names, and rows with a list of the rows. The column names can either be plain strings, or dictionaries with the keys
- ordering: Either “+”, “-” or None depending of if the table is sorted
ascending, descending or unsorted with respect to this column
name: A string value with the name of the column
minwidth: The minimum width that values in this column should be
- alignment: “L” or “R” depending on if this column should be left or right
aligned. Ignored unless minwidth is defined
Classes:
Dictionary-like class which alows for case-insensitive dot-access, for example.
Attributes:
The contract the board was played in.
Dealer of the board.
Vulnerability of the board.
- class Info
Bases:
dict
Dictionary-like class which alows for case-insensitive dot-access, for example:
info["Event"] = "WBF 2017" print(info.event) # WBF 2017
Methods:
_find_key
(key)- _find_key(key: str)
- property contract: Optional[Contract]
The contract the board was played in. If not provided, then attempts to calculate based on the auction and play history.
- class endplay.types.Card(name: Optional[str] = None, *, suit: Optional[Denom] = None, rank: Optional[Rank] = None)
Bases:
object
Immutabale class representing a card with suit and rank read-only attributes
Attributes:
- class endplay.types.Contract(data: Optional[Union[contractType, str]] = None, *, level: Optional[int] = None, denom: Optional[Denom] = None, declarer: Optional[Player] = None, penalty: Optional[Penalty] = None, result: Optional[int] = None)
Bases:
object
Class representing a specific contract
Attributes:
The declarer of the contract
The denomination of the contract
The level of the contract
The number of tricks over or under the contract made
Methods:
copy
()Return a copy of this contract object
from_auction
(dealer, auction)Construct a contract from a bidding sequence
Returns true if the contract represents a passout
score
(vul)The number of points the contract would score for the declarer
- _pat = re.compile('^([1-7])((?:NT?)|S|H|D|C)([NSEW]?)((?:XX|X|D|R)?)((?:=|(?:[+-]\\d+))?)$')
- static from_auction(dealer: Player, auction: Sequence[Bid])
Construct a contract from a bidding sequence
- is_passout() bool
Returns true if the contract represents a passout
- property level: int
The level of the contract
- property result: int
The number of tricks over or under the contract made
- class endplay.types.ContractBid(level: int, denom: Denom, alertable: bool = False, announcement: Optional[str] = None)
Bases:
Bid
Class representing a call that names a contract, i.e. has a level and strain
- Variables:
level (int) – The level of the call (between 1 and 7)
denom – The strain of the call
alertable (bool) – Flag indicating whether the bid is alertable
announcement (Optional[str]) – String transcription of the announcement for this bid
- class endplay.types.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])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:
The hand of the curplayer
The player to play the next card to the current trick
Return a list of cards played to the current trick
The east hand
The player to lead the first card to the current trick
The north hand
The south hand
The trump suit the deal is being played in
The west hand
- clear() None
Clear all hands and the cards in the current trick
- 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
- property curtrick: list[endplay.types.card.Card]
Return a list of cards played 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”
- 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
- to_LaTeX(board_no: Optional[int] = None, exclude: Iterable[Player] = [], ddtable: bool = False) str
Return a LaTeX representation of the hand
- 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
- class endplay.types.Denom(value)
Bases:
IntEnum
Encoding for suits and contract denomination
Attributes:
- return:
A short identifier for the denomination
Methods:
bidorder
()- return:
An iterator over all the denominations in the order they appera in a bidding box
find
(name)Convert a string value into a Denom object
is_major
()- return:
True if the denomination is spades or hearts
is_minor
()- return:
True if the denomination is diamonds or clubs
is_suit
()- return:
True if the denomination is not notrumps
suits
([reverse])Iterate over the suits, excluding notrumps
- property abbr: str
- Returns:
A short identifier for the denomination
- static bidorder() Iterator[Denom]
- Returns:
An iterator over all the denominations in the order they appera in a bidding box
- clubs = 3
- diamonds = 2
- hearts = 1
- is_major() bool
- Returns:
True if the denomination is spades or hearts
- is_minor() bool
- Returns:
True if the denomination is diamonds or clubs
- is_suit() bool
- Returns:
True if the denomination is not notrumps
- nt = 4
- spades = 0
- class endplay.types.Hand(data: Union[str, Array[c_uint]] = '...')
Bases:
object
Class allowing manipulations of cards in the hand of a single player
Methods:
add
(card)Adds a card to the hand
clear
()Remove all cards from the hand
copy
()extend
(cards)Add multiple cards to the hand
from_lin
(lin)Construct a Hand from a LIN string
from_pbn
(pbn)Construct a Hand from a PBN string
pprint
([vertical, stream])Print the suits in the hand using suit symbols
remove
(card)Remove a card from the hand
to_LaTeX
([vertical, ten_as_letter])Create a LaTeX representation of the hand.
to_lin
()Convert a Hand to a LIN string
to_pbn
()- return:
A PBN representation of the hand
Attributes:
The club holding of the hand
The diamond holding of the hand
The heart holding of the hand
The spade holding of the hand
- add(card: Card) bool
Adds a card to the hand
- Parameters:
card – The card to be added to the hand
- Returns:
False if the card was already in the hand, True otherwise
- clear() None
Remove all cards from the hand
- property clubs: SuitHolding
The club holding of the hand
- property diamonds: SuitHolding
The diamond holding of the hand
- extend(cards: Iterable[Card]) int
Add multiple cards to the hand
- Parameters:
cards – An iterable of the cards to add
- Returns:
The number of cards successfully added
- static from_lin(lin: str) Hand
Construct a Hand from a LIN string
- Parameters:
lin – A LIN string for a hand, e.g. “SQT62HDAQT852CQJT”
- static from_pbn(pbn: str) Hand
Construct a Hand from a PBN string
- Parameters:
pbn – A PBN string for a hand, e.g. “QT62..AQT852.QJT”
- property hearts: SuitHolding
The heart holding of the hand
- pprint(vertical: bool = True, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) None
Print the suits in the hand using suit symbols
- remove(card: Card) bool
Remove a card from the hand
- Parameters:
card – The card to be added to the hand, can be a string representation e.g. “CQ”
- Returns:
False if the card wasn’t in the hand, True otherwise
- property spades: SuitHolding
The spade holding of the hand
- to_LaTeX(vertical: bool = True, ten_as_letter: bool = False) str
Create a LaTeX representation of the hand.
- Parameters:
vertical – If True uses vhand, else hhand layout
title – The hand title. If vertical is False this is ignored
- to_lin() str
Convert a Hand to a LIN string
- to_pbn() str
- Returns:
A PBN representation of the hand
- class endplay.types.Penalty(value)
Bases:
IntEnum
Encodes a penalty
Attributes:
Methods:
find
(name)- property abbr: str
- doubled = 2
- static find(name: str)
- passed = 1
- redoubled = 4
- class endplay.types.PenaltyBid(penalty: Penalty, alertable: bool = False, announcement: Optional[str] = None)
Bases:
Bid
Class representing a call that does not name a contract, i.e. pass, double or redouble
- Variables:
penalty (Penalty) – The type of the call
alertable (bool) – Flag indicating whether the bid is alertable
announcement (Optional[str]) – String transcription of the announcement for this bid
- class endplay.types.Player(value)
Bases:
IntEnum
Encoding for player seat
Attributes:
- return:
A single character string for the player name
- return:
The player on the current player's left
- return:
The player opposite the current player
- return:
The player to the current player's right
Methods:
enumerate
(iterable[, step])Return an iterator whose next method returns a tuple containing a Player (starting from this player) and the values obtained from iterating over iterable, where the player increments each time by step rotations clockwise
find
(name)Convert a string into a Player object
from_board
(n)Return the player who is the dealer of the corresponding board
from_lin
(n)Convert a BBO LIN representation of a player into a Player object.
is_vul
(vul)Iterate over all four players, clockwise, starting from this player
iter_order
(order)Iterate over a sequence of players in a given order
next
([n])- return:
The player who is n places left of the current player
prev
([n])- return:
The player who is n places right of the current player
to_lin
()turns_to
(other)Return the number of positions clockwise other is from self
- property abbr: str
- Returns:
A single character string for the player name
- east = 1
- enumerate(iterable: Iterable, step: int = 1) Iterator
Return an iterator whose next method returns a tuple containing a Player (starting from this player) and the values obtained from iterating over iterable, where the player increments each time by step rotations clockwise
- static from_lin(n: int) Player
Convert a BBO LIN representation of a player into a Player object. The conversion is determined by 1=S, 2=W, 3=N, 4=E
- iter_from() Iterator[Player]
Iterate over all four players, clockwise, starting from this player
- Returns:
An iterator over all four players in play order
- static iter_order(order: str) Iterator[Player]
Iterate over a sequence of players in a given order
- Parameters:
order – The specified order as a four-character string or list of strings
- Returns:
An iterator over the players in the specified order
- north = 0
- south = 2
- to_lin() int
- west = 3
- class endplay.types.Rank(value)
Bases:
IntEnum
Encodes the rank of a suit. The standard values use powers of two, however some internal functions use an alternative encoding AlternateRank using the values 2-14.
Attributes:
Methods:
find
(value)- R2 = 4
- R3 = 8
- R4 = 16
- R5 = 32
- R6 = 64
- R7 = 128
- R8 = 256
- R9 = 512
- RA = 16384
- RJ = 2048
- RK = 8192
- RQ = 4096
- RT = 1024
- property abbr: str
- to_alternate() AlternateRank
- class endplay.types.SuitHolding(data: Union[c_uint_Array_4, str] = '', idx: Optional[int] = None)
Bases:
object
Methods:
add
(rank)Add a rank to the suit holding
clear
()Removes all cards from the holding
copy
()extend
(ranks)Add multiple ranks to the suit holding
from_pbn
(pbn)Construct a SuitHolding object from a PBN string
remove
(rank)Remove a rank from the suit holding
to_pbn
()Create a PBN representation of the suit holding
- add(rank: Union[Rank, str]) bool
Add a rank to the suit holding
- Parameters:
rank – The rank to add
- Returns:
False if the rank was already in the holding, True otherwise
- clear() None
Removes all cards from the holding
- copy() SuitHolding
- extend(ranks: Iterable[Rank]) int
Add multiple ranks to the suit holding
- Parm ranks:
An iterable of the ranks to add
- Returns:
The number of ranks successfully added
- static from_pbn(pbn: str) SuitHolding
Construct a SuitHolding object from a PBN string
- remove(rank: Rank) bool
Remove a rank from the suit holding
- Parameters:
rank – The rank to remove
- Returns:
False if the rank wasn’t in the holding, True otherwise
- to_pbn() str
Create a PBN representation of the suit holding
- class endplay.types.Vul(value)
Bases:
IntEnum
Encodes the vulnerability
Attributes:
A short string representation of the vulnerability
Methods:
find
(name)Convert a string into a Vul object
from_board
(board_no)- return:
The vulnerability of the specified board
from_lin
(s)Convert a BBO LIN string of vulnerability into a Vul object.
to_lin
()- property abbr: str
A short string representation of the vulnerability
- both = 1
- ew = 3
- static from_lin(s: str) Vul
Convert a BBO LIN string of vulnerability into a Vul object. The conversion is determined by o=none, e=ew, n=ns, b=both
- none = 0
- ns = 2
- to_lin() str