# Home

### INTRODUCTION

The number and variety of card games is large, certainly in the order of a thousand. Most people know the exact rules for relatively few games; nevertheless, it is usually easy to learn the rules of a new one. This is because most card games fall into one of two types. One involves collecting and/or discarding cards (call this the POKER type), and the other involves taking tricks where a trump suit is important (call this the WHIST type). The most successful study and consequent automation of card games has been with the former. This section discusses four common games of this type in increasing depth of analysis. Unless otherwise stated, assume that an ordinary 52-card pack is being used.

### 2.1 BRAG

This game is the ancestor of one of the greatest card games, poker. In fact it is occasionally referred to as 3-card poker, because

1. The best hand wins (see rules for definition of best hand).
2. Players can bet and re-bet on the respective merits of their hand.
3. If the player making the largest bet is not called, then he wins without showing his hand.

Thus there is an element of bluff.

#### Rules

Three cards are dealt from a full pack to each of the players. The hands are graded into the following classes (from best to worst):

 1 Prile of 3's (three 3's) 2 Prile (three cards of the same value) 3 Straight flush (three cards, consecutive in value and identical in suit) 4 Straight (consecutive in value) 5 Flush (identical in suit) 6 Pair (two cards of the same value) 7 High card (none of the above).

Betting now takes place. A player either bets (because he has a good hand), throws in (because he considers his hand too weak to risk more money), or bluffs. The important thing to appreciate about bluffing is that it is not a technique for winning large sums of money with poor hands. Its main purpose is to prevent opponents knowing the strength of your hand from the amount you bet on it. It is often good policy to be found out in a bluff early in the game; this will encourage people to go with you when you have a really good hand later on. It is sometimes advantageous to underbid a hand and this is also termed bluffing.

The first thing to do in a game involving the concept of best hand is to calculate the relative values of the hands, i.e. the probability of being dealt, in this case, a hand in one of the seven listed classes. For brag the computation can be done by hand, as follows.

#### 1. Prile of 3's

There are four 3s in a full pack. Now the chance of being dealt a member of a group (size m) from a pack of cards (size n) is m/n. Therefore the chance of getting a 3 with the first card is 4/52. Having obtained it, the chance of getting another 3 from the depleted pack is 3/51, and of getting the final 3 is 2/50. These individual probabilities are now multiplied together to obtain the actual probability, which is (approximately) 0.02%. Thus one can reasonably expect to see a prile of 3's every 5000 hands.

#### 2. Prile

Quite simply, twelve times more likely than a prile of 3s, approximately 0.22%.

#### 3. Straight Flush

The first card can be anything, for example the 8 of spades. We now have to consider two possibilities:

1. the next card is adjacent, i.e. either the 7 or 9 of spades
2. the next card is one removed, i.e. the 6 or 10 spades.

##### Fig. 2.1

Case (a) is twice as likely to result in a straight flush as case (b) (see Fig. 2.1). A final adjustment is to note that K, A, 2 is not a straight. Therefore the probability is

In actual fact a straight flush is slightly less likely than a prile.

#### 4. Straight

There are sixteen possible ways the second and third card can vary their suits together. Of these one gives a straight flush (class 3 above), hence a straight is fifteen times more likely than a straight flush, i.e. about 3.26%.

#### 5. Flush

Same argument as for a prile, but one must subtract the straight flush probability component, thus:

#### 6. Pair

There are three possible ways in which a pair can be picked up, thus (P means similar in value, * is any other card):

```     PP*    P*P    *PP
```

Therefore the probability is

#### 7. High card

At this point the probability of a high card can be deduced by subtracting the total percentage of the six classes so far calculated. This gives the answer to be 74.4%. However, it is a useful check to make the calculation. There are two ways to have a 5 high (2,3,5, and 2,4,5), and six ways in which the three cards can be ordered. Finally, the three cards can each be one of four suits, i.e. 4 × 4 × 4 = 64; but to remove the possibility of a flush we multiply by 15/16.

Therefore the probability of obtaining a 5 high is

There are five ways to obtain a 6 high (2,3,6; 2,4,6; 2,5,6; 3,4,6; 3,5,6); and finally, there are 274 ways of obtaining a hand in the class of high card, thus:

HIGHEST CARD NUMBER OF WAYS
5 2
6 3 + 2 = 5
7 4 + 3 + 2 = 9
8 5 + 4 + 3 + 2 = 14
9 etc 20
10 27
J 35
Q 44
K 54
A (remember 2,3,A is a straight) 64
Total 274

Therefore the probability of obtaining a high card hand is

which agrees with the deduction.

In order to use the information now obtained, it is clearer to expand the class of high card into the individual highest card probabilities and give the cumulative probabilities of all the classes, as shown in Fig. 2.2.

Description Approximate
Probability %
Cumulative
Probability %
5 high 1 1
6 high 1 2
7 high 2 4
8 high 4 8
9 high 5 13
10 high 7 20
J high 10 30
Q high 12 42
K high 15 57
A high 18 75
Pair 17 92
Flush 5 97
Straight 3 100
Straight flush Negligible 100
Prile Negligible 100
Prile of 3s Negligible 100
##### Fig 2.2

From this table a hand can be evaluated. The values of all the better than average hands (> 50/%) are given in Fig. 2.3. Only the two most significant cards are identified.

Value 0 1 2 3 4 5 6 7 8 9
50% K,9 K,10 K,10 K,J K,J K,Q K,Q A,4 A,5 A,6
60% A,7 A,8 A,8 A,9 A,9 A,10 A,10 A,J A,J A,Q
70% A,Q A,Q A,K A,K A,K 2,2 2,2 3,3 4,4 5,5
80% 6,6 6,6 7,7 8,8 9,9 10,10 10,10 J,J Q,Q K,K
90% A,A A,A 6 High
Flush
9 High
Flush
J High
Flush
K High
Flush
A High
Flush
10 High
Straight
Q High
Straight
A High
Straight

