File: commands.html

package info (click to toggle)
deal 3.0.8-2sarge1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,048 kB
  • ctags: 715
  • sloc: ansic: 5,098; tcl: 2,983; makefile: 189
file content (1691 lines) | stat: -rw-r--r-- 53,619 bytes parent folder | download | duplicates (2)
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
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
<head>
<title>Deal Commands</title>
<body bgcolor="#EEEEFF">
<h1>Introduction</h1>
<table width="100%" cellpadding=5><tr valign=top><td width="65%">
This is meant to be a comprehensive list of commands in Deal which
are not native to Tcl.  If you want to learn Tcl, I will be providing
a set of pointers later.
<td width="35%">
<table border=2 bgcolor="#DDEEFF" width="100%"><tr><td>
<font size=-1 color="#000066">Text in blue is meant for Tcl afficianado
- reading this text without knowledge of Tcl might confuse more than
enlighten.</font><br>
</table>
<br>
<table border=2 bgcolor="#EEFFDD" width="100%"><tr><td>
<font size=-1 color="#006600">Text in green is meant for programmers
interested in finding code definitions.</font>
</table></table>
<hr>

<a name="north"></a><a name="east"></a><a name="south"></a><a name="west"></a>
<a name="hand"></a>
<a name="shape"></a><a name="pattern"></a>
<h1>Hand commands: <code>north</code>, <code>east</code>, <code>south</code>, <code>west</code>, <code>hand</code></h1>
<table cellpadding=5 width="100%">
<tr valign="top"><td width="65%">
<h2>Usage</h2>
<blockquote><pre>
east [ -void <em>string</em>] [ <em>suitname</em> ... ]
hand {<em>hand string</em>} [ -void <em>string</em>] [ <em>suitname</em> ... ]

south <em>subcommand</em> [ <em>... args ...</em> ]
hand {<em>hand string</em>} <em>subcommand</em> [ <em>... args ...</em> ]
</pre></blockquote>
These are very strange commands - they really have too much stuffed
into them.  That's a historical anomoly which I'm reluctant to abandon.
<p>
With no subcommands, the routine is used for formatting the hand as
a string. For example, if south is:
<blockquote><pre>
S: AJ5432
H: KT94
D: void
C: K93
</pre></blockquote>
Then the results of various commands are:
<blockquote><pre>
south                    =>    {AJ5432 KT94 {} K93}
south spades             =>    AJ5432
south hearts clubs       =>    {KT94 K93}
south -void -            =>    {AJ5432 KT94 - K93}
south -void --- diamonds =>    ---

set h {AK4 {} A95432 JT98}
hand $h                  =>    {AK4 {} A95432 JT98}
hand $h spades           =>    AK4
hand $h hearts clubs     =>    {{} JT98}
hand $h -void -          =>    {AK4 - A95432 JT98}
</pre></blockquote>
The -void switch exists precisely for formatting the output.
<p>
The various subcommands will be treated in seperate sections.

The <code>hand</code> version of this command only works with some subcommands.
</td><td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>C code
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>tcl_hand_cmd</code>
</dl>
</font>
</table></td><tr valign=top><td width="65%">
<h2>Subcommand: <code>shape</code></h2>
<h3>Usage</h3>
<blockquote><pre>
north shape
hand {AJTxx Axx JTxx x} shape
</pre></blockquote>
<h3>Summary</h3>
Returns a list of suit lengths, in standard order.
<p>
For example, the second command above would return the list:
<blockquote><pre>
5 3 4 1
</pre></blockquote>
<h2>Subcommand: <code>pattern</code></h2>
<h3>Usage</h3>
<blockquote><pre>
north pattern
hand {AJ32 A5 JTxx xxx} pattern
</pre></blockquote>
<h3>Summary</h3>
Returns a sorted list of the suit lengths, starting with the longest.
For example, the second command above would return the list:
<blockquote><pre>
4 4 3 2
</pre></blockquote>
<h2>Subcommand: <code>is</code></h2>
<h3>Usage</h3>
<blockquote><pre>
south is {<em>handstring</em>}
</pre></blockquote>
<h3>Summary</h3>
This command pre-places a specific 13 cards. For voids, you can use
the "<code>-</code>" character:
<blockquote><pre>
south is {AJ32 KT932 - Q876}
</pre></blockquote>
Calls to this subcommand must occur before dealing begins, outside the
"<code><a href="#main">main</a></code>" command.  
<p>
This subcommand calls the <a href="#stack_hand"><code>stack_hand</code> command.</a>
Inside the <code>main</code> code, the deal is already dealt.
<h2>Subcommand: <code>gets</code></h2>
<h3>Usage</h3>
<blockquote><pre>
<em>handname</em> gets <em>card</em> [<em>card</em> ...]
</pre></blockquote>
<h3>Summary</h3>
Puts a specific list of cards in the hand named.  As with the
"<code>is</code>" subcommand, this must be called before dealing
starts, outside the "<code><a href="#main">main</a></code>" command.
The card is specified in two characters, a rank character and a suit
character:
<blockquote><pre>
AS KH JH 9D
</pre></blockquote>
This routine dispatches its data to <a href="#stack_cards">the <code>stack_cards</code> command.</a>

