DEALER, a bridge hand generator program Hans van StaverenThe program dealer can be used to generate hands for partnerships bidding training or for generating statistics that can be used to design conventions, or win postmortems. The program reads the description from standard input, and writes results on standard output. In general the input specifies a condition and an action, and the program will generate a lot of hands, and if the condition is satisfied execute the action. A simple example: shape(north, any 4333 + any 4423) and hcp(north)>=19 as input will print 40 hands with strong balanced Norths. Here is a partial explanation of all possible inputs: if you really want to know all read the source. generate generate hands. If you do not specify this a million will be generated produce produce hands that satisfy the condition. If you do specify this and you want the hands to be printed you get 40. If you only asked for statistics or so you will get a hundred thousand. = defines to represent predeal can be used to assign certain cards to certain hands, for example to check probabilities for actual play. See the example in Descr.6c for enlightenment. pointcount points to give to A K Q etc respectively The hcp() function uses this. Default is the 4 3 2 1 scale. condition
for every hand generated is calculated. If it is non zero the corresponding action is executed. If you do not specify a condition the constant 1 will be assumed. The word condition can actually be omitted. action list of actions to be executed. If you do not specify an action the "printall" action is assumed. The "generate" and "produce" numbers are upper limits. The first one to become true will terminate the program. An expression looks like a C expression, with all normal operators present. If you look for leftshift, or exponentiation forget it, but all normal ones are there, with their normal priorities. Parentheses can be used, and all in all it is just like C. The && form can be used, or the word "and". The same goes for "or" and "not". The special operators needed in a bridge-dealer program are provided: ( ) , eg hearts(west) the number of cards in the suit held by the player hcp ( ), eg hcp(north) the number of high card points held by the player, 4321 count. hcp ( , ), eg hcp(south, spades) the number of high card points in the specified suit hascard ( , ), eg hascard(east, TC) whether east holds the 10 (T) of clubs shape ( , shapelist), eg shape(north, any 4333 + 54xx - any 0xxx) whether north holds one of the shapes in the list, in this case either a 4333 in any suit, or 5 spades and 4 hearts, but no void anywhere. A shapelist is a list of shapes combined with + or - signs. The word any prepended to a shape means that any suit can match the numbers, without the word any the shapes are the normal ones in the order spades, hearts, diamonds and clubs. Instead of a digit the letter 'x' can be given to match any length. All of this means that "any 55xx" means any shape with two five card suits. This operator is one of the most important in the program and is very efficiently implemented. Any shape() call, no matter how complicated is executed in constant time. Use shape() for all length expressions if you can. The different actions are: printall prints all four hands next to each other. This is the default. print ( ), eg print(east,west) print all hands specified on separate pages. This is the best way to generate hands to be used for partnership training. One of the partners gets one page, and one the other and they can start practicing. average "optional string"
, eg average "points" hcp(north) calculates and prints the average of the expression over all hands satisfying the condition. The optional strings is printed before the average. frequency "optional string" ( , , ) calculates and prints a histogram of the values of , between the bounds and inclusive. The optional string is printed before it. The speed of the program obviously depends on the machine it runs on. On my home machine, a SparcStation 1+, it generates about 4000 hands a second if the condition is not too complicated. I rarely play more than 150 hands a week, so in less than two seconds I can generate the boards of a year.
When you report bugs please mention the version number in the source files, and preferably send context diffs if you changed anything. I might put in your fixes, and distribute a new version someday.
I would prefer if you did *not* use this program for generating hands for tournaments. I have not investigated the random number generation closely enough for me to be comfortable with that thought.
Hans van Staveren Amsterdam Holland