endplay.dealer.generate

Generic routines for generating deals based on a set of constraints

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().

endplay.dealer.generate.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.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