<h2>Subcommand: <code>has</code></h2>
<h3>Usage</h3>
<blockquote><pre>
<em>handname</em> has <em>card</em> [<em>card</em> ...]
hand {<em>string</em>} has <em>card</em> [...]
</pre></blockquote>
<h3>Summary</h3>
This returns a count of the cards listed that occur in the hand named.
<blockquote><pre>
% south
AJ54 JT54 43 654
% south has SA HK HJ HT
3
</pre></blockquote>
</td><td width="35%">&nbsp;</td></table>
<hr>
<h1>Control commands</h1>
<a name="accept"></a><a name="reject"></a>
<h2>Commands: <code>accept</code> and <code>reject</code></h2>
<table width="100%" cellpadding=5><tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
accept [ [ if | unless ] <em>expr expr ...</em>]
reject [ [ if | unless ] <em>expr expr ...</em>]
</pre></blockquote>
<h3>Summary</h3>
Without arguments, <code>accept</code> and <code>reject</code> are the
same as <nobr><code>return 1</code></nobr> and <nobr><code>return
0</code></nobr>, respectively.  
<p>
With arguments it's a little more obscure.
<blockquote><pre>
accept if {$h>4}
</pre></blockquote>
This returns 1 if the expression matches.  It is equivalent to:
<blockquote><pre>
if {$h>4} { return 1 }
</pre></blockquote>
The code:
<blockquote><pre>
accept if {$h>4} {$s>4}
</pre></blockquote>
Is logically equivalent to:
<blockquote><pre>
if {$h>4 || $s>4} { return 1}
</pre></blockquote>
That is, the values are accepted if either of the expressions
evaluates as true.
<p>
The <code>unless</code> option does the opposite:
<blockquote><pre>
accept unless {$h>4} {$s>4}
</pre></blockquote>
This is equivalent to:
<blockquote><pre>
if {!($h>4) || !($s>4)} { return 1 }
</pre></blockquote>
<p>
The means we return with a true value <em>unless</em> one of the expressions
is true.  If one of the values is true, we simply go on to the next line.
<p>
<h3>Examples</h3>
Virtually all of the examples included in the release contain an
instance of "accept" or "reject."

<td width="35%">
<table border=2 bgcolor="#EEFFDD" width=100%>
<tr valign=top>
<td>
<dl>
<font size="-1" color="#006600"><b>For Programmers:</b><p>
<dt>Implementation:</dt>
    <dd>C code</dd>
<dt>Location:</dt>
    <dd>tcl_deal.c, procedure <code>tcl_deal_control</code>.</dd>
</dl>
This construct is borrowed from the Perl programming language.
Originally, I added it to Deal 2.0 for performance reasons.  Those
reasons are obsolote with Tcl 8.x, but I like the mnemonic enough
to keep it, and removing it might confuse old users.</font>
</table><br>
<table border=2 bgcolor="#DDEEFF" width=100%>
<tr valign=top><td>
<font size="-1" color="#000066"><b>For Tcl Experts:</b><p>
There actually is one subtle and occasionally useful distinction
between <code>accept/reject</code> and the stated "<nobr><code>if {...} { return ... }</code></nobr>"
version.  In reality:
<blockquote><pre>
accept if {$h>4} {$s>4}
</pre></blockquote>
is equivalent to:
<blockquote><pre>
if {$h>4||$s>4} { 
    return 1
}
expr 0
</pre></blockquote>
This only matters when the command is the last
command in a procedure.  The two procedures:
<blockquote><pre>
proc A {h s} {
    if {$h>4||$s>4} {
        return 1
    }	
}

proc B {h s} {
     accept if {$h>4} {$s>4}
}
</pre></blockquote>
are slightly different.
A call of <code>A 3 3</code> returns an empty string, while a call
of <code>B 3 3</code> returns 0. That can be useful, as you can see
here.</font></td>
</table>
</table>

<hr>
<a name="main"></a>
<h2>Command: <code>main</code></h2>
<table cellspacing=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
main {
   <em>block of code</em>
}
</pre></blockquote>

<h3>Summary</h3>
This defines the primary block of code evaluated after <em>each</em>
deal is generated.  If the code <em>returns</em> true,
<bold>Deal</bold> will treat the deal as a "match" and call
<bold>write_deal</bold>. It will also increment its count of deals
found and exit if the limit is reached.
</td><td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td><font size=-1 color="#006600" size=-1><b>For Programmers</b><p>
<dl><dt>Implementation:</dt><dd>C code</dd>
<dt>Location:</dt><dd>tcl_deal.c, procedure <code>tcl_deal_control</code>.
</dl>
</tr></tr></table>
</table>
<hr>

<a name="whogets"></a>
<h2>Command: <code>whogets</code></h2>
<table cellspacing=5 width="100%">
<tr valign=top><td width=65%">
<h3>Usage</h3>
<blockquote><pre>
whogets <em>cardname</em>
</pre></blockquote>
This returns the name of the person holding the card <em>cardname</em>.
</td><td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td><font size=-1 color="#006600" size=-1><b>For Programmers</b><p>
<dl><dt>Implementation:</dt><dd>C code</dd>
<dt>Location:</dt><dd>tcl_deal.c, procedure <code>tcl_deal_to_whom</code>.
</dl>
</td></tr>
</table>
</table>

<a name="deal_finished"></a>
<h2>Command: <code>deal_finished</code></h2>
<table cellspacing=5 width="100%">
<tr valign=top><td width=65%">
<h3>Usage</h3>
<blockquote><pre>
deal_finished {
   <em>block of code</em>
}
</pre></blockquote>
This defines the code called at the completion of generating all deals.
This is code you would use to dump statistics, for example.
</td><td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td><font size=-1 color="#006600" size=-1><b>For Programmers</b><p>
<dl><dt>Implementation:</dt><dd>C code</dd>
<dt>Location:</dt><dd>tcl_deal.c, procedure <code>tcl_after_set</code>.
</dl></tr></td></table>
</table>


<hr>
<h1>Bridge Evaluators</h1>
<h2>Common interfaces</h2>
There are some standard interfaces to bridge evaluation functions.
<a name="handInterface"></a>

<h3>Hand Procedures</h3>
Any procedure defined entirely based on the values in one hand is considered
a <em>hand procedure</em>.  These procedures can be called in one of two
ways:
<blockquote><pre>
Weak2Bid <em>handname</em>

Weak2Bid hand {AKQxxx xxx xxx x}
</pre></blockquote>
The <em>handname</em> parameter can be one of
<code>north</code>, <code>south</code>, <code>east</code>, <code>west</code>.
<a href="#shapes">Shape procedures</a> and <a href="#holdingp">holding
procedures</a> fit the hand procedure calling method, along with other
options.
<hr>
<a name="shapes"></a>
<h3>Shape procedures</h3>
Any procedure defined on the shape of a hand can be called with one of
the following methods:
<blockquote><pre>
balanced <em>handname</em>

balanced hand {AJ43 AKxx xxx K5}

balanced eval 4 3 4 2