#### Bidding

This is a function of at least five parameters, namely:

1. Value of hand.
2. The rules of bidding.
3. Number of players.
4. The order in which the players bid (the last person has an advantage over the first person).
5. Bluff.
##### 1. Value of hand

Having been dealt a hand at brag, the table in Fig. 2.3 can be used to look up the value.

##### 2. The rules of bidding

The mechanics of bidding can introduce complications. For the following discussion the simplest rules are in force. These are as follows. Each player antes one unit. The cards are dealt. A player, at his turn, can either stay in the game by putting an extra unit in the pot or he may drop out. When only two players are left the highest hand wins. If only one player bids he wins without showing his cards.

##### 3. Number of players

The particular case of four players will be discussed and then generalised.

##### 4. The order in which the players bid

This is the most difficult parameter. Because the players are bidding in sequence, then each player who bids in a round has an advantage over all preceding players. Consider the following (admittedly non-optimal) algorithm for the first player, A. Once every four hands, on average, A will be dealt a hand with a value of 75 or more. Assuming he does not bluff he will bet only on these hands (otherwise he will steadily lose his ante money). The second player, B, now has the bid. If A has already bid, then B will drop out unless he also has a hand of value 75 or more. The problem now arises of what B does if A has not bid. B has apparently only got to beat two other players (C and D) now. He should have a better hand than them once every three times that he finds himself in this position. By similar argument to deciding whether A makes a bid or not, B will bid if his hand is of value 67 or more.

Therefore, C will bid if A bid first and C has value ≥ 75 or B bid first and C has value ≥ 67 or if C is first to bid and C has value ≥ 50.

D will bid: = if A bid first and D value ≥ 75
or B bid first and D value ≥ 67
or C bid first and D value ≥ 50
or D first to bid and D value ≥ 0.

This shows the advantage of D, the last player to bid, especially in the case when A, Band C all pass. To overcome this advantage the deal is rotated each hand. Generalising to n players, we have the following situation:

The first bidder is in position 1; the last bidder is in position n. It is now the turn of player me (1 ≤ me ≤ n) to bid. Assume first bidder is set to 0 at the start of a round of bidding, but is automatically reset to point to the first player to bid (if any). The player will decide to bid or not on the result of two questions:

```Q1: if first bidder = 0 then first bidder: = me;
```
```Q2: if value of my hand ≥ (1 - 1/(n + 1- first bidder))
then I bid else I pass;
```

This very simple algorithm is not optimal, but it does give some indication of the factors to be considered when deciding to bid. It has two bad omissions.

(a) Bidding weaker hands because of the ante. Consider the ridiculous case of 100 players. The first 98 have passed. The 99th player has a very poor hand (say 6 high). He has about a one in 50 chance of beating the last player, but by hazarding 2 units he stands to win 99 units (the ante of all the other players). In the situation this is an even bet, so he must bid even though he has a very bad hand. Define what I can win to be all the money put in by the players who have now passed + 2.

```if (value of my hand) * (what I can win) / (what I must bid) ≥
(1-1/(n + 1 - first bidder))  )
then I bid else I pass;
```

(b) Rounds. The next problem is when more than two players are still bidding at the end of a round, i.e. there must be another round of bidding. Consider the particular case of four players and everyone has bid in the first round. The first player must now assume that everyone has a hand of value 75 or more. This is equivalent to the situation of his being the first player to bid in a game comprising eight players. To allow for this he must multiply the number of players still in at the end of the last round by the number of the new round, and also adjust what I can win. (N.B first bidder is reset for every round.) The decision is now:

```if ( value of my hand * (what I can win) / (what I must bid) ≥
(1 - 1 / (number of people still in * round number + 1 - first bidder))  )
then I bid else I pass;
```

The decision is now becoming fairly complicated, but is still not as good as most human players. One obvious error still evident is that in a game of four players the actual chance of winning with a hand of value 75 is (3/4)3 = 42%. The calculation of best strategy is extremely involved (even using the simple betting rules described here). The point of this discussion is to isolate and emphasise some important features of the game.

##### 5. Bluffing

The problem of when a program should bluff (i.e. say I bid when it should say I pass) can be handled by a random number generator giving a yes/no answer in pre-selected proportions. Exactly what the proportions are for optimal play depends on the number of players, value of hand, plus other factors already mentioned. For a game of the complexity of poker and brag these calculations are extremely difficult. The only known case of an optimal strategy for a bluffing game (called Guess It) is described in Chapter 1.4.

A more important problem is to detect whether another player is bluffing or not. Since there is no known optimal strategy for bluffing in brag, a human player must attempt to randomise his play himself. In fact a human player is a very poor random number generator. If he is deprived of a randomising device (a penny or dice, etc.), a pattern will emerge. This was demonstrated by Winston Riley of Westat Research, Inc. (6). A computer program was written for an IBM 1401 to play the game of matching pennies. In this game both the human opponent and the computer select heads or tails simultaneously. The computer wins if it guesses the same as the human player; it loses if its guess is different. The program had a pattern recognition scheme, and experience showed that after 25 to 40 plays the program was able to lock onto the opponent's pattern of play, and further winning plays were rapidly learned by the computer.

A good card playing program which requires random play by the opponent would almost certainly incorporate a pattern of play recogniser. Of course the human player does have access to a randomiser, the cards themselves. For example, in a situation where a player should bluff about one in every thirteen times, then the decision could be made from the value of the first card picked up; if it was an ace then bluff, otherwise pass. Experience indicates that people don't do this; basically a person is very likely to bluff if he is winning, but hardly bluffs at all when he is losing. It should be possible to detect such a pattern.

#### Actual Play

When it comes to writing a program for a computer to simulate bidding, most people agree on the important features. Thus to bid or not bid is a function of

• Value of hand
• Who bids first in a round
• Number of people still bidding (actively and potentially)
• Round number
• Wager risked compared to expectation
• Bluffing (mainly detection of).

