In Deal 2.0, we were able to define Vector functions, which assigned integer values to each card. This covered a lot of standard evaluation techniques, but not the more complicated forms. Evaluators like "quick tricks" and "losers," while still computed suit by suit and totaled, cannot be defined by assigning values to cards alone.
The solution is to allow the creation of general procedures for evaluating a holding, while still taking advantage of fast lookup tables. Thus, the introduction of the holdingProc command.
holdingProc
Commandto define a function calledholdingProc HCP {A K Q J} { expr {$A*4+$K*3+$Q*2+$J} }
HCP
. This function behaves exactly
the same as the builtin hcp
routine - the user can ask for
the total points in a hand or for a specific suit in the hand:
When evaluated, the parameter A is set to one if the holding has the ace, and zero otherwise.set n [HCP north] set hs [HCP north spades]
That's a simple example, but let's say we want to do some smart reevaluation. For example, we might want to add a point for each card in a suit beyond the fourth. We also might want to evaluate a stiff king as two points, rather than three, a stiff queen as zero, and a doubleton queen as one.
We can do this by adding a "length" parameter to the parameters list:
Even though this code is slow, it is only evaluated at most 160 times, after which values are reused, yielding remarkably fast evaluations. One deal, you might get a holding ofholdingProc SmartHCP {A K Q J length} { if {$length>=4} { # Normal evaluation, +1 for each card longer than the fourth return [expr {$A*4+$K*3+$Q*2+$J+($len-4)}] } if {$length==3} { # Normal evaluation for 3-card suits return [expr {$A*4+$K*3+$Q*2+$J}] } if {$length==2} { # Jacks in doubletons are worth zero, queens one return [expr {$A*4+$K*3+$Q}] } if {$length==1} { # Queens and jacks in singletons are worth zero, kings two return [expr {$A*4+$K*2}] } return 0 }
KQ75
which this routine evaluates
as if it were evaluating KQxx
. The next hand, it sees the
holding KQ82
and, seeing this also as KQxx
, remembers
the previous value.
If you want the return value interpreted as a double, you can specify it in the declaration. For example, we can define a quick tricks procedure:
holdingProc -double QuickTricks {A K Q J T length} { if {$A&&$K} { return 2 } if {$A} { return 1 } if {$K && ($Q || ($J && $T))} { return 1 } if {$K && $length>1} { return 0.5 } return 0 }
You can define the type to be any of the following:
-integer
-double
-boolean
spades hearts
" for the hand KT954 AJ32 94 92
.
-string
They can occur in any order.holdingProc SmartHCP {ace King QuizShow j len} { ... }
For spot cards, you can use arguments named "x2", "x3", "x4", .., and "x9." The ten can be passed as "x10" or "T."
One last possible parameter is anything beginning with an "s" or "S", which means that the holding is passed as a string. This is useful when you already have a hash table somewhere for stored data. For example, the 'ddeval' code which comes with iDeal and Deal 3.1 uses a table of raw data created in advance.
Thomas Andrews
(thomaso@best.com)
Copyright 1996-2002. Deal is covered by the
GNU General Public License.
Plane Dealing graphic above created using POV-Ray. |