endplay.dealer.constraint
Engine for converting dealer-syntax expressions into evaluatable Python functions. You should not need to use this directly unless you are developing your own functions, as most functions accept strings as well as functions and automatically compile them using the machinery in this module.
Classes:
Provides an interface for evaluating constraints in the Dealer program syntax and testing them against a deal |
- class endplay.dealer.constraint.ConstraintInterpreter
Bases:
object
Provides an interface for evaluating constraints in the Dealer program syntax and testing them against a deal
Methods:
_dispatch_function
(node, deal)_dispatch_operator
(node, deal)_evaluate_shape
(node, shape)_fn_cccc
(node, deal)_fn_control
(node, deal)_fn_hascard
(node, deal)_fn_hcp
(node, deal, scale)_fn_if
(node, deal)_fn_imps
(node, deal)_fn_loser
(node, deal)_fn_quality
(node, deal)_fn_score
(node, deal)_fn_shape
(node, deal)_fn_suit
(node, deal)_fn_trick
(node, deal)_op_add
(node, deal)_op_and
(node, deal)_op_div
(node, deal)_op_equal
(node, deal)_op_geq
(node, deal)_op_greater
(node, deal)_op_leq
(node, deal)_op_less
(node, deal)_op_mod
(node, deal)_op_mul
(node, deal)_op_not
(node, deal)_op_notequal
(node, deal)_op_or
(node, deal)_op_sub
(node, deal)evaluate
(node, deal)Evaluate an expression tree over a specific deal into a logical or arithmetic type
get_env
(name)- return:
The value of the named environment variable
lambdify
(node)Convert an expression tree (or string) into an anonymous function accepting a single
Deal
argument and returning the expression evaluated over this dealparse
(s)Parse an expression string into a syntax tree
Reinitialise the environment to the default values
set_env
(name, value)Insert a new variable into the interpreter's environment or change the value of an existing variable
unset_env
(name)Remove an variable from the interpreter's environment.
Attributes:
- _dispatch_function(node, deal)
- _dispatch_operator(node, deal)
- _evaluate_shape(node, shape)
- _fn_cccc(node, deal)
- _fn_control(node, deal)
- _fn_hascard(node, deal)
- _fn_hcp(node, deal, scale)
- _fn_if(node, deal)
- _fn_imps(node, deal)
- _fn_loser(node, deal)
- _fn_quality(node, deal)
- _fn_score(node, deal)
- _fn_shape(node, deal)
- _fn_suit(node, deal)
- _fn_trick(node, deal)
- _op_add(node, deal)
- _op_and(node, deal)
- _op_div(node, deal)
- _op_equal(node, deal)
- _op_geq(node, deal)
- _op_greater(node, deal)
- _op_leq(node, deal)
- _op_less(node, deal)
- _op_mod(node, deal)
- _op_mul(node, deal)
- _op_not(node, deal)
- _op_notequal(node, deal)
- _op_or(node, deal)
- _op_sub(node, deal)
- _re_namedpt = re.compile('(?:tens?)|(?:jacks?)|(?:queens?)|(?:kings?)|(?:aces?)|(?:top[2-5])|(?:c13)')
- _re_pt = re.compile('(?:pt[0-9])')
- _re_suit = re.compile('(?:spades?)|(?:hearts?)|(?:diamonds?)|(?:clubs)')
- evaluate(node: Union[Node, str], deal: Deal) float
Evaluate an expression tree over a specific deal into a logical or arithmetic type
- get_env(name: str) Any
- Returns:
The value of the named environment variable
- lambdify(node: Union[Node, str]) Callable[[Deal], Union[float, int, bool]]
Convert an expression tree (or string) into an anonymous function accepting a single
Deal
argument and returning the expression evaluated over this deal- Parameters:
node – The root of the expression tree, or a string containing an expression
- parse(s: str) Node
Parse an expression string into a syntax tree
- reset_env()
Reinitialise the environment to the default values
- set_env(name: str, value: Any)
Insert a new variable into the interpreter’s environment or change the value of an existing variable
- Parameters:
name – The name of the environment variable
value – The new value of the variable
- unset_env(name: str)
Remove an variable from the interpreter’s environment. Attempting to remove an essential variable (one of the ptN scale definitions) throws an error
- Parameters:
name – The name of the variable to remove