But there can be violent disagreement of how these features are combined and weighted. There is no reason why two programs, vastly different in concept, should not be equally successful. Also there are more features than those listed above which could also be relevant e.g. psychological, but are much more difficult to assess.

There is an interesting way to partially resolve these problems. Instead of writing just one program, a group of people could each write a program to play what they themselves feel is a good strategy. A master program is then used to deal cards and control the bidding. Such a system could play many millions of hands and then declare which individual program was the best. If many such programs were written and tested, then the simple process of elimination (or evolution) should result in quite a powerful bidding program for brag (see Chapter 4.3).

#### The squeeze

Unless the program gives a value of 100 to some hands, e.g. a prile of 3's, it will always have a limit to how far it will continue to bid. This means that if two players form a coalition against it, then the program will be squeezed out of the bidding and never win. This is a problem in an actual game, and the best answer is to have a limit to the total bet size. Other answers are to play only with people who are not co-operating, and/or to have a set amount of money at the start - a player who loses all his money dropping out.

#### Conclusion

There is no reason why a program could not cater for the difficulties and problems of the simple game discussed. In fact a computer program should play better, first because it does not care about financial win or loss, secondly because it can play randomly itself and yet detect patterns in human play, and finally because it has a natural poker face.

### 2.2 POKER

There are ten classes of hands in 5-card poker, and it is consequently more difficult to calculate the relative values. A further problem is that players can attempt to improve their hands by changing up to three cards of the hand originally dealt to them. An added complication, also not dealt with in the discussion on brag, is that jokers may be used; these cards may be valued as any card in the full pack other than genuine cards already held in one's hand.

It is possible (and much simpler than hand calculation) to obtain a rough solution to the value of a hand by writing a simulation program to produce a random poker hand, classifying the hand, and then counting the number of times each class is generated. (This is actually a standard test for random number generators.) Fig. 2.4 is a shortened Fortran program to do this. The ten classes are:

NAME SUMMATION VARIABLE
IN PROGRAM
HIGH CARD INONE
PAIR I2
TWO PAIRS I22
THREE OF A KIND I3
FULL HOUSE I32E
FOUR OF A KIND I4
STRAIGHT (OR RUN) IRN
FLUSH IFL
STRAIGHT FLUSH ISF
ROYAL FLUSH IRF
```      DIMENSION ICHK(13),IVAL(5),ISUIT(5)
C     CLEAR SUMMATION VALUES

INONE = 0    HIGH CARD
I2 = 0       PAIR
I22 = 0      TWO PAIRS
I3 = 0       THREE OF A KIND
I32 = 0      FULL HOUSE
I4 = 0       FOUR OF A KIND
IRN = 0      STRAIGHT
IFL = 0      FLUSH
ISF = 0      STRAIGHT FLUSH
IRF = 0      ROYAL FLUSH

DO 100 K = 1,10000        DEAL 10000 HANDS
DO 30 I = 1,13            CLEAR ARRAY WHICH DETECTS PAIRS
30   ICHK(I) = 0
CALL GENHAND              GENERATE A HAND IN IVAL, ISUIT
J = 2
ICHK(IVAL(1)) = 2
DO 1 I = 2,5

IF(ICHK(IVAL(I)) 2,3,2
2   J = J*ICHK(IVAL(I))       DETECT PAIRS IF ANY
ICHK(IVAL(I)) = J
GO TO 1
3   ICHK(IVAL(I)) = 2
1   CONTINUE

IF(J-2)4,5,4              NO PAIR?
4   IF(J-4)6,7,6              PAIR?
6   IF(J-8)8,9,8              TWO PAIR?
8   IF(J-16)10,11,10          THREE OF A KIND?
10   IF(J-256)12,13,12         FOUR OF A KIND?

12   I32 = I32 + 1             MUST BE A FULL HOUSE
GO TO 100

13   I4 = I4 + 1               FOUR OF A KIND
GO TO 100
11   I3 = I3 + 1               THREE OF A KIND
GO TO 100
9   I22 = I22 + 1             TWO PAIR
GO TO 100
7   I2 = I2 +1                PAIR
GO TO 100
C     NOW LOOK FOR HANDS NOT CONTAINING PAIRS

5   J = IVAL(1) + IVAL(2) + IVAL(3) + IVAL(4) + IVAL(5)
IACE = 0
IF(ICHK(1))52,52,50       ACE IN HAND?
50   IACE = 1                  YES
52   SUM = J
SUM = SUM * 0.2           SUM IS NOW MEAN VALUE
IRUN = 2
ISAME = 3
DO 51 I = 1,5
IF((ABS(IVAL(I)-SUM)) > 2.2) IRUN = 1
51   IF(ISUIT(1)≠ISUIT(I)) ISAME = 0
IF(J = 47 .AND. IACE = 1) IRUN = 2      TOP STRAIGHT
M = IRUN + ISAME

C     IF M = 1 THEN HIGH CARD ONLY, M = 2 THEN
C     STRAIGHT ONLY
C     IF M = 3 IS DUMMY, M = 4 THEN FLUSH ONLY, M = 5
C     THEN
C     STRAIGHT FLUSH, POSSIBLY ROYAL FLUSH

GOTO(53,54,55,55,56),M
53   INONE = INONE +1
GO TO 100
54   IRN = IRN + 1
GO TO 100
55   IFL = IFL + 1
GO TO 100
56   IF(J-47)57,58,57         STRAIGHT/ROYAL FLUSH
58   IRF = IRF + 1
GO TO 100
57   ISF = ISF + 1
100   CONTINUE
STOP
END
```
##### Fig 2.4 Fortran program to classify and count poker hands

A count to generate 10,000 hands is set up. The poker hand is then dealt by calling subroutine GENHND. Basically, this routine produces values (IVAL) for each of the five cards in the range 1 (an ace) to 13 (a king), and suits (ISUIT) for the same five cards in the range 1 to 4. (It is unimportant what the suits are.) It also has a check to prevent the same card (identical value and suit) from being included more than once in each generated hand.

