endplay.utils.play

Miscellaneous functions relating to play history

Functions:

linearise_play(table, first, trump[, pad_value])

Convert a table-style play history to a linear play history.

result_to_tricks(result, level)

Convert a result to tricks made, e.g.

total_tricks(play, trump)

Calculate the total number of tricks made by the side initially on lead in play with the given trump suit

trick_winner(trick, first, trump)

Calculate the winner of a trick

tricks_to_result(tricks, level)

Convert tricks made to a result, e.g.

endplay.utils.play.linearise_play(table: list[endplay.types.card.Card], first: ~endplay.types.player.Player, trump: ~endplay.types.denom.Denom, pad_value: ~endplay.types.card.Card = Card(rank=<Rank.R2: 4>, suit=<Denom.nt: 4>)) list[str]

Convert a table-style play history to a linear play history. PBN record play history is in blocks of four tricks always starting with the same player, but many double dummy solving algorithms rely on a linear play history where cards are recorded in the order they are played.

Some data formats include the ability to write cards with an unimportant value, and which are required for the table structure. The pad_value parameter should be set to a sentinel value (usually a card with nt suit) to be recognised

endplay.utils.play.result_to_tricks(result: int, level: int)

Convert a result to tricks made, e.g. +1 in a 3 level contract becomes 10

endplay.utils.play.total_tricks(play: Iterable[Card], trump: Denom)

Calculate the total number of tricks made by the side initially on lead in play with the given trump suit

endplay.utils.play.trick_winner(trick: Iterable[Card], first: Player, trump: Denom)

Calculate the winner of a trick

endplay.utils.play.tricks_to_result(tricks: int, level: int)

Convert tricks made to a result, e.g. 8 tricks in a 4-level contract becomes -2