Dealer, a tutorial

Some 20 years ago, I became involved with the dealer software. Dealer is a program to deal bridgehands. However, while most programs to deal hands try to generate completely random hands, dealer allows the user to steer the program to generate hands that match certain specifications. This is great to generate practice hands. For example, suppose you want to practice bidding after 1NT, then you simply tell the program to generate hands where one player holds 15-17 points and a balanced hand, and the other has (say) 8 or more points. Print the hands on separate sheets, give one to your partner and start bidding. In fact, the example hands in my article on Muppet Stayman were generated that way. For the formatting, I have written a little bit of perl code that translates the output into a nicely formatted pdf file, see below.

Dealer was developed in the 1990’s by Hans van Staveren and put in the public domain. A few years after that, I found that I needed some extensions so I took the code and extended it.  More people contributed and I ended up being the maintainer for the program. After a few years, development stopped as the program did everything people wanted it to do and no bugs were found. I left it online and I saw that people sometimes downloaded it. Earlier this year, I noticed that downloads were close to zero, so when I cleaned up my website, I took some stuff down. 

That wasn’t the smartest of ideas. Within a couple of weeks, people started to write where the code had gone. The fact that Microsoft updated to WIndows to version 10 and forced its users to move along, probably had something to do with it as well. Under windows10, the various pre-compiled binaries that were around, no longer worked. So, earlier this week, I put everything back online here.

So, what can one do with this program, and more importantly, how does one use this program?

Dealer was written in the time that lots of us worked on unix machines with no GUI’s. (GUI, Graphical User Interface, or the official name for the combination of screen, mouse, keyboard and everything behind that). Using it will be a bit like writing your own software. That may be a step backwards for some of you, for others it might be completely new, but then again, one is never too old to learn.

INSTALLATION: First, you will have to install your program. Dealer was written for a Sun Sparkstation, running a Unix flavour. Unix is still around, in fact, most people using an iMac or MacBook are, in fact, using a FreeBSD machine, where FreeBSD is another flavor of Unix. So, the easiest way forward is to go to the repository and download these files:

  • dealer_20161012.tar.gz
  • dealer_w10_20161012.exe (for windows)
  • dealer_mac_20161012.exe (for mac)

On Windows: Click on the dealer_20161012.tar.gz file. It will expand into a directory (folder) dealer. Move the dealer_xxx_20161012.exe file into that folder, and rename it to dealer.exe (windows). Open the cmd.exe program and go to the dealer folder. There type 

  • dealer.exe
  • control-d

40 hands shold appear. If it doesn’t, something is wrong.

Linux: Open the xterm or kterm program on Linux.  Compile the program by typing:

  • gzip -dc dealer.tar.gz | tar xvf -
  • cd dealer
  • make (ignore any warnings that may appear, they are harmless).
  • ./dealer
  • control-d

40 hands should appear.

Mac: you have 2 options. Compile it yourself, as described under Linux. This requires that you have the xcode tools installed. They come for free with any mac but not everybody installs them. Alternatively, open the terminal window, go to the folder where you downloaded your files and do:

  • gzip -dc dealer.tar.gz | tar xvf -
  • cd dealer
  • mv ../dealer_mac_20161012.exe dealer
  • chmod +x dealer
  • ./dealer
  • control-d

Again, 40 hands will appear. 

From here on, I’m going to assume that we are working on a Mac, things work pretty much the same on Linux and Windows. (Actually, I’m 100% sure that it works the same on Linux, I’m not so sure about Windows, as I’ve been Microsoft-free for ages and like to keep it that way). 

GENERATING HANDS: In the previous step, you actually generated some hands but didn’t control the generating process. That is what we are going to do in this step. The process is controlled by an input file, with this layout:

command1 "parameters for command 1” 

command2 "parameters for command 2” (… more commands…) 

condition "list of conditions”

action "list of actions

# A comment.

What this does is the following: the commands describe things like the features of the hands, the number of hands to generate, and so on. When the program starts to generate hands, it will use those parameters. The condition is used to select hands, every time a hand is generated, it will be compared against the requirements in the condition, if it matches, the actions in the list of actions will be performed. Finally, lines starting with a # are considered comments and ignored. They do make your files a lot more readable though. For example, suppose you have the hand on the right and the auction starts 1 by LHO, 2 from partner and a pass. Now what? Anything can be right and this is mainly depending on the style of the 2 in your partnership. 

You decide to generate a few example hands to discuss this with partner. This input file will accomplish that:

produce 25

vulnerable EW

dealer west

predeal south SAQ542, HKJ87, D32, CAK

west1c = hcp(west)>11 && clubs(west)>= 3

north2d = diamonds(north)>= 6 && hcp(north)>5 && hcp(north)<11

condition (west1c && north2d)

action printall

