File: reference.html

package info (click to toggle)
deal 3.1.9-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,576 kB
  • sloc: ansic: 5,224; cpp: 4,186; tcl: 3,125; makefile: 203; javascript: 21; sh: 10
file content (608 lines) | stat: -rw-r--r-- 20,484 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
     "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<!-- $Id: reference.html 313 2009-06-11 05:44:13Z thomasoa $ -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK REL="SHORTCUT ICON" HREF="/icon/bridge.ico">
<link rev="made" href="mailto:deal&#64;thomasoandrews.com (Thomas Andrews)">
<link rel="stylesheet" type="text/css" href="look.css">
<title>
    Deal - New Features in Version 2.0
</title>


</head>
<body>
<div class="toplevel back">
<A href="index.html">Back to <em>Deal Top Page</em></A>.
</div>

<table class="toplevel">
<tr>
<td valign="middle"><img
style="width:225px; height:216px"
src="graphics/falling_small.jpg" alt="Plane Dealing image"></td>
<td valign="middle" width="50%"><span class="header"><h1>Deal 2.0</h1>
<h2>Reference Guide</h2>
</span>
Covering: <UL>
<LI> Command line arguments
<LI> Additive Functions
<LI> Shape Functions and Classes
<LI> String Boxes and formatting
<LI> Often used Tcl features
<LI> Library routines
</UL>
</td>
</tr></table>
<div class="toplevel">
<hr>

<h2> Command Line Options </h2>

<DL>
<DT>	-e <var>expr</var>
<DD>		Evaluate the Tcl expression <var>expr</var>.  Not very
                useful, but occasionally good for setting variables
		which affect the user's script, like:
<pre class="codesample">
deal -i userscript -e "set maxnorth 10"
</pre>
<DT>	-v
<DD>            Verbose mode.  Lets you know how many hands have
		been accepted and how many hands have been tried.
<DT>	-[NSEW] <var>hand-spec</var>
<DD>		Specifies the cards held by the specified hand.
		The <var>hand-spec</var> should be of the form:
<span classs="code">"AK8532 - KQ72 A65"</span>.
		Voids must be represented with a '-' character.
		<var>hand-spec</var> should be <em>one</em> argument,
		so the string should be quoted on the command line.

<DT>	-i <var>file</var>
<DD>		Source the commands in the file named.  The language
		used is "Tcl".  Read the man page for Tcl for help
		in writing Tcl code. Additions to Tcl specific to deal are
		listed in this manual.

<DT> -x <var>file</var>
<DD> Like -i, except execute this file and then exit.
<DT>	-f
<DD>		Instead of dealing new hands, reads hands from
		standard input.  The hands must be in the format
		put out by "deal -l".  You might deal, say, 10,000
		hands which satisfy specific criteria, saving them
	        to a file.  Then you can use that output for input
		with deal -f to find out which hands satisfy other
		constraints.

<DT> -t
<DD>		Print <A href="dist.html">distribution table</A> and exit.
		The distribution table is an ordered list
		of all possible hand patterns for a single
		hand.

<DT> -l
<DD>		Write deals in a "single-line" format.  In previous
		releases this was the default format. It is useful
		for piping to formatters written in other languages.
		Most formatting can be defined internally, using
		Tcl now.  Still useful with the "-f" option.
		
</DL>

<h2> Simple Usage </h2>

The most basic usage of the program is to generate random deals
with no conditions:

<pre class="codesample">
% deal 2
	  S : QJ9
	  H : AJ
	  D : T52
	  C : AKQ84
 S : 752            S : AK83         
 H : T85            H : Q632         
 D : AK8763         D : J4           
 C : 2              C : T96          
	  S: T64
	  H: K974
	  D: Q9
	  C: J753
---------------------------
	  S : QJ9
	  H : 52
	  D : AKJT9
	  C : A86
 S : 763            S : A52          
 H : T763           H : J98          
 D : Q54            D : 876          
 C : T95            C : KQJ7         
	  S: KT84
	  H: AKQ4
	  D: 32
	  C: 432
---------------------------
</pre>

    If you want a raw format, more readable by external programs,
    use the -l flag, which prints deals in a single-line format:

<pre class="codesample">
% deal -l 5
K75 T987 AQT5 95|AQ86 2 943 QJ643|JT32 J43 KJ KT82|94 AKQ65 8762 A7
QJ96 KQ6 T95 K76|T5 J953 A72 AJT9|8432 A7 83 Q8432|AK7 T842 KQJ64 5
K52 QJT9 AKQ K63|AJ AK7542 T732 8|94 3 J965 QJT972|QT8763 86 84 A54
A76 A764 43 KJT2|J9 KJ53 K986 A87|K8543 T82 72 953|QT2 Q9 AQJT5 Q64
Q6 QJ75 3 AJ7642|AT9874 KT963 AT |K32 4 QJ2 KQ9853|J5 A82 K987654 T
</pre>



This output form is crude; it is meant to be post-processed.  Each
line is of the form:
<blockquote>
        &quot;<var>North</var>|<var>East</var>|<var>South</var>|<var>West</var>&quot;

</blockquote>
Each hand is specified by:
<blockquote>

	&quot;<var>Spades</var> <var>Hearts</var> <var>Diamonds</var> <var>Clubs</var>&quot;

</blockquote>
    where the space character separates each suit.

In the examples above, the east hand in the last deal is:
<pre class="codesample">
"AT9874 KT963 AT "
</pre>
which might be written more verbosely as:

<pre class="codesample">
S: AT9874   H: KT963   D: AT   C: ---
</pre>
I've included three formatters with the package, one of which creates
a TeX file for the hands generated, the other two simple text files.
The formatters are <A href="http://www.cis.ufl.edu/perl/">Perl</a> scripts, 
so if you don't have
Perl on your system they won't work.  To format, you just run deal with
the -l flag, and pipe to the formatter:

<pre class="codesample">
% deal -l 5 | perl ./compactdeal
Deal # 1          - AKQT43 AKT65 A3
JT65 82 QJ32 752                    AKQ82 6 94 KJ984
                  9743 J975 87 QT6
------------------------
Deal # 2          3 QJT43 A8742 K4
QT4 86 T93 AJ973                    AK52 2 QJ65 T862
                  J9876 AK975 K Q5
------------------------
Deal # 3          A76 KT9 QJ84 K53
T952 A832 A95 Q8                    J Q76 KT632 J762
                  KQ843 J54 7 AT94
------------------------
Deal # 4          AQ752 J632 - 8652
6 AK74 A863 AKT9                    KJ98 Q95 J752 QJ
                  T43 T8 KQT94 743
------------------------
Deal # 5          A4 AJ72 852 AKQT
63 T9654 QT9 865                    QJ852 Q J764 J94
                  KT97 K83 AK3 732
------------------------
</pre>

<pre class="codesample">
% deal -l 2 | perl ./formatdeal
Deal 1         S : 75                     |
               H : Q4                     |
               D : QJ962                  |
               C : AT64                   |
     S : KQ63           S : J98           |
     H : K732           H : T985          |
     D : K75            D : A843          |
     C : 83             C : J2            |
               S : AT42                   |
               H : AJ6                    |
               D : T                      |
               C : KQ975                  |
-------------------------------------------
Deal 2         S : AKQJ                   |
               H : J43                    |
               D : KQ4                    |
               C : 762                    |
     S : 73             S : 9865          |
     H : QT76           H : AK82          |
     D : J972           D : T86           |
     C : JT4            C : A9            |
               S : T42                    |
               H : 95                     |
               D : A53                    |
               C : KQ853                  |
-------------------------------------------
</pre>


<h2>Putting Conditions on the Deal</h2>

    There are two distinct types of conditions which can be placed on
    a hand.
<p>
    One is the rigid placement of cards, as in, `South gets the ace of
    clubs,' or `East is "AK52 AK32 9652 6"'.  Card placements are done
    before any randomnizations.