The program first detects and classifies a hand if it has at least one pair in it. It does this by using the scratch array ICHK to find cards of similar value and, by a trick of multiplying powers of 2, it can then classify the hand immediately. Particular examples, showing what is produced in the array ICHK, are given in Fig. 2.5.

Array ICHK Result
in J
1 2 3 4 5 6 7 8 9 10 11 12 13
A 2 3 4 5 6 7 8 9 10 J Q K
PAIR: A,A,2,3,4 4 2 2 2 4
TWO PAIRS: 4,4,5,5,6 4 8 2 8
THREE: 7,7,7,8,9 16 2 2 16
FULL HOUSE: 10,10,10,J,J 16 32 32
FOUR: Q,Q,Q,Q,K 256 2 256
STRAIGHT: A,2,3,4,5 2 2 2 2 2 2
##### Fig 2.5

On exit, a variable (J) will have been set to the highest integer generated - shown highlighted in Fig. 2.5. Note that the case of a full house does not give a unique value of J, but depends on the order of the cards. It is usually 32 but, for example, J,J, 10, 10, 10 would exit with J = 64. If J is still 2 at the end of the scan for pairs, then no pairs are present in the hand.

The next step is to detect if an ace is present (the content of ICHK(l) is examined). This is because an ace can be at the bottom (A,2,3,4,5) or the top (10.J.Q.K.A) of a straight. A marker is set (IACE) if there is an ace.

To detect straights, the sum of the values of the cards is calculated and the mean value obtained; for example, (6,7,8,9,10) has a sum of 40 and a mean of 8. The individual values are then checked so as to be not greater than 2 from the mean. If this is true then, because we already know all the values are different, the hand must be a straight. The special case of a top straight (10, J, Q, K, A = 47) is also checked for.

A flush is a simple test that the cards have the same suit number. A combination of whether the hand is a straight and/or a flush allows the hand to be identified, and added into the five remaining classes.

#### Results of the program

The classes are now ordered into decreasing probability. N.B. The results can depend on the random number generator to a minor extent.

CLASS TOTAL PERCENTAGE
PROBABILITY
HIGH CARD 5025 50
PAIR 4196 42
TWO PAIRS 482 5
THREE OF A KIND 214 2
STRAIGHT 42 -
FLUSH 24 -
FULL HOUSE 15 -
FOUR OF A KIND 2 -
STRAIGHT FLUSH 0 -
ROYAL FLUSH 0 -

The probability of a royal flush appearing is

##### Animation of a program

and a straight flush is only nine times more likely (about 1.4 × 10-5), so it is not surprising that none were found in 104 hands.

The next problem is how to improve the hand that is first dealt. With most hands in the HIGH CARD class the two highest cards are kept, but there are three sub-classes of high card for which it is better to keep four cards. These are

1. FOUR FLUSHER - four cards only of same suit.
2. OPEN STRAIGHT - four cards only in sequence.
3. INSIDE STRAIGHT - one inside card is missing from the sequence, e.g. (4,5,-,7,8).

An extension (to the part of the program which detects a high card) was written to include the three subclasses. The results were

CLASS TOTAL PERCENTAGE
PROBABILITY
TRUE HIGH CARD 2998 30
FOUR FLUSHER 437 4
OPEN STRAIGHT 353 4
INSIDE STRAIGHT 1237 12

The program was again extended to attempt to improve the hands first dealt. The decisions are made as follows:

```TRUE HIGH CARD -           keep two highest, draw 3
FOUR FLUSHER -             keep four,        draw 1
OPEN AND INSIDE STRAIGHT - keep four,        draw 1
PAIR -                     keep pair,        draw 3
TWO PAIRs -                keep two pairs,   draw 1
THREE OF A KIND -          keep three,       draw 2
```

All the other classes are more likely to deteriorate if cards were changed except the four of a kind, but changing one card in this case would not alter its classification. The results of changing cards under these conditions were

CLASS TOTAL PERCENTAGE
PROBABILITY
HIGH CARD 3587 36
PAIR 4073 41
TWO PAIRS 1435 14
THREE OF A KIND 812 8
STRAIGHT 102 1
FLUSH 46 -
FULL HOUSE 55 -
FOUR OF A KIND 7 -
STRAIGHT FLUSH 0 -
ROYAL FLUSH 0 -

Assuming there is no bidding before changing cards, then the above values can be used in the same way as the values of hands in brag.

#### The joker

One joker in a full pack makes a great deal of difference in evaluating a hand. In a game involving six players the joker is almost certain to have been dealt to one of the players, either in the first deal or when the cards were exchanged. It is important for a player to try to keep track of the joker and have a good idea whether the card is in play or not. A simple way to value a hand, when the joker is believed to be in play, is to modify the program to deal hands in which the joker always appears. Assuming the joker was dealt before cards were exchanged is equivalent to having the program deal only four genuine cards. Classify the result as before, but re-interpret the results, i.e. a high card is now a pair. Ignoring royal and straight flush (which are still negligible), the results were

FOUR CARD
HANDS
CLASS
INTERPRETATION
PERCENTAGE
PROBABILITY
HIGH CARD PAIR 65
PAIR THREE OF A KIND 30
TWO PAIRS FULL HOUSE 1
THREE OF A KIND FOUR OF A KIND 1
STRAIGHT STRAIGHT 2
FLUSH FLUSH 1
FOUR OF A KIND FOUR OF A KIND 0

Applying the same rules for exchanging cards gives a better than normal chance of improvement to the player holding the joker. Results were

CLASS PROBABILITY
PERCENTAGE
PAIR 43
THREE OF A KIND 49
RUN 2
FLUSH 1
FULL HOUSE 3
FOUR OF A KIND 2

To illustrate the discontinuity caused by the joker when it is in play, Fig. 2.6 shows the normal expectation of a final hand compared with final hands which had the joker to begin with.

