endplay.dealer

Functionality for generating bridge deals. This submodule provides an API via generate_deals() as well as an executable module which can be run with python3 -m endplay.dealer and which aims to emulate the behaviour of Hans van Staveren’s original dealer program

Functions:

generate_deal(*constraints[, predeal, ...])

Generates a random deal satisfying the constraints, giving 13 cards to each player.

generate_deals(*constraints[, predeal, ...])

Generates produce random deals satisfying the constraints which should be given as for generate_deal().

run_script(script[, show_progress, produce, ...])

Execute a dealer script file

endplay.dealer.generate_deal(*constraints: Union[Callable[[Deal], Union[float, int, bool]], str], predeal: Deal = Deal('N:... ... ... ...'), swapping: int = 0, seed: Optional[int] = None, max_attempts: int = 1000000, env: dict = {}) Deal

Generates a random deal satisfying the constraints, giving 13 cards to each player. The constraints should be supplied as functions taking a whole deal and returning a boolean, for example lambda d: hcp(d.north) > 10, or as expressions compatible with the dealer expression syntax (see https://www.bridgebase.com/tools/dealer/Manual/input.html#expr)

Parameters:
  • constraints – Constraints, as callables or strings

  • predeal – A Deal object which may be partially filled with cards; these will not be shuffled, allowing you to specify that players should have particular holdings.

  • swapping – An integer representing the type of swapping algorithm to use, either 0 (no swapping), 2 (swapping EW) or 3 (swapping EWS)

  • seed – The number to seed the random generator with. A numpy random generator is used which is guaranteed to be stable between Python releases.

  • max_attempts – Maximum number of shuffles to perform when finding a deal which matches the constraints. Set to -1 for infinite

  • env – A dictionary of the environment used when evaluating constraints

endplay.dealer.generate_deals(*constraints: Union[Callable[[Deal], Union[float, int, bool]], str], predeal: Deal = Deal('N:... ... ... ...'), swapping: int = 0, show_progress: bool = False, produce: int = 40, seed: Optional[int] = None, max_attempts: int = 1000000, env: dict = {}, strict: bool = False) Iterator[Deal]

Generates produce random deals satisfying the constraints which should be given as for generate_deal(). produce and max_attemps are upper limits, the first to be reached terminates the program

Parameters:
  • constraints – Constraints, as callables or strings

  • predeal – A Deal object which may be partially filled with cards; these will not be shuffled, allowing you to specify that players should have particular holdings.

  • swapping – An integer representing the type of swapping algorithm to use, either 0 (no swapping), 2 (swapping EW) or 3 (swapping EWS)

  • show_progress – If True, a progress bar is displayed with information on how many hands have been generated so far

  • produce – The total number of hands satisfying the constraints to find.

  • seed – The number to seed the random generator with. A numpy random generator is used which is guaranteed to be stable between Python releases.

  • max_attempts – Maximum number of shuffles to perform when finding a deal which matches the constraints. Set to -1 for infinite

  • env – A dictionary of the environment used when evaluating constraints

  • strict – If True, a RuntimeError is raised if max_attempts is reached before produce hands are produced. Otherwise, a warning is generated

endplay.dealer.run_script(script: Optional[str], show_progress: bool = False, produce: int = 40, generate: int = 1000000, seed: Optional[int] = None, verbose: bool = False, swapping: int = 0, outformat: str = 'plain', outfile: Optional[str] = None, constraints: list[str] = [], actions: list[str] = [], predeal: str = '', board_numbers: bool = False) list[endplay.types.deal.Deal]

Execute a dealer script file

Parameters:
  • script – The name of the script file to run

  • show_progress – Display a progress meter while hands are generated

  • produce – The number of hands to produce

  • generate – The maximum number of shuffles to perform

  • seed – The seed for the random number generator

  • verbose – Print extra debugging info and statistics at completion

  • swapping – The swapping algorithm to use (0=no swapping, 2=swap EW, 3=all permutations of SEW)

  • outformat – The format to print output in: ‘plain’, ‘latex’ or ‘pdf’

  • outfile – A filename to write the output to, if None then printed to stdout

  • constraints – A list of extra constraints to apply

  • actions – A list of extra actions to apply

  • predeal – A list of players and the suit holdings to deal to them

  • board_numbers – If True, print board numbers along with the generated deals

Returns:

The generated deals in a list