HANDS

New Version: 2.0 -- generates Postscript

by Morris Jones
Data types by Matthew Clegg

Creates 30 randomly dealt bridge hands suitable for an average club duplicate game.

Overview

Hands is a program to generate bridge hands for a duplicate game. The program writes output to the terminal ("Standard out") which may be redirected to a file or a printer. The output is suitable for printing on 8 1/2 x 11 inch pages using any fixed-pitch font at 12 characters per inch, such as 10-point Courier, or for redirection to any Postcript printer or compatible interpreter.

Options are provided for printing headers and footers, providing a seed, and for generating dealing guides after the hand records that may be useful for preparing the game boards. In Version 2.0, the output may be written as Adobe Postscript (option -a).

A sample of the (ASCII) program output is as follows:


Bd  1     S KQT42             | Bd  2     S T                 | Bd  3     S 2                   
Dlr N     H AK52              | Dlr E     H 95                | Dlr S     H AT97                
Vul None  D 72                | Vul N-S   D AKQJ973           | Vul E-W   D KJT853              
          C A9                |           C 932               |           C 52                  
S 86           S J973         | S 8654         S Q97          | S JT84         S A93            
H T863         H QJ9          | H KQT2         H A84          | H KQ82         H 53             
D KQ94         D 86           | D 8            D 542          | D 94           D AQ76           
C Q76          C KJ82         | C JT64         C Q875         | C J98          C KQ76           
          S A5                |           S AKJ32             |           S KQ765               
          H 74                |           H J763              |           H J64                 
          D AJT53             |           D T6                |           D 2                   
          C T543              |           C AK                |           C AT43                
------------------------------+-------------------------------+-----------------------------    

...

I have no sample of the Postscript output of the program (yet) for this document, but there are some cosmetic differences, as follows. The lines between hands are drawn instead of built with bars, hyphens and plusses. The suit symbols are drawn from the Symbol font instead of using SHDC. The Heart and Diamond symbols are outlines. Times-Roman is used for headers, footers, and the titles inside each hand box. Fixed-pitch Courier remains for the actual card designations, with 'T' for the 10 card. Using a fixed-pitch font for the card allows you to more easily see distributions at a glance, unlike the new style of ACBL hand record which uses a proportional font for card designations.

There are two style options for dealing guides. Both options are based on having an unshuffled deck in which the Ace of Spades is the top card, King next, down to the deuce. The Spade suit is followed by the Heart suit in the same order, which is followed by Diamonds, which is followed by Clubs.

(At my club games I have the players sort my boards after the game into sorted suits, with the cards placed face up in the duplicate boards.)

The -p dealing guide format was suggested by Gary Porter, though it has probably been in use by other program developers in the past. With the -p option, hands will print this dealing guide for the above three hands:

Board 1 SNNeNewewSNeN NNeewewSwNSwN SwwSSweNeSwSN NeweSNewwSSSe Board 2 SSeSNewewwwSS ewwSwNeSSNeSw NNNNSNwNSeeNe SSewwNeewewNN Board 3 eSSwwewSSSweN NwwSNNwNSeSew eNeNNwNeeNwNS SeewSwweeNSSN Using Board 1 for an example, the Ace of Spades should be dealt to South, the King to North, the Queen to North, and so on, down to the deuce of Clubs.

Another dealing guide option is -q (no mnemonic for either of these I'm afraid), which changes the NSew markers to text arrows, using ^v>< characters, as follows:

Board 1 v^^>^><><v^>^ ^^>><><v<^v<^ v<<vv<>^>v<v^ ^><>v^><<vvv> Board 2 vv>v^><><<<vv ><<v<^>vv^>v< ^^^^v^<^v>>^> vv><<^>><><^^ Board 3 >vv<<><vvv<>^ ^<<v^^<^v>v>< >^>^^<^>>^<^v v>><v<<>>^vv^ If you're more graphically inclined, then you can picture the arrows being relative to sitting South at the table. Using Board 2 for an example, the Ace of Spades would be dealt down (South), the King down (South), the Queen right (East), and so on.

About the Dealing Algorithm

The dealing algorithm used was borrowed with permission from Matthew Clegg's OKBRIDGE program, along with his data types for representing bridge deals. The deck is randomly shuffled and dealt in a rotation to the four players. The dealing algorithm is highly dependent on the quality of the random number generator(RNG). I suspect that the RNG from the MS-DOS C Library is only a 16-bit routine, and I consider it only barely suitable for generating hands. In the Sun version of the program, I use a 48-bit RNG that is provided with the Solaris libraries. This would be the preferred environment for generating bridge hands with this program.

Before putting the hands into play, I tested the shuffling and dealing algorithms to verify that the order of the cards in the deck had a flat random distribution. I have not tested these deals to see if the resulting hands meet expected distribution frequencies, but my anecdotal experience with them is that they are quite excellent.

Naturally, bridge players (especially newer players) are very suspicious of computer-dealt bridge hands. Their suspicion is somewhat akin to a superstitious belief that pre-dealt bridge hands must be set up to give them troubles.

As with duplicate games in which the boards are well shuffled, you will have occasions when the hands in play are more distributional than usual, or more flat than usual, or any number of other coincidences that are perfectly normal for such a tiny selection of truly random hands. In my personal experience, I don't believe I've ever attended a club game where someone didn't say to me, "The hands have been really strange today!" That's a sign to me that the hands are perfectly normal. :)

Options

These options may be specified on the command line:
-a
Produce Postscript output, suitable for redirection to most Postcript-compatible printers and interpreters.
-h "header text"
Adds a header to the top of each printed page.
-f "footer text"
Adds a footer to the bottom of each printed page. I typically put the game location and date in the header, and my name and phone number in the footer. On the second page of hands, the seed number is printed after the footer.
-s <number>
Specify the seed number for generating hands. If this isn't specified, the 32-bit Unix time is used as a seed. Note that you need to be careful that multiple sets of hands are generated at least one second apart, to prevent using the same seed.
-p
Print a dealing guide using Porter style designations, NSew.
-q
Print a dealing guide using arrow direction designations, ^v><.

Example

With the printer set for 12-pitch fixed-pitch printing, this command line will generate four pages of output, two pages with hand records, suitable for copying back to back on a single 8 1/2" x 11" sheet, and two pages of dealing guides using arrows:

hands -h "San Jose Bridge Center, June 16, 1995" -f "Morris Jones, (408) 369-1710" -q >prn

Get the Latest

These archive files include C language source and executable programs for the following platforms. If you port the program to another platform, I'd be delighted to offer it here as well, though you should find that the program compiles easily on any Gnu-compatible platform.

I strongly recommend against using the DOS 16-bit version of the program. I do not feel that the standard Microsoft 16-bit C Library rand() function is adequate. Look for a good Unix system to run the program (Linux and FreeBSD are often easy to find).

Version 2.0:

Version 1.0: This program is hereby released into the public domain, and may be reused for any purpose whatsoever.
Last Updated: Tuesday, 05-Feb-2002 15:27:33 PST
Return to WhiteOaks Home Page