Another interpretation of these results is Fig. 2.7. It gives the description of the least hand which has even' chance of being the best when playing against 2 to 5 players with or without the joker.

It is easy to further modify the program to study other variations of poker. For example, if it is difficult to know whether the joker is in play or not (a computer would not be able to watch the cards), then the program can be made to deal from a simulated pack containing the joker. This smooths out the discontinuity shown in Figs, 2.6 and 2,7 but means that play is less accurate.

2 3 4 5
NORMAL PAIR
8s
PAIR
Qs
TWO PAIR
4 HIGH
TWO PAIR
7 HIGH
JOKER THREE
4s
THREE
8s
THREE
10s
THREE
Qs
##### Fig 2.7 Number of players

Once the joker is allowed to occur randomly it is possible to include more wild cards and study their effect. Some simple results for opening hands were

CLASS NORMAL JOKER 2s WILD
HIGH CARD 50 45 30
PAIR 42 44 46
TWO PAIRS 5 4 4
THREE OF A KIND 2 5 13
STRAIGHT - - 2
FLUSH - - -
FULL HOUSE - - -
FOUR OF A KIND - - 1

Roughly speaking, the more wild cards the greater the probabilities of a pair, three, and four of a kind.

Although the results are not as accurate as the hand calculation (done for the example of brag), they are adequate, readily obtained, and also give a better feeling for the game. For example, an important advantage of the simulation method is that hands tend to be sorted before being thrown in (pairs are put together and so on); it is possible to allow for this in the program, but practically impossible mathematically. So far simulation has only been used to calculate values for hands. In the next two sections actual playing strategies will be obtained by simulation.

### 2.3 CHEMIN-DE-FER

The previous two sections have dealt with games in which the deal was rotated and, therefore, the games have been fair, each player eventually having equal opportunities from his position in the order of bidding. If one wishes to playa card game in a casino, however, one must assume that the house will always play in the most favourable position, i.e. the last one. Chemin-de-fer is such a game.

#### Rules

The banker (playing for the casino) has control of the size of the bet. Before the hands are dealt he names a sum, and his opponent (who can be a representative for a number of players) must cover that sum in order to play.

From the deck (initially at least three packs) the banker then deals two hands of two cards each. The object of the game is to have two or three cards which total 9, or as nearly 9 as possible. The addition is modulo 10. Ace counts as 1, and J, Q, K count as 10. For example:

```      5 + 7 = 2
A + J = 1
10 + Q = 0 (a zero total is called baccarat)
```

A player whose total is 9 or 8 has a natural, and shows his hand immediately; the banker then shows his own cards and the higher hand wins. If the scores tie there is a new deal. If a natural has not been dealt, then the player must stand on 6 or 7, must draw on 0, 1, 2, 3 or 4, but has a choice on 5. The additional card, if requested, is dealt face up.

The banker is in an advantageous position. If the player calls, he knows the player must have an initial score of 0, 1, 2, 3, 4, or 5, and also the value of the third card. If the player stands, he must have an initial score of 5, 6, or 7. With this information plus the knowledge of his own score, the banker must now decide either to stand or deal himself another card. The banker's strategy and the advantage it confers can be found by running the Fortran program given below:

##### Fortran Program to find Banker's Strategy
```      DIMENSION IVAL(6),ISTRAT(10,11)
DO 15 NHANDS = 1,1000    1000 HANDS TO PLAYER AND BANKER
IDRAW = 11               INITIALISE PLAYER TO STANDING
CALL SIXVAL              GENERATE 6 CARDS, 3 FOR EACH
ISP = IVAL(1) + IVAL(2)  PLAYERS TOTAL
ISB = IVAL(3) + IVAL(4)  BANKERS TOTAL
1   IF (ISP -10)4,3,2
2   ISP = ISP - 10           PLAYERS TOTAL MOD 10
GO TO 1
3   ISP = 0
4   IF (ISB -10)7,6,5
5   ISB = ISB - 10
GO TO 4                  BANKERS TOTAL MOD 10
6   ISB = 0
7   IF (ISP - 5) 8,10,11
8   ISP = ISP + IVAL(5)      PLAYERS < 5 THEREFORE DRAWS A CARD
IDRAW = IVAL(5) + 1
IF(ISP - 10)11,9,9        ADJUST NEW TOTAL MOD 10
9   ISP = ISP - 10
GO TO 11
10   IF(IVAL(1) < 4) GO TO 8  PLAYER HAS 5
DECIDES WHETHER TO DRAW OR NOT
11   IF(ISB-ISP)12,15,13      SEE WHO WINS
12   IR = -1
GO TO 14
13   IR = IR + 1
14   ISB = ISB + 1
ISTRAT(ISB,IDRAW) = ISTRAT(ISB,IDRAW) + IR
15   CONTINUE
STOP
END
```

The array ISTRAT is first cleared. It is used to build up a histogram of the 10 possible initial scores of the banker (0-9) by the 11 possible situations presented by the player (calls a card of value 0 to 9 or stands). Six values (IVAL(l)-IVAL(6)) are generated in the range 0-9, and the correct proportion, using the random card procedure SIXVAL. The initial scores, modulo 10, of the player (ISP) and the banker (ISB) are then calculated. Statement number 7 is now executed:

```  7   IF(ISP - 5)8,10,11
```

If the player has less than 5 then he has the third card IVAL(5) added to his total. If he has exactly 5 then the further card is requested on a 8/13 chance (the value of IVAL(l)); this mixes the strategy of the player about 50:50. If the player has more than 5 then he stands.

The result is now decided. If the player has the better hand, then a-1 is added into the appropriate element of the array ISTRAT. If the banker wins, a+1 is added. A draw is not recorded. In this program the banker never draws a third card. The result of such a strategy over 1000 hands is given in Fig. 2.8.