balanced shape {4 3 4 2}
</pre></blockquote>
This follows the <a href="#hand">hand procedure</a> outline with the
addition of the <code>eval</code> option.
<p>
<hr>
<a name="holdingp"></a>
<h3>Holding procedures</h3>
A holding procedure is a <a href="#handInterface">hand procedure</a>
which is evaluated on a bridge hand by evaluating each suit holding
one at a time, and then accumulate the results.  There are two
common ways of defining holding procedures,
<a href="#defvector"><code>defvector</code></a> and
<a href="#holdingProc"><code>holdingProc</code></a>.  
<p> This is an
abstraction of a very common bridge evaluation technique.  The most
commonly used holding functions are  <em>high card points</em>,
<em>losing trick count</em>, <em>controls</em>.  For example, when
counting the losers in the hand <code>AKxx Axx KQJxxx x</code>, we
find 1 loser in spades, 2 losers in hearts, 1 loser in diamonds,
and one loser in clubs.  We define the total losers to be the sum
across all suits, and get 5 losers, total.  <p> The interface lets
you evaluate the entire hand, or only selected suits in a hand, or
a specific list of holdings.

<blockquote><pre>
hcp <em>handname</em> [ <em>suitname</em> ...  ]

hcp hand {AKJxxx K xxx xxx} [ <em>suitname</em> ...  ]

hcp holding AK43 [ ... ]
</pre></blockquote>
In the first two cases, if no suits are named, all suits are evaluated, and
the results are accumulated.  In the case of the <code>holding</code> call,
the specific holdings passed in are evaluated.
<p>
Note, I've been saying "accumulated" rather than added.  In some cases,
you might have an accumulation method different from addition.  For example,
you might return the standard opening leads from a holding:
<blockquote><pre>
    openingLead holding KQJ7    =>   K
    openingLead south           => {K} {7 2} {4} {J}
</pre></blockquote>
Each suit would create a list of proposed leads, and the result would be
a list of lists of all standard leads from all holdings.  Here, the
accumulation is to simply make a list.
<hr>

<a name="balanced"></a>
<a name="semibalanced"></a>
<h2>Command: <code>balanced</code> and <code>semibalanced</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
balanced <em>handname</em>

balanced hand {<em>text hand</em>}

balanced eval <em>s</em> <em>h</em> <em>d</em> <em>c</em>
</pre></blockquote>
<h3>Summary</h3>
These are both <a href="#shapes">shape procedures</a>.
<p>
<code>balanced</code> returns true if the hand is some 4333, 4432, or 5332
without a 5-card major.
<p>
<code>semibalanced</code> returns true if the hand has no singletons
 or voids, not six-card majors, and no seven-card minors.
<td width="65%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd><code>Tcl</code> with <code>shapecond</code>
<dt>Location:</dt>
<dd><code>deal.tcl</code>
</dl>
These use to be hard-coded in the C code, but it made more sense
to add them to the library code - the user can change the definitions
as he likes.
</font>
</table>
</table>
<hr>

<a name="clubs"></a>
<a name="diamonds"></a>
<a name="hearts"></a>
<a name="spades"></a>
<h2>Commands: <code>clubs</code>, <code>diamonds</code>, <code>hearts</code>, <code>spades</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
     <code>spades</code> <em>handname</em>
     <code>spades</code> <code>hand</code> <code>{AKxx Axx AJxx Kx}</code>
</pre></blockquote>
These implement the <a href="#hand">hand procedure</a> interface, and
return the suit lengths for the appropriate suit.
<td width="65%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>tcl_suit_count</code>
</dl>
These could be <em>shape procedures</em> but for speed reasons, I've
left them this way.
</font>
</table>
</table>
</center>
<hr>

<h1>Holding Evaluators</h1>
<a name="hcp"></a>
<h2>Command: <code>hcp</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
hcp <em>handname</em>
hcp <em>handname</em> <em>suitname</em> [<em>suitname</em> ...]
hcp hand {<em>s h d c</em>}
hcp hand {<em>s h d c</em>} <em>suitname</em> [<em>suitname</em> ...]
</pre></blockquote>
This procedure computes standard high card points - ace is 4, king
is 3, queen is 2, jack is 1. The procedure implements the 
<a href="#holdingp">holding procedure</a> interface.
<td width="65%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl>
<dt>Implementation:
<dd>C code
<dt>Location:
<dd>Built with additive.c, <code>tcl_create_additive</code>
      and deal.c, <code>count_hcp</code>
</dl>
</font>
</table>
</table>
</center>
<hr>
<a name="losers"></a>
<h2>Command: <code>losers</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
losers <em>handname</em>
losers <em>handname</em> <em>suitname</em> [<em>suitname</em> ...]
losers hand {<em>s h d c</em>}
losers hand {<em>s h d c</em>} <em>suitname</em> [<em>suitname</em> ...]
</pre></blockquote>
This implements a <a href="#holdingp">holding procedure</a> which
computes the number of <em>half losers</em>.  This is for historical reasons -
the only holding functions allowed in past releases returned integer
values, but I wanted to have some refinements over raw losing trick count.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>C code
<dt>Location:</dt>
<dd>Built with additive.c, <code>tcl_create_additive</code>
      and deal.c, <code>count_hcp</code>
</dl>
It is probably better to reimplement in <code>Tcl</code> using
<a href="#holdingProc"><code>holdingProc</code></a>.
</font>
</table>
</table>
</center>
<hr>

<h1>Bridge Logic and Utilities</h1>
<a name="lho"></a>
<a name="rho"></a>
<a name="partner"></a>
<h2>Commands: <code>lho</code>, <code>partner</code>, <code>rho</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
lho <em>handname</em>
rho <em>handname</em>
partner <em>handname</em>
</pre></blockquote>
<h3>Summary</h3>
These routines accept one hand name and return another. For example,
"<nobr><code>lho north</code></nobr>" returns "<code>east</code>," and
"<nobr><code>partner east</code></nobr>"
returns "<code>west</code>."
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>C code
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>tcl_other_hand</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="holding"></a>
<h2>Commands: <code>holding</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
holding length AJxx           =>     4

holding contains AJ64 A6      =>     1 (true)
holding contains AJ64 A65     =>     0 (false)

holding encode AJ4            =>     4612  (binary: 1001000000100 )

holding decode 4612           =>     AJ4

holding matches AKxx  AK42    =>     1 (true)