The may look complex at first, but try to read it. "Produce 25” says to stop after 25 hands have been generated (the program will also stop by default if 1,000,000 hands are generated even if not 25 have matched the description). “Predeal…” forces the program to give the 13 cards to south, and use the remaining 39 for the other hands. The next line will be familiar to anybody who has ever written a computerprogram. hcp(west) returns the number of points in the west hand, clubs(west) the number of clubs, thus the variable west1c will be true if west has at least 11 points, and (&&) at least 3 clubs. The next line says that north should have 6 diamonds and between 6 and 10 points. These 2 are used to create a condition (west1c && north2d), which means that the program should only consider hands which meet both these criteria. (&& is the mathematical and, “a and b” evaluates to true if both conditions are met, the alternative is or, ||, “a or b” is true if a is true, or b is true (or both). If you cannot remember these shortcuts, one can also use the keywords “and” and “or"). 

Open the textedit program on your mac, enter these lines and save the result as a file myhand.txt in the same place where you put the dealer program. Go back to the terminal and type

  • ./dealer myhand.txt

This will print 25 hands on the screen. If you want to capture the output, use:

  • ./dealer myhand.txt >output.txt

The hands now are in the output.txt file, instead of the screen, ready to be printed or mailed or whatever you want to do with them.

A MORE COMPLEX EXAMPLE: Suppose you are a teacher/coach and want to teach your students Muppet Stayman over 2NT. Yes, this is an advanced class. First you write the input file for dealer:

east_notrump = shape(east, any 4333 + any 4432 + any 5332 ) && 

               hcp(east)>=20 && hcp(east)<=22

west_interesting = hcp(west)>=5

hfit = (hearts(west) + hearts(east)) >7

sfit = (spades(west) + spades(east)) >7

condition east_notrump && west_interesting && (hfit || sfit)

produce 100

action printoneline

The shape command is one of the more powerful commands. It specify the shape of a hand. Shapes are given in the usual order (spades-hearts-diamonds-clubs), so 5431 means specifically 5 spades, 4 hearts, 3 diamonds and 1 club. It is often inconvenient to specifically write all shapes, so the keyword “any” has been introduced. “any 5431” thus means any hand with a 5 card, a 4 card and a 3 card suit plus a singleton. The “+” sign adds shapes to the list, so “any 4333 + any 4432” translates to either a 4333 or a 4432 shape. If you don’t want to specify suit lengths, use an “x”. 54xx thus translates to 5 spades and 4 hearts, with the remaining cards 4-0, 3-1 or 2-2. Also allowed is a - sign, to exclude shapes. “any 4xxx - any 4333" thus means a hand with a 4 card suit but not 4333. Note that the x’s can be a bit tricky, a 9-4-0-0 shape is consistent with any 4xxx. 

We are training Stayman, so we want to have a major suit fit. The lines hfit and sfit add up the number of hearts and spades in the 2 hands. Also, we want to make sure that west bids, so we give him at least 5 points. 

That adds up to the condition “east opens 2 NT”, “West Responds” and there is a major suit fit. 100 hands are enough, and the action is to print the hands on a single line.

Save and run, this creates 100 lines of output like:

n T8732.K.K2.K9863 e AK.Q652.AJ75.AQ7 s 654.T973.Q43.J54 w QJ9.AJ84.T986.T2

While these are the hands you want, this is not a very friendly output. For this reason, I wrote a little postprocessor dealer2latex.pl. This takes the EW hands and formats them into a nice document using the LaTeX formatting system:

  • ./dealer Descr.2NT | dealer2latex.pl
  • latex practice.tex

This creates a file practice.pdf which you can print. Latex2html.pl does two extra things: first it swaps east and west on the even numbered hands. That way, half the time, one player will open 2NT and the other responds, while on the other half the other player opens. It also adds vulnerability to the hands (overriding anything you specified in the input), for cases where that is relevant. 

The dealer2latex.pl and practice.tex files are available from the repository. Obviously, feel free to modify the text in the practice.tex file with your name, specific instructions and what not. 

NEXT STEPS: If you have done all this, and ended up with a few hands on the screen, you have done everything it takes to generate hands. The next step will be to learn the full syntax of the program, including all possible operators. The description can be found in the Manual subfolder of the distribution. Click on the index.html and it will appear in your browser. If you need more help, go to the Examples folder. Here you find some examples that I have collected over the years and show how the program works.  After that, it is practice and more practice. 

Happy generating!

DISCLAIMER: Finally, a disclaimer. Dealer is intended to generate practice hand, it is NOT, and never was, intended to generate random hands for tournament play. The program has a few major flaws for this. First, it only uses 32 bits of randomness, which means that it will only generate 232, or about 4 billion, different hands out of the 296 possible hands. There is no guarantee that there aren’t any specific biases towards certain distributions (even though I haven’t found them). The second issue is that it is easy to manipulate the hands, say by generating only hands where at least 1 player has 12 points. These 2 issues are against the laws of the game, so for these reasons the program is out. Finally, the random seed can be set and this will recreate hands generated before. While this is great for analysis purposes, for tournament play, it means that once a user knows the seed, he can generate the hands for a session himself. (And there are more risks here, but that is another discussion).  

Of course, for practice and analysis purposes, all this doesn’t matter. 4 billion hands is more than anybody will ever play, and there are no requirements for practice hands. 

© Henk Uijterwaal 2019