<p>

    Card placements are ignored when using deal with the -f option.  This
    is because `deal' is reading already built hands.

<p>
    The other conditionals are evaluated conditionals, like "South 
    has at least 4 hearts" or "West has 11 to 15 HCP" or "North has
    exactly one of the ace and king of clubs."
<p>

    The flow of control is:
<OL>
<LI> Place known cards
<LI> Deal rest of the cards at random
<LI> Determine whether to accept or reject deal.  If rejected,
                go to 2.
</OL>

This is less than optimal in many ways.  The <a href="Optimization.html">optimizing problem</a> here
is pretty painful, though, and, although I have some ideas for solutions,
I'm trying to be careful to do it right; in the meantime, this
method will have to do.

<p>
Scripts use the Tcl language, with bridge-related additions.
To understand these scripts, you should read the Tcl man
page.

<p>

An example script (ex/1.tcl from the kit):
<blockquote>
<pre>
##############################################
# Look for deals where north has 44 in the majors, a short minor,
# and 11-15 HCP.
# To execute:
#       deal -i ex/1.tcl [num]
##############################################
main {
                                          # Pitch deals
                                          # where north does
                                          # not have four spades
        reject if {[spades north]!=4}

                                          # Pitch deals
                                          # where north does
                                          # not have four hearts
        reject if {[hearts north]!=4}

                                          # Pitch deals
                                          # where north has
                                          # 2 or 3 diamonds
        set d [diamonds north]
        reject if {$d==2} {$d==3}

                                          # Accept deals
                                          # where north has
                                          # 11-15 HCP.
        set hcp_n [north]
        accept if {$hcp_n>=11 && $hcp_n<=15}
}
##############################################
</pre>
</blockquote>
The "main" command defines the expression which is to be evaluated
to ascertain whether a deal is accepted or rejected.  This occurs after
all cards have been dealt.  If the hand is never explicitly accepted,
the hand is rejected.

<p>
We can run this example as:
<blockquote>
<pre>
        % deal -i ex/1.tcl 10
</pre>
</blockquote>

This will produce ten deals where north has a mini-Roman hand with
a short minor.
<p>

"deal" takes a "-v" flag which lets the user know about progress
in the hand generation; how many hands have been searched, and
how many have been checked.

<blockquote>
<pre>
% deal -l -v -i ex/1.tcl 5
KJ92 AQ42 7 K842|8 KT9763 A862 95|Q73 J JT94 QJ763|AT654 85 KQ53 AT
Deal 1 found after 61 tries
AJ62 AQ84 9 J764|K84 J2 875 KT932|QT T73 AJ643 Q85|9753 K965 KQT2 A
Deal 2 found after 269 tries
JT86 AQJ8  KQ543|9 T9432 542 A976|K7532 K6 KQJ7 T2|AQ4 75 AT9863 J8
Deal 3 found after 303 tries
A652 AT94 A985 2|3 QJ532 T63 J543|QT74 8 K7 KT9876|KJ98 K76 QJ42 AQ
Deal 4 found after 394 tries
AJ65 9743 K AJT8|T742 T6 T764 972|KQ83 AQ5 Q32 643|9 KJ82 AJ985 KQ5
Deal 5 found after 523 tries
</pre>
</blockquote>
The progress output is sent to "stderr", so you can still pipe the
hands to a formatter or file without trouble.
<p>
You can specify on the command line that you want South to hold a specific
hand:
<blockquote><pre>
        % deal -v -i ex/1.tcl -S 'AK52 42 K52 7642' 10
</pre></blockquote>

Here are some of the procedures built in to the program which
have been added to Tcl for <b>Deal</b>.

<DL>
<DT> accept                
<DD>        Accept the current deal.  Use only from "main".
<DT>    accept if <var>expr</var> [<var>expr</var>...]
<DD>                                Accept the current deal if one of
                                the expressions is true.  Use only
                                from "main".  Stops evaluating
                                <var>expr</var>s when it finds a true one.
<DT>        accept unless <var>expr</var> [<var>expr</var>...]
                        <DD>        Accept the current deal unless one of
                                the expressions is true.  Use only
                                from "main".  Stops evaluating <var>expr</var>s
                                when it finds a true one.
<p>
<DT>             reject        <DD>        Reject the current deal.  Use only
                                from "main".
<DT>        reject if <var>expr</var> [<var>expr</var>...]
                        <DD>        Reject the current deal if one of
                                the expressions is true.  Use only
                                from "main".  Stops evaluating
                                <var>expr</var>s when it finds a true one.
<DT>        reject unless <var>expr</var> [<var>expr</var>...]
                        <DD>        Reject the current deal unless one of
                                the expressions is true.  Use only
                                from "main".  Stops evaluating
                                <var>expr</var>s when it finds a true one.
<p>
<DT>        spades <var>hand</var>,        hearts <var>hand</var>,
        diamonds <var>hand</var>, clubs <var>hand</var>        
<DD>        Returns the number of cards held in the suit by hand <var>hand</var>
<p>
<DT>        controls <var>hand</var> [<var>suit</var>]
                        <DD>        Return the number of controls (A=2,
                                K=1) held in the suit given.  If no
                                suit given, the total number of
                                controls.
<p>
<DT>        <var>hand</var> is <var>hand-spec</var>
<DD> This places all the cards of one hand.
The hand spec looks like:
<blockquote> <code>
"AKQ - T642 QT9876"
</code></blockquote>
The format is pretty inflexible.
Example:

<blockquote> <code>
east is "AKQ AKQ AKQ AKQT"
</code></blockquote>

This is the same as saying:
<blockquote> <code>
-E 'AKQ AKQ AKQ AKQT'
</code></blockquote>
on the command line.
<p>
<DT> <var>hand</var> gets <var>card</var> [<var>card</var>...]
<DD> Places individual cards in to the hand.
Example:
<blockquote> <code>
north gets AC
</code></blockquote>
places the ace of clubs in the north hand.
<p>
<DT>        <var>hand</var> has <var>card</var> [<var>card</var>...]
<DD>                                Checks to see if the hand holds
                                the specified cards, e.g.
<blockquote> <code>
                                if {[north has AC]} {...}
</code></blockquote>
<p>

<DT>        <var>hand</var> shape    
<DD>       Returns a string of the 4 suit lengths, in the order S,H,D,C, e.g.
<blockquote> <code>
puts stderr [south shape]<br>
4 3 2 4
</code></blockquote>
<p>

<DT>        <var>hand</var> pattern  
<DD>       Return a string of the 4 suit lengths, sorted in descending
order:
<blockquote> <code>
puts stderr [south pattern]<br>
4 4 3 2
</code></blockquote>
  <p>                              
<DT>        <var>hand</var>        
<DD> Return the HCP total for the hand,  e.g.
<blockquote> <code>
reject if {[north]>=16}
</code></blockquote>
<blockquote>
[Design note: this treatment might go away.   I have serious problems
with making high card points so prominent, and <code>[south]</code> might
be better used as a method of extracting a tcl list like: <code>
{AK} {QJ65} {T9872} {53}
</code>. If I were to do this, I would add a function, <code>hcp</code>.
Of course, you can implement the hcp function
yourself with <code>defvector</code>. ]
</blockquote>
<DT>        defvector <var>name</var> <var>val</var> [<var>val</var> ...]

<DD> A vector is a fast counting procedure.  The "vector" for counting
HCP is (4,3,2,1,0,0,0,0,0,0,0,0,0).  We can define
<blockquote><code>
defvector Hcp 4 3 2 1
</code></blockquote>

and then use "Hcp" as a procedure later:

<blockquote><code>
reject if {[Hcp north]>=16}
</code></blockquote>

Or
<blockquote><code>
defvector Top3 1 1 1
</code></blockquote>

creates a procedure for counting how many aces, kings, and queens are held.
<p>
One nice thing about these routines is that they are fast.
Clever use of vectors speeds up all sorts of evaluation routines.
<p>
<DT>        <var>vector</var> <var>suit</var> [<var>suit</var> ...]
<DD>        Counts the hand using the vector.
If a list of suits is given, only those
suits are counted.  Otherwise, all suits
are counted.  E.g., 
<blockquote><code>
defvector AKQ 3 2 1<br>
AKQ south hearts spades
</code></blockquote>
counts the Ace-King-Queen points held by the south hand in hearts and spades.
<p>
<DT>        shapeclass <var>name</var> { <var>code</var> } 
<DD>                                This, like defvector, is an optimization
                                issue.  E.g.,

<blockquote><code>
shapeclass michaels {return [expr $h>=5 && $s>=5]}<br>
main { accept if {[michaels north]}}
</code></blockquote>
A shapeclass generates a lookup table 
the first time it is called, and fast
shape matching occurs each time after.
  <p>                              
<DT> shapecond <var>name</var> { <var>expression</var> }
<DD>  This is just a shorthand for:
<blockquote>
<code>
shapeclass <var>name</var> {return [expr <var>expression</var>] }
</code>
</blockquote>

<DT>        <var>definedclass</var> <var>hand</var>
<DD>                                Returns true if the hand is in the shape
                                class and false otherwise.
<p>
<DT>        <var>definedclass</var> compile
<DT>
<DD>        Returns a string of 0's, 1's and whitespaces
        for faster shapeclass reuse.  Really for my personal use,
        but included here for completeness.
<p>

<DT>        shapeclass.binary <var>name</var> { <var>bits</var> }
<DD>        This is how to define the "compiled" form of the shapeclass
        definitions, only really useful for shape
        classes which are reused often.
<p>
<DT>        balanced <var>hand</var>
<DD>        Returns true if the hand is "balanced"
        in the classical Goren-style:  4333s,
        4432s, and 5332s with 5-card minor.
        This could be implemented as a shapeclass,
        but there still remains an internal definition
        which is pretty fast.
<p>
<DT>        losers <var>hand</var> [<var>suit</var> ...]
<DD>                                Returns the number of losing tricks for
                                the hand, or, if suits are given, the
                                number of losing tricks in those suits.
<p>
<UD>

    You can, of course, create new routines with Tcl, and then call
    them from the "main" procedure.

</DL>

There are many examples in the kit; look them over.  There is also
a file called "library" which defines some useful procedures.

<h1>Hints</h1>

    Clever use of count vectors can solve many problems efficiently.
    For example, if you and your partner play that a weak two promises
    2 of the top 3 <em>or</em> 3 of the top 5, you could define:

<code><blockquote>
        defvector Weak2Quality 2 2 2 1 1
</blockquote></code>

    This vector evaluates to 4 or greater whenever the suit has the
    right quality, so we could check for a weak-two spade suit with:

<code><blockquote>
        reject if {[spades north]!=6} {[Weak2Quality north spades]<4}
</blockquote></code>

    The program doesn't do much optimization, but you can do some
    yourself.  Try not to use logical conjunctions in "require" and "accept"
    parameters. It is better to say:

<code><blockquote>
        accept unless {[north]<13} {[hearts north]<7}
</blockquote></code>

   than to say:

<code><blockquote>
        accept if {[north]>=13 && [hearts north]>=7}
</blockquote></code>

   That's because the {[hearts north]<7} expressions doesn't get
   evaluated if {[north]<13} evaluated as true.
<p>
   It is even better to do:

<code><blockquote>
        accept unless {[hearts north]<7} {[north]<13} 
</blockquote></code>

   Why?  Because you are eliminating more hands initially.  (Also,
   the suit-length functions are faster than most since the numbers
   are incidentally calculated at deal-time.)
<p>
   Automated optimization is another area which I'm considering for
   later versions of this program.

<h1>Who to Blame</h1>
Questions, comments and great thoughts are welcome.  Just send me email
at the address at the bottom of this page.

<hr>
<table><tr><td><a href="http://bridge.thomasoandrews.com/" class="image">
<img style="border:0;width:40px;height:56px" alt="Silhouette" src="graphics/StampSm.gif"></a><td>
<a NAME="mysig"> Thomas Andrews</a>
(<a href="mailto:deal&#64;thomasoandrews.com">deal&#64;thomasoandrews.com</a>)
<a name="caveat"> Copyright 1996-2005.</a>  Deal is covered by the 
<a href="http://www.gnu.org/copyleft/gpl.html">GNU General Public License.</a>
</tr></table>
</div>
</body>
</html>