holding disjoint AJ65 KT82    =>     1 (true)
holding disjoint A65  A32     =>     0 (false)

holding index AKJ4 0          =>     A
holding index AKJ4 1          =>     K
holding index AKJ4 3          =>     4
holding index AKJ4 -2         =>     J
holding index AKJ4 10         =>     ""
</pre></blockquote>
<h3>Summary</h3>
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>C code
<dt>Location:</dt>
<dd><code>holdings.c</code>, function <code>IDeal_HoldingCmd</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="score"></a>
<h2>Command: <code>score</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
source lib/score.tcl
   ...
score <em>contract</em> <em>vulnerability</em> <em>tricks</em>
</pre></blockquote>
<h3>Summary</h3>
This routine computes the standard duplicate bridge score for a contract
from the point of view of declarer, if declaring side takes the given number
of tricks.
<p>
The <em>contract</em> is passed as a list:
<blockquote><pre>
2 spades

2 spades undoubled 

4 clubs doubled

6 notrump redoubled
</pre></blockquote>
The <em>vulnerablity</em> is one of the words <code>vul</code> or
<code>nonvul</code>.
<p>
The <em>tricks</em> is the number of tricks taken by declarer.
<h3>Examples</h3>
<blockquote>
<pre>
score {2 spades} nonvul 8           =>  110
score {2 spades doubled} nonvul 8   =>  470
score {2 spades redoubled} nonvul 8 =>  640
score {2 spades doubled} vul 8      =>  670
score {2 spades} nonvul 7           =>  -50
score {2 spades doubled} nonvul 7   =>  -100
score {2 spades doubled} vul 7      =>  -200
</pre>
</blockquote>

<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>Tcl
<dt>Location:</dt>
<dd><code>score.tcl</code>
</dl>
</font>
</table>
</table>
</center>
<hr>
<p>
<a name="gibstuff"></a>
<h1>GIB-related routines</h1>
These next routines use calls to the GIB double-dummy engine.  You must have
a licensed version of <a target="new" href="http://www.gibware.com/">GIB</a>
installed on your computer for these routines to work. Also, these
routines only work on Windows at the moment.
<p>
<a name="gib::directory"></a>
<h2>Command: <code>gib::directory</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
source lib/gib.tcl
   ...
gib::directory <em>path</em>
</pre></blockquote>
<h3>Summary</h3>
This tells the GIB-related routines where GIB is installed.
<p>
If this routine is not called, it defaults to GIB's default install
directory, <nobr><code>C:/Program Files/GIB</code>.</nobr>
<p>
<em>Note: your path should include forward slashes '<code>/</code>',
even on Windows.</em> 
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>Tcl</dd>
<dt>Location:</dt>
<dd><code>gib.tcl</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="gib::tricks"></a>
<h2>Command: <code>gib::tricks</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
source lib/gib.tcl
   ...
gib::tricks <em>declarer</em> <em>denomination</em>
</pre></blockquote>
<h3>Summary</h3>
<em>Denomination</em> can be a suit name or "<code>notrump</code>."
<em>Declarer</em> can be any hand name.
<p>
This routine returns the double-dummy number of tricks available
in this deal, in the given denomination by the given declarer.
<p>
If GIB is installed anywhere unusual, you will need to call
<a href="#gib::directory"><code>gib::directory</code></a> before
<code>gib::tricks</code> is called.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>Tcl</dd>
<dt>Location:</dt>
<dd><code>gib.tcl</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="parscore"></a>
<h2>Command: <code>parscore</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
source lib/parscore.tcl
   ...
set result [parscore <em>dealer</em> <em>vul</em>]

set contract [lindex $result 0]
set declarer [lindex $result 1]
set score [lindex $result 2]
set tricks [lindex $result 3]
set auction [lindex $result 4]
</pre></blockquote>
<h3>Summary</h3>
This computes the double-dummy par result for the hand.
<p>
The parscore routine returns a list of five values - the contract (in
the same form that is used by the <a href="#score"><code>score</code></a>
routine above), the declarer, the score for north/south, the number of
tricks taken, and a "stupid" auction to the contract suitable for putting
into a PBN file.
<p>
Dealer is relevant on a few occasions.  If both south and west can make
1NT, for example, and no 2-level contracts make, then "par" is 1NT by
whomever gets a chance to bid it first.
<p>
If GIB is installed anywhere unusual, you will need to call
<a href="#gib::directory"><code>gib::directory</code></a> before
<code>gib::tricks</code> is called.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>Tcl
<dt>Location:</dt>
<dd><code>parscore.tcl</code>
</dl>
</font>
</table>
</table>
</center>
<hr>


<h1>Bridge Command Builders</h1>

A number of common types of bridge functions can easily be implemented to
run quickly via lookup tables, including 
<a href="#holdingp">holding</a> and <a href="#shape">shape</a> procedures.
Deal lets the user take advantage of these two sorts of lookup procedures
relatively easily.

<a name="defvector"></a>
<h2>Command: <code>defvector</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
defvector <em>vec</em> <em>aceVal</em> [ <em>kingVal</em> ... ]

<em>vec</em> <em>handname</em>

<em>vec</em> <code>hand</code> {<em>text hand</em>}

<em>vec</em> <em>handname</em> <em>suitname</em> [ <em>suitname</em> ... ]

<em>vec</em> <em>handname</em> <em>suitname</em> [ <em>suitname</em> ... ]

<em>vec</em> <code>hand</code> {<em>text hand</em>} <em>suitname</em> ...
</pre></blockquote>
<h3>Summary</h3>
This defines a <a href="#holdingp">holding procedure</a> which assigns
integer values to the various cards in the hand.  For example
<blockquote><pre>
defvector hcp6421 6 4 2 1
</pre></blockquote>
Defines a holding procedure which counts the ace as worth 6 points, the
king as worth 4, the queen as 2, and the jack as 1.
<p>
Vectors are limited to being integer-valued.  For more complicated
holding procedures, use <a href="#holdingProc"><code>holdingProc</code></a>.
</pre></blockquote>
<td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
Implementation: C<br>
Location: <code>vector.c</code>
Vectors are slighly faster than their equivalent
<a href="#holdingProc"><code>holdingProc</code></a>.  They are an
old optimization which remain mostly for backwards compatibility.
</font>
</table>
</table>
</center>
<hr>