The program is now run through the same sequence of random hands, but this time the banker always calls for a third card unless the player has a natural (8 or 9). The most favourable strategies for each of the 110 situations the banker can face are obtained by taking the most positive or least negative element from the respective answers given by the two programs. Fig. 2.9 shows the total result. In all the situations to the left of the thick line the banker should call for a card; in all the situations to the right it is better not to do so (and so is unchanged from Fig. 2.8).

Of the 1000 hands 684 were drawn or cancelled out, the player won an excess of 151 and the banker, with his greater sophistication, won an excess of 165, half of them with a natural 9. This means the banker has a (165- 151)/1000 = 1.4% advantage.

0 Playerdreworstood
##### Fig 2.8 Banker never draws and has initial total
0 Playerdreworstood
##### Fig 2.9 Best mixture of Banker draws and never draws

The strategy of the banker is dependent on what the player is doing. In the example given the player's strategy was to draw to a five roughly half the time. A good description of the game is given by James Bond in Casino Royale. Bond's analysis of whether to stand or draw on a five was that the chances of bettering or worsening the hand are exactly even. This statement is not strictly accurate. There are four cards which can improve a 5 (A,2,3,4), and five cards which can degrade it (5,6,7,8,9). All these cards are equally probable.

0-2 Playershowsorstands
##### Fig 2.10 * Banker should draw with frequency 0.4

An extremely accurate study for the optimal strategies of the player and the banker is described by Foster (7). The calculations were made on an Atlas computer and involve game theory. It was assumed that the banker would always draw to a 2 or less and always stand on a 7 or more (cf. Fig. 2.9). The strategy Foster obtained for the player is to draw on a 5 with a frequency of 80%. He comments that this strategy is roughly equivalent to standing on the (2,3) combination only and is known to very expert players although they don't know why this is the best play. The optimal strategy Foster obtained for the banker assumes the player is only standing on the (2,3) combination. It is given in Fig. 2.10 and yields an advantage percentage of 1.287 to the banker. Banker has initial of

The strategy given by the simulation program compares favourably with Foster's (or I wouldn't give it). Although not giving the extreme accuracy of Foster's results, it is more than adequate. This is because it was assumed that the composition of the deck was unchanged by the deal, a reasonable assumption at the beginning of a game. However, as more and more cards are seen and discarded, it is possible to predict the values of the remaining cards with increasing accuracy until, when only one card is left, certainty is reached. Such play significantly alters the pure calculated strategy.

Assume the banker is actually watching the cards carefully and a position is reached where all the remaining cards in the pack are of value 4 or less. This means the banker can always draw on a 5 or less irrespective of what the player mayor may not have been dealt. The banker, in such a position, would put up a large bet with an excellent chance of winning it. Fine play like this has not been considered but it must raise the banker's advantage.

The next section deals with a similar game where such fine play considerations have been discovered for the player, and have resulted in very successful winning systems.

### 2.4 BLACK JACK

Other names for this game are pontoon and vingt-et-un. It is the most popular card game in casinos and, until ten years ago, it was assumed that the dealer (playing for the casino) had the advantage. Edward Thorp (8), in a series of studies using a digital computer, developed a betting system with which he consistently beat the casinos. The system is described in his book Beat the Dealer, along with entertaining anecdotes of his experiences in the gambling world. He was so successful that he was barred from playing on many occasions, and eventually the casinos had to alter the rules to cut their losses to the many system players who followed Thorp's instruction.

#### How the game is played

Assume there is only one player. To play he first makes a bet, the limits of which are decided by the house, but normally range between £1 and £100. (The range is important, because the winning strategy is to vary the size of the bet depending on whether the situation is favourable or not.) The dealer then deals two cards to the player and two to himself. A crucial fact is that one of the dealer's cards is face up. The object of the game is to obtain a total which is greater than the dealer's, but not greater than 21. The player can value an ace as either 1 or 11; J, Q and K count as 10, and all other cards have their face value. For example

```    J, Q = 20
A, 5 = 6 or 16
A, 10 = 21 (a natural or blackjack)
```

The first hand is called a hard hand because it has a unique value; the last two are termed soft because the ace allows for two totals, less than or equal to 21. The distinction is important, as will be seen.

If the dealer shows an ace or a ten, he may himself have a natural; to save time he then checks his hole card and declares the hand if this is the case. If the dealer does not have a natural the player now looks at his cards. He may either elect to stand or he can ask for extra cards. These are dealt one at a time and face up. If a card makes the player's total exceed 21 then he has bust and loses his bet. If he does eventually stand then it is the dealer's turn to play.

Irrespective of what the player has done, the dealer is restricted to a simple strategy. He turns over his hole card and if his total is 17 or more he will stand, otherwise he must draw cards until the condition is met or he busts (in which case the player has won his bet).

If neither player nor dealer bust then the higher hand wins an amount equal to the player's bet. In the event of a draw no money changes hands.

There are two other features in the game:

1. Splitting pairs: If the player's first two cards are identical in value, t hen he may split them into two hands and receive a second card on each. In effect it allows a player to have and play two hands if he wishes.
2. Doubling down: After looking at the initial value of his hand (or hands), a player may double his bet and draw one, and only one, more card.

#### The basic strategy

The rules are more complex then chemin-de-fer, so a greater number of situations have to be investigated. Nevertheless the empirical approach used for chemin-de-fer can still be applied, but in this case the simulation is run over many thousands of hands and the results are very accurate.

Consider first the situation where a player has been dealt a hard total of 16 and the dealer is showing an ace. The dealer does not have a natural. The slight significance of the actual cards making up the 16 (they can be (10,6) (9,7) or (8,8)) is overcome by doing a large number of trials.

The first experiment is to assume the player stands. The simulation program now reveals the dealer's hole card, which is any card other than a ten (he didn't have a natural), and then continues to give the dealer random cards (now including the correct probability of a ten) until the dealer busts or has a hard or soft total of 17 or more. If the dealer busts then the player wins; if the dealer does not bust then the player, with only 16, must lose. Adding +1 for a win and -1 for a loss results, over a hundred hands, in a net loss of 66 units for the player (the dealer wins 83 and the player only 17). Therefore the player who stands on hard 16 against an ace loses at the rate of 66%.

Now assume the player draws just one extra random card to his 16. He may now bust, and if he does the dealer wins (this is the main advantage the dealer has in the game). If, however, the player does not bust, then the dealer is given cards as before. A tie may occur. Adding 0 for a tie, +1 for a win, and -1 for a loss results, over a hundred hands, in a net loss to the player of about 51 units.

Obviously the particular situation is unfavourable to the player but he can minimise his losses by always drawing one more card; in fact, he gains an advantage of 66 - 51 = 15% by drawing rather than standing.

Thorp gives extracts of the computer's output for the player's gain by drawing rather than standing for all hard totals greater than 11. These are reproduced in Fig. 2.11. All positive gains (those to the left of the thick line) are situations where the player should draw; if the gain is negative he should stand. The value of 15% just mentioned, for the case of hard 16 against an ace, is highlighted.

Players total (21 would require at least 3 cards to be hard
Dealer
shows
but
never
has
a
natural
12 13 14 15 16 17 18 19 20 21
2 4 -2 -8 -14 -17 -38 -75 -114 -147 -200
3 1 -5 -12 -18 -21 -42 -78 -110 -148 -200
4 -2 -9 -16 -22 -26 -47 -76 -112 -149 -200
5 -5 -12 -19 -26 -30 -55 -79 -116 -152 -200
6 -3 -9 -17 -23 -22 -47 -85 -119 -154 -200
7 21 17 11 12 11 -33 -96 -131 -161 -200
8 19 15 15 11 10 -8 -66 -127 -163 -200
9 14 15 10 6 6 -11 -40 -96 -159 -200
10 16 12 8 4 3 -15 -47 -81 -142 -200
A 25 22 19 16 15 -9 -55 -105 -153 -200
PLAYER DRAWS PLAYER STANDS
##### Fig 2.11 Player's gain by drawing rather than standing

The same method was used to calculate the player's gain (and hence his strategy) for soft totals, i.e. one of the cards is an ace which is counted as 11, but the total is still ≤ 21. The draw/stand demarcation for these situations is given in Fig. 2.12.

##### Fig 2.12

It shows that a player should only stand on a total of at least 19 if the dealer shows a 9 or 10; on at least 18 for all other dealer's up cards. Note that the strategy recommends drawing to higher soft totals than hard totals; compare Fig. 2.11 with Fig. 2.12.

Of course the restriction of drawing just one extra card is used only to discover the correct action. If a player was dealt a hard 12 against a 7, then he must continue drawing cards until he reaches a total of at least 17.

The decisions of whether to split pairs and whether to double down (risking twice the original bet) on hard and soft totals were next investigated. Fig. 2.13 gives the results computed by Thorp. These decision tables are called the basic strategy, and a player using them would normally reduce the casino's advantage to about 0.5%. The flow diagram of a program to use tables is given in Fig. 2.14. Although incomplete (it does not check whether it has bust or not), it is fairly complex and exemplifies the detailed descriptions required by computers before they can play games.

SPLIT? (a 1 means split)
Dealer
2 3 4 5 6 7 8 9 10 A
Player
has
A,A 1 1 1 1 1 1 1 1 1 1
10,10
9,9 1 1 1 1 1 1 1
8,8 1 1 1 1 1 1 1 1 1 1
7,7 1 1 1 1 1 1 1
6,6 1 1 1 1 1 1
5,5
4,4 1
3,3 1 1 1 1 1 1
2,2 1 1 1 1 1 1
DOUBLE? (a 1 means double)
Dealer
2 3 4 5 6 7 8 9 10 A
Player
has
HARD 11 1 1 1 1 1 1 1 1 1 1
10 1 1 1 1 1 1 1 1
9 1 1 1 1 1
SOFT A,7 1 1 1 1
A,6 1 1 1 1 1
A,5 1 1 1
A,4 1 1 1
A,3 1 1 1
A,2 1 1 1

##### Fig. 2.14 A flow diagram of the player's key decisions

Ignoring the complexities of programming, the strategy is fairly easy for a human player to learn and operate. The surprising thing is that is gives such an even game. On discovering this encouraging fact, Thorp went on to calculate a winning strategy. He used the same program which had obtained the basic strategy for a normal deck to find (a) the best strategy for certain special decks, and (b) the resulting total advantage/ disadvantage to the player.

The most interesting results were obtained when the computer played the game with decks from which had been removed, in turn, all the aces, all the twos, and so on. These results are given in Fig. 2.15.

CARDS REMOVED FROM DECK
2 3 4 5 6 7 8 9 10 A
PLAYER's ADVANTAGE 1.8 2.1 2.6 3.6 2.4 2.1 0.4 -0.4 -1.6 -2.42

(with corresponding best strategy)

##### Fig 2.15 Reduced Packs

The results show that when there are high cards missing (9,1O,A) the casino has the advantage; when low cards are missing (2,3,4,5,6,7,8) then the player has the advantage. In a normal game the composition of the deck is changing, and it is possible for the deck to have, relatively speaking, fewer high or low cards.

Consider the particular case of the fives missing. Assume only one player is in the game, used cards from previous hands being put aside. Then about one hand in ten will be played from a deck which has no fives; this is equivalent to the original deck having no fives, and the player has a better than 3% advantage with best strategy play.

Ignoring the finer points, his main advantage is derived from knowing the now relevant hard standing totals. There are only four alterations and these are shown highlighted in Fig. 2.16.

Dealer Shows (from Fig. 2.11)
2 3 4 5 6 7 8 9 10 A
Normal 13 13 12 12 12 17 17 17 17 17
No Fives 12 12 12 12 12 17 17 15 15 17
##### Fig 2.16 Missing Fives

In all other decisions he plays the normal basic strategy. Now assume the player takes 100 hands per hour. There will be about 10 situations when no fives remain and his advantage is about 3%. If he bets £10 in these situations his net gain will be

```   10 × 0.03 × 10 = £3
```

The rest of the time (90%) he plays the basic strategy, essentially waiting. His disadvantage is 0.5%. If he bets £1 in these unfavourable situations then his net loss will be

```90 × 0.005 × 1 = 45p
```

giving a net profit overall of £2.55 per hour.

Having shown, by the above example, that it is possible to win at the game (albeit rather slowly), Thorp developed a much more powerful system called the Ten Count System.

##### The Ten Count System

The same program which had produced the Basic and the Missing Fives strategy was again used to compute the best strategy, and the player's resulting advantage with varying numbers of Tens, The results are given in Fig. 2.17.

Normal
Deck
Number of Tens 0 4 8 12 16 20 24 28 32 36
Player's Advantage -1.6 -2.1 -3.1 -1.9 -0.5 1.9 3.5 5.1 6.5 7.7
Ratio of Others/Tens 9 4.5 3 2.25 1.8 1.5 1.3 1.1 1
36/0 36/4 36/8 36/12 36/16 36/20 36/24 36/28 36/32 36/36

In a normal deck there are 16 Tens and 36 Others giving the ratio Others/Tens of 2.25. Fig. 2.17 shows that the player has an increasing advantage the more Tens are in the deck, and this is equivalent to the ratio Others/Tens becoming greater than 2.25 in normal play. For example, say there are 20 cards left to be dealt, and the player (by counting) knows that there are 10 Tens still to be dealt. Then the situation is exactly as if the game had begun with 36 tens and 36 others; the ratio of Others/Tens is the same and the player has an advantage of 7.7%.

There are three problems to be overcome before the Ten Count System can be used successfully:

1. To calculate the ratio Others/Tens, a player must be in a game where he can see almost all the cards played. Some casinos deal the cards face up (the dealer has fixed rules so he gains no advantage). If this is not the case then a player must either play by himself or with people who will turn their cards up.
2. Knowing the ratio Others/Tens, the amount of the bet must be calculated. The winning system fundamentally depends on betting the minimum when the casino has the advantage (roughly half the time), and the maximum when the player has the advantage. Unfortunately such behaviour (called betting wild) is unwise, partly because it requires a very large bank roll as the fluctuations of fortune are enormous, and partly because it can win at such a rate as to cause the player to be banned from the casino. To guard against the fluctuations, and winning too quickly, it is better to relate the amount of the bet to the amount of the advantage. Thorp suggests the following scheme:
Others/Tens ratio Bet (in units)
> 2 1 (minimum)
2 - 1.75 2
1.75 - .65 4
< 1.65 5 (maximum)
3. Finally, the best strategy changes as the ratio changes. All the results from the computer had to be combined into a system which would allow for this and also be possible to commit to memory. The resulting tables for strategy are complicated and require at least one week for a player to become proficient.

In his book Thorp describes his (very entertaining) adventures in the gambling casinos using his Ten Count System. Many other people also used it and the result was that the casinos began to lose heavily. In 1963 the inevitable happened. A computer had calculated the strategies, so why not use a computer to actually play the game? The Tropicana Hotel in Las Vegas accepted a match against a computer (called the LGP 21) using methods similar to those described above. The machine won \$360 in one hour. The casinos were by then thoroughly alarmed. The rules were changed to stop the system players winning, and these counter measures have resulted in the good system player barely holding his own and the uninformed amateur playing at a disadvantage.

The ultimate player would be a large digital computer which could play very accurately and also, by counting every card, exploit powerful end play. For example, it would be possible to know the dealer's hole card having seen all the other fifty-one cards and this would give the computer an advantage of 10%. This is very unlikely to happen, because (a) large computers cost a lot of money to use, and (b) why shouldn't the casino use a computer also? Although the dealer's strategy is fixed he can shuffle whenever he wishes. How does he know when to do this? A simple device would be two dip switches at the dealer's foot; one is pressed to count Tens and the other to count Others, a warning signal (e.g. locking the switches) could be made by a simple computer when the deck becomes advantageous to the player. The result is the dealer shuffles, and the player or computer is then always at a disadvantage.

##### The friendly game

A version of the game most people are familiar with outside the casino allows the deal to change hands. This occurs when a player is dealt a natural (A, 10). Because of this, the game is even in the long run. However, in the short run, the dealer has a tremendous (> 10%) advantage if the following common rules are also in force:

1. All cards are dealt face down.
2. The dealer wins all ties.
3. The dealer is not constrained to a set strategy.

The finer details of the player's strategies in the casino game are now overwhelmed by the simple fact that his advantage will rarely overcome the dealer's. He must now always bet minimum stakes and wait for his turn to win the deal. Because the dealer shows no cards the player's best strategy is to stand on hard totals of 17 or more and soft totals of 18 or more (this is the dealer's strategy also). The player should split aces and eights and double down on 10 or 11 only.

A winning strategy is to throw in stacked hands which increase the possibility of a natural being dealt, e.g., if four people are playing and one player has five cards from his last hand (probably bust). Arrange them A, *, *, *,10 before throwing them in. This is called a set up. The more cards a player holds the easier it is to make a set up. The best strategy in this type of play is to stand on hard totals of 17 or more, always draw to a soft hand unless one already has the cards for a set up, split aces, tens and eights and double down on eleven only.

### 2.5 WHIST-TYPE GAMES

Several programs have been written to bid bridge hands (9). The technique is usually a large table-lookup (derived by the programmer from one of the conventional bidding systems), and is relatively unsophisticated. The programming of computers to actually play whist-type games has not attracted much attention. The reasons for this are many and varied (see Chapter 7, Future Developments); but most of the problems will be solved by the first machine which is able to win that most trivial of card games-namely SNAP.