<a name="holdingProc"></a>
<h2>Command: <code>holdingProc</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
</pre></blockquote>
<p>
Temporarily, see the <a href="holding.html">seperate documentation</a>.
<td width="65%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><br>
Implementation: C<br>
Location: <code>holdings.c</code>, function <code>IDeal_DefHoldingProc</code>
</font>
</table>
</table>
</center>
<hr>

<a name="shapeclass"></a>
<a name="shapecond"></a>
<a name="shapefunc"></a>
<h2>Commands: <code>shapeclass</code>, <code>shapecond</code>, and <code>shapefunc</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
shapeclass <em>name</em> {... <em>code</em> ...}

shapecond <em>name</em> {<em>expr</em>}

shapefunc <em>name</em> {... <em>code</em> ...}

<em>name</em> [ north | south | east | west ]

<em>name</em> eval <em>s</em> <em>h</em> <em>d</em> <em>c</em>

<em>name</em> shape {<em>s</em> <em>h</em> <em>d</em> <em>c</em>}

</pre></blockquote>
A shape class (or equivalently, a shape condition) also has the list
subcommand:
<blockquote><pre>
<em>name</em> list
</pre></blockquote>
<h3>Summary</h3>
These commands create new procedures which fit the <a href="#shapes">shape
function</a> interface.
<p>
<code>shapeclass</code> and <code>shapecond</code> define procedures which returns boolean
values. <code>shapefunc</code> can return any type of data.
<code>shapecond</code> is actually an alias:
<blockquote><pre>
shapecond <em>name</em> {<em>expr</em>}
</pre></blockquote>
is the equivalent of:
<blockquote><pre>
shapeclass <em>name</em> {
  if {<em>expr</em>} {
    return 1
  } else {
    return 0
}
</pre></blockquote>
The <em>code</em> or <em>expr</em> is allowed to use the variables
<code>s</code>, <code>h</code>, <code>d</code>, or <code>c</code>.
<p>
More details can be found in the
<a href="advanced.html#shapefunc">Advanced Guide</a>.
<p>
The <code>list</code> subcommand for shape classes returns a list of
shapes that are in the class.
<p>
Why are there two subcommands, "eval" and "shape" which do the
roughly the same things?
<p>
Let's say you have a class named "SemiBalanced" already defined,
which includes 5-card majors.  You want to define a "Balanced"
class which excludes the 5-card majors.  You can do this with
the call:
<blockquote><pre>
shapecond Balanced {[SemiBalanced eval $s $h $d $c] && $s<5 && $h<5}
</pre></blockquote>

On the other hand, if you have a shape - output by the, say, a
call to [north shape] you can evaluate it as:

<blockquote><pre>
    SemiBalanced shape [north shape]
</pre></blockquote>

In fact, this is exactly equivalent to calling 

<blockquote><pre>
    SemiBalanced north
</pre></blockquote>

only slightly slower.

<td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr valign>
<td colspan=2><font size="-1" color="#006600"><b>For Programmers</b><br>
Implementation: C<br>
Location: <code>dist.c</code>, functions <code>tcl_shapeclass_define</code>,
<code>tcl_shapecond_define</code>, and <code>tcl_shapefunc_define</code>
</table>
</table>
</center>
<hr>

<a name="statistics"></a>
<h1>Statistics</h1>
<a name="sdev"></a>
<h2>Command: <code>sdev</code></h2>
<table cellpadding=5 width="100%">
<tr><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
sdev <em>name</em>

<em>name</em> add <em>data</em> [ <em>data</em> ... ]

<em>name</em> count

<em>name</em> average

<em>name</em> sdev

<em>name</em> rms
</pre></blockquote>
<h3>Summary</h3>

The "sdev" command defines a new Tcl procedure with the given name, which behaves as a 
data collection object.  You can add data points to it, or you can retrieve
the current number of data points, the average of the data points, the
standard deviation of the data points, or the "root mean square" of the
data points.
<p>

</td><td width="35%">
<table width="100%" border=2 bgcolor="#EEFFDD">
<td><font color="#006600" size=-1><b>For Programmers</b><br>
<dl><dt>Implementation:</dt><dd>C code</dd>
<dt>Location:</dt><dd>stat.c, function <code>tcl_sdev_define</code>.
</dl>
This was implemented in C for efficiency reasons - most real number
computations really need to be done in C if they are going to be done
frequently, and here, the "add" command is called quite often in normal
usage.
</table>
</table>
<hr>
<a name="correlation"></a>
<h2>Command: <code>correlation</code></h2>
<table cellpadding=5 width="100%">
<tr valign="top"><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
     correlation <em>name</em>

     <em>name</em> add <em>xval</em> <em>yval</em> [ <em>xval</em> <em>yval</em> ... ]

     <em>name</em> count

     <em>name</em> correlate

     <em>name</em> average [ x | y ]

     <em>name</em> sdev [ x | y ]

     <em>name</em> rms [ x | y ]
</pre></blockquote>
<h3>Summary</h3>
The <code>correlation</code> declaration defines a routine much like
the <code>sdev</code> command, but each datapoint is a pair of values,
and it computes the linear correlation between the <em>x</em> and <em>y</em>
values.
<p>
You can also get individual data for the <code>x</code> and <code>y</code>
values.
<p>
If there is no data, it returns an error on <code>average</code>,
<code>correlate</code>, <code>sdev</code> and <code>rms</code>.
<p>
If there is only one pair entered, it will throw an error on
<code>sdev</code>.
<p>
</td><td width="35%">
<table width="100%" border=2 bgcolor="#EEFFDD">
<td><font color="#006600" size=-1><b>For Programmers</b><br>
<dl><dt>Implementation:</dt><dd>C code</dd>
<dt>Location:</dt><dd>stat.c, function <code>tcl_correlation_define</code>.
</dl>
This was implemented in C for efficiency reasons - most real number
computations really need to be done in C if they are going to be done
frequently, and here, the "add" command is called quite often in normal
usage.
</table>
</table>

<h1>Utility Procedures </h1>


<a name="deal_deck"></a>
<h2>Command: <code>deal_deck</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal_deck
</pre></blockquote>
<h3>Summary</h3>
<code>deal_deck</code> is called at every new deal,
even when all 52 cards are specified (<em>stacked</em>) precisely.
Imagine stacking cards as stacking them in an undealt <em>deck</em>,
but that the cards are only distributed to the hands when
<code>deal_deck</code> is called.
<p>
Most of the time, you won't need to call deal_deck directly, but it is
useful to understand its behavior if you are going to write advanced
procedures like <a href="#deal::input">input formats.</a>
<p>
Stacked cards are permanently stacked until the deck is reset.  In this code:
<blockquote><pre>
    stack_hand south {AKQ32 AJ53 K54 2}
    deal_deck
    deal_deck
    puts [south spades]
</pre></blockquote>
The output is "AKQ32".  Use <a href="#reset_deck"><code>reset_deck</code></a>
to undo card stackings.
<p>
The <code>deal_deck</code> procedure does one thing rather complicated
when it is called, the first thing it does is execute  all
code registered with the 
<a href="#deal_reset_cmd"><code>deal_reset_cmds</code></a>.
This allows the script writer to do one of several things before
the deal is generated:
<ul>
<li>Delete metadata related to the deal.  For example, the first time
the user calls <code>gib::tricks south spades</code> it calls the 
GIB double-dummy processor.  Each time after that, it uses a stored
value for this function call up until the next call to
<code>deal_deck</code>.
<li>The reset command might, instead, read the next deal from a file,
stack the deck, and then re-register itself.  Then when deal_deck is
is called, it just deals that hand from the file.  This is a crude
way of allowing Deal to transparently read deals from a file (or generate
deals in other ways, such as <a href="#smartstack">smart stacking.</a>
</ul>
<a href="#deal::metadata">
<li>

<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>C
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>tcl_deal_deck</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="reset_deck"></a>
<h2>Command: <code>reset_deck</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
reset_deck
</pre></blockquote>
<h3>Summary</h3>
This forgets about all stacked cards.  The <em>deck</em>, from <em>Deal</em>'s
point of view, plus a list of cards which must go to specific hands.
The cards which are assigned to specific hands are "stacked."  The cards
which are not stacked can go anywhere at the next call to
<a href="#deal_deck">deal_deck</a>.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>C
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>tcl_reset_deck</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="stack_hand"></a>
<a name="stack_cards"></a>
<h2>Commands: <code>stack_hand</code> and <code>stack_cards</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
stack_hand <em>handname</em> <em>hand</em>
stack_cards <em>handname</em> <em>suitname</em> <em>holding</em> [...]
</pre></blockquote>
<h3>Summary</h3>
By default, these two routines just call <a href="#deck_stack_hand">
deck_stack_hand and deck_stack_cards,</a>
respectively - that is, they forcibly place cards in the deck.
<p>
But these routines are meant to be overridden.  For example, when using
one of the <em>input formats</em> which reads deals from a file,
the format will redefine these two procedures to give errors.
<blockquote><pre>
% deal -I "line foo.txt" -e "stack_cards south spades AJ"
Tcl stack dump of error info:
No card stacking with input format ::line
<em>...</em>
</pre></blockquote>
A more complicated re-definition occurs in the <a name="#smartstack">
<code>smartstack</code> input format,</a> which alters its hand
generation depending on what cards are stacked where.

<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl>
<dt>Location:</dt>
<dd><code>hand.c</code>, function <code>tcl_stack_hand</code> and
<code>tcl_stack_cards</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="deck_stack_hand"></a>
<a name="deck_stack_cards"></a>
<h2>Commands: <code>deck_stack_hand</code> and <code>deck_stack_cards</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deck_stack_hand <em>handname</em> <em>hand</em>
deck_stack_cards <em>handname</em> <em>suitname</em> <em>holding</em> [...]
</pre></blockquote>
<h3>Summary</h3>
These routines are the "underlying" deck-stacking routines.  Any cards
stacked with these routines remain stacked until the next call to
<a href="#reset_deck"><code>reset_deck</code></a>
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl>
<dt>Location:</dt>
<dd><code>hand.c</code>, function <code>tcl_stack_hand</code> and
<code>tcl_stack_cards
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="stacked"></a>
<h2>Command: <code>stacked</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
stacked <em>handname</em>
</pre></blockquote>
<h3>Summary</h3>
Determines what cards are stacked to this hand, returning them as
a list of holdings:
<blockquote><pre>
south gets AS KH 3H QD JD TC 9C 8C
puts [stacked south]
</pre></blockquote>
writes out the list:
<blockquote><pre>
A K3 QJ T98
</pre></blockquote>
This is useful for the <a href="#smartstack">smartstacker</a>, because
we don't want to force the user to stack cards *after* specifying conditions.
<blockquote><pre>
stack_hand north {AJT KT3 KJ 75432}
deal::input smartstack south balanced hcp 20 21
</pre></blockquote>
The call to <code>stack_hand</code> occurs before <code>smartstack</code>
is loaded, so <code>stack_hand</code> has not been redefined.  So what
<code>smartstack</code> does is read the cards already stacked, and
use that for its initial conditions.
<p>
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>tcl_stacked_cards</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<a name="deal::nostacking"></a>
<h2>Command: <code>deal::nostacking</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
::deal::nostacking
</pre></blockquote>
<h3>Summary</h3>
This procedure redefines the <a href="#stack_hand">stack_hand and
stack_cards</a> procedures to generate error messages, and
generates an error if any cards are currently stacked.
<p>
This is used in all of the input formats which read complete deals from
files, and thus are incompatible with stacking.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>
<dt>Location:</dt>
<dd><code>deal.tcl</code>, function <code>deal::nostacking</code>
</dl>
</font>
</table>
</table>
</center>
<hr>


<a name="deal_reset_cmds"></a>
<h2>Command: <code>deal_reset_cmds</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal_reset_cmds {<em>...code...</em>} [ ... ]
</pre></blockquote>
<h3>Summary</h3>
This adds a set of commands that are to be called before the next
deal.  The code is executed at the next call to the
<a href="#deal_deck"><code>deal_deck</code></a> procedure, which, unless
you are doing something complicated, means it is called at the beginning
of each time through the evaluation loop.
<p>
<code>deal_reset_cmds</code> can be used so that metadata about the previous deal,
such as cached values and the like, are unset.  See
<a href="#deal::metadata"><code>deal::metadata</code></a>.
<p>
It is also used for defining <a href="#deal::input">input formats,</a>
so that deals can be read from files.  For example, the "line" input format
has the following routine declared:
<blockquote><pre>
namespace eval line {
    #....
    proc next {} {
	variable handle
	set length -1
	catch { set length [gets $handle line] }

        # ... process the line, or handle oef stuff ...
        # ...
	deal_reset_cmds {::line::next}
    }
}
</pre></blockquote>
<p>
The key is that when line::next is done, it re-registers itself, making
sure that it is called next time through as well.
<p>
The <em>code</em> passed in to <code>deal_reset_cmds</code> is
called only once, at the next request for a deal - think of it as
registering a one-time trigger.  Multiple triggers can be registered -
they are called in the reverse order that they are added, which can seem
counter-intuitive until you think of the process as an "undo" process.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>
<dt>Location:</dt>
<dd><code>tcl_deal.c</code>, function <code>add_reset_cmds</code>
</dl>
This callback idea is fairly powerful, and will probably be clarified
and elaborated in later releases.  Unfortunately, initial efforts to use
it to alter the deal source (by say reading deals from a file) have
been mixed - Windows/DOS seems to choke occasionally on it.
</font>
</table>
</table>
</center>
<hr>

<a name="deal::metadata"></a>
<h2>Command: <code>deal::metadata</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal::metadata <em>name</em> {<em>...code...</em>}
</pre></blockquote>
<h3>Summary</h3>
Currently, this is just a peculiar way of caching slow evaluation routines.
At the moment, the only place it is used is in
<a href="#gib::tricks"><code>gib::tricks</code></a>.
<p>
When you call <code>deal::metadata</code>, it will check to see if
there is a value associated with the <em>name</em> requested 
already.  If there is, the value is returned.  If it does not, it evaluates the
specified code and associates the result with the <em>name</em>.  The key
is, when the next deal is being analyzed, all the cached values are pitched.
<p>
This isn't really necessary or efficient in most cases, but with
evaluations which take some time, <em>e.g.</em> GIB calls, it
improves things.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td colspan=2><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd><code>Tcl</code>
<dt>Location:</dt>
<dd><code>deal.tcl</code>
</dl>
In later releases, metadata read from input streams (say, the fields
from a PBN file) will also be stored here.
<p>
This procedure uses
<a href="#deal_reset_cmds"><code>deal_reset_cmds</code></a>.
The metadata is cleared each time the <code>deal_deck</code>
command is called.
</font>
</table>
</table>
</center>
<hr>
<h1>Input formats</h1>
<a name="deal::input"></a>
<h2>Command: <code>deal::input</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal::input <em>formatName</em> <em>args</em>
</pre></blockquote>
<h3>Summary</h3>
The <code>deal::input</code> command is used to define an input source
for deals. It works as follows:
<ol>
<li>The file <code>input/&lt;formatName&gt;.tcl</code> is loaded.  This
Tcl file should define a new Tcl 'namespace' with the name <em>formatName</em>,
with member procedures named <code>set_input</code> and <code>next</code>.
<li>Deal then calls 
<code>&lt;formatName&gt;::set_input <em>args</em></code>, which should
initialize the format reading.  Usually, the argument(s) are one argument
representing the source file.
<li>The next deal, <code>&lt;formatName&gt;::next</code> is called.
</ol>
</ol>
</td>
<td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr valign=top>
<td>
<dl>
<font size="-1" color="#006600"><b>For Programmers:</b><p>
<dt>Implementation:</dt>
    <dd>Tcl code</dd>
<dt>Location:</dt>
    <dd>deal.tcl</dd></dt>
</dl>
</table></table>
<hr>
<a name="giblib"></a><a name="library.dat"></a>
<h2>Input Format: <code>giblib</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal::input giblib [<em>filename</em>]
</pre></blockquote>
or on the command line:
<blockquote><pre>
% deal -I giblib
</pre></blockquote>
or
<blockquote><pre>
% deal -I "giblib <em>filename</em>"
</pre></blockquote>
<h3>Summary</h3>
Specifies that deals are read from the specified file in the format
of Matt Ginsberg's library.dat file.  This includes double-dummy tricks
data, so that later calls to <a href="#gib::tricks"><code>gib::tricks</code></a>
will not entail calls to the GIB binaries.
<p>
If no filename is given, the library tries to read from a file called
"library.dat" in the current directory.
<p>
The <code>-I</code> command-line flag is a quick alias for
<code>deal::input</code>, passing the next argument as
Tcl arguments to the <code>deal::input</code> command.
<td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr valign="top"><td>
<dl>
<font size="-1" color="#006600"><b>For Programmers:</b><p>
<dt>Implementation:</dt>
    <dd>Tcl code</dd>
<dt>Location:</dt>
    <dd>input/giblib.tcl</dd></dt>
This procedure uses <a href="#deal_reset_cmds">deal_reset_cmds</a>.
</dl>
</table>
</table>
<hr>
<a name="line"></a>
<h2>Input Format: <code>line</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal::input line [<em>filename</em>]
</pre></blockquote>
<h3>Summary</h3>
Specifies that deals are read from the specified file in the format
written by Deal's "-l" option.
<p>
If no filename is given, the library reads from standard
input.  This way, you can create a single data file and then
run several different queries against it:
<blockquote><pre>
% deal -l 100000 > sample
% deal -e "deal::input line sample" -i query1 
% deal -e "deal::input line sample" -i query2
</pre></blockquote>
[ The <code>-e</code> option just evaluates the code in the next
argument as Tcl code.  Alternative, you can use the <code>-I</code>
option, which is shorthand for input formats:
<blockquote><pre>
% deal -I "line sample" -i query1 
</pre></blockquote>
The <code>-I <em>args</em></code> option is exactly the same as -e "deal::input <em>args</em>"

<td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr valign="top"><td>
<dl>
<font size="-1" color="#006600"><b>For Programmers:</b><p>
<dt>Implementation:</dt>
    <dd>Tcl code</dd>
<dt>Location:</dt>
    <dd>input/line.tcl</dd></dt>
</dl>
</table>
</table>
<a name="smartstack"></a>
<h2>Input: <code>smartstack</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
deal::input smartstack <em>hand</em> <em>shapeclass</em> [<em>holdproc</em> <em>min</em> <em>max</em>]
</pre></blockquote>
or on the command line:
<blockquote><pre>
% deal -I "smartstack <em>shapeclass</em> ..."
</pre></blockquote>
<h3>Summary</h3>
This is the most complicated Deal input method in the current release.
It does not read deals from a file - it is, instead, a different path to
generation of deals.  The purpose of this format is to allow fast generations
of deals where one hand fits a very specific description.  For example,
if you want to find hands where south has a balanced 27-count, you
could write:
<blockquote><pre>
deal::input smartstack south balanced hcp 27 27
</pre></blockquote>
On my computer, that returns the first deal in 14 seconds, and every deal after
that takes a tiny fraction of a second.  That's because <code>smartstack</code>
first builds a large "factory" in memory, but once it is built, the
factory spits out hands matching this condition very quickly.
<p>
By contrast, a standard "deal" script to find balanced 27-counts
takes about 2.8 seconds to find each deal.  That means that if you only
want to find about five deals of this sort, the old style program
is faster, but if you want a lot more, use <code>smartstack</code>.
For example, if you wanted 1000 examples, <code>smartstack</code>
takes about 15 seconds, while the old deal will take about 45 minutes.
<p>
One interesting feature of <code>smartstack</code> is that it is often
faster if the hand type is less frequent.  For example, it takes about 6
seconds to find ten deals with 9-card spade suits, and about 5 seconds to
find ten deals with 10-card spade suits.  Similarly, it is faster at
finding hands with exactly 9 controls than it is at finding hands
with 9-12 controls.
<p>
The <code>smartstack</code> routine only works on one hand - after it
places cards in that hand, it generates the rest using the usual
algorithm.
<td width="35%">
<table border=2 bgcolor="#EEFFDD" width="100%">
<tr valign="top"><td>
<dl>
<font size="-1" color="#006600"><b>For Programmers:</b><p>
<dt>Implementation:</dt>
    <dd>Tcl code</dd>
<dt>Location:</dt>
    <dd>input/smartstack.tcl, lib/handFactory.tcl</dd></dt>
<dt>Notes</dt>
<dd>See the two articles from the bridge developers mailing list
describing the algorithm:
<a href="http://www.cirl.uoregon.edu/pipermail/developers/2001-February/000339.html">My first stab at describing it</a> and
<a href="http://www.cirl.uoregon.edu/pipermail/developers/2001-February/000342.html">some corrections.</a>

</dl>
</table>
</table>
<hr>
<h1>Formatting</h1>
<a name="write_deal"></a>
<h2>Command: <code>write_deal</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
write_deal
</pre></blockquote>
<h3>Summary</h3>
This is the the name of a procedure which is called when deals are accepted.
By default, it writes the result in the format:
<blockquote><pre>
          S: 98632
          H: A4
          D: AJ754
          C: J
 S: K              S: AJT7
 H: J3             H: QT95
 D: T98            D: Q2
 C: AKT7532        C: 984
          S: Q54
          H: K8762
          D: K63
          C: Q6
--------------------------
</pre></blockquote>
New output formats are defined by <em>redefining this routine</em>.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>Tcl
<dt>Location:</dt>
<dd><code>format/default</code>
</dl>
</font>
</table>
</table>
</center>
<hr>
<a name="flush_deal"></a>
<h2>Command: <code>flush_deal</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
flush_deal
</pre></blockquote>
<h3>Summary</h3>
This routine is called at the very end of a run for deal. It does nothing,
by default, but some output formats may require it if data is cached.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td ><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>
<dt>Location:</dt>
<dd><code>YYYYY</code>, function <code>ZZZZ</code>
</dl>
</font>
</table>
</table>
</center>
<hr>

<!--
<a name="hooks">
<h1>Deal Hooks</h1>
<font size="+1" color="red">Not yet implemented - planned for 3.0 final
release.</font>
To get a better grip of what the hooks are, why you'd use them and
when they get executed, see the <a href="hooks.html">Introduction
to Deal Hooks</a>.  You can define your own hooks, and that can be useful,
but you can also used the pre-defined hooks.
<p>
Hooks can be used to add statistical analysis or data caching or new input
or output formats, or a host of other nifty features.
<a name="define_hook"></a>
<h2>Command: <code>define_hook</code></h2>
<table cellpadding=5 width="100%">
<tr valign=top><td width="65%">
<h3>Usage</h3>
<blockquote><pre>
define_hook <em>hookname</em>

<em>hookname</em> add <em>code</em> [<em>code</em> ...]

<em>hookname</em> onerror { <em>...code...</em> }
<em>hookname</em> onbreak { <em>...code...</em>}
<em>hookname</em> onreturn { <em>...code...</em>}

<em>hookname</em> run [-reverse]

<em>hookname</em> commands

<em>hookname</em> clear

</pre></blockquote>
<h3>Summary</h3>
At definition time, it creates a procedure under the given name.
<p>
The "<code>add</code>" subcommand add one or more pieces of
code to the hook.
<p>
The "<code>onerror</code>," "<code>onbreak</code>," and "<code>onreturn</code>"
indicate what happens when various exception conditions occur when running
the hooks. By default, all of these conditions are ignored, except errors,
which cause a program error.
<p>
The "<code>run</code>" subcommand causes all the code in the hook to be run. If
run with the <code>-reverse</code> option, the code is run in the reverse
of the order that they were added to the hook.  This is useful if the hook
is an "undo" hook - that is, the code is meant to unset stuff.
<p>
The "<code>clear</code>" subcommand deleted all the code from the hook.
<p>
The "<code>commands</code>" subcommand lists all the code in the hook.
<td width="35%"><table border=2 bgcolor="#EEFFDD" width="100%">
<tr>
<td ><font size=-1 color="#006600"><b>For Programmers</b><p>
<dl><dt>Implementation:</dt>
<dd>INCOMPLETE
<dt>Location:</dt>
<dd><code>YYYYY</code>, function <code>ZZZZ</code>
</dl>
</font>
</table>
</table>
</center>
<hr>
-->