Punto Banco - an algorithm - 2
You should have played a few hands of Punto Banco now and be familar with the rules. To summarise, the player and bank both get two cards. Aces count as 1 and 10s, Jacks, Queens and Kings count as 0. A third card may be dealt, according to the tables below. The winner is the hand whose total is closest to 9. When a total is double digit e.g. 14, you only count the right hand digit, which is 4 in this example.
Player | |
Player has a total of: | |
0, 1, 2, 3, 4, 5 | Player must take another card |
6, 7, 8, 9 | Player must stick with the cards they have. |
Bank | |
Bank has a total of: | |
0, 1, 2 | Bank takes another card regardless of what the Player has. |
3 | Bank must take another card if the Player has any total except 8. |
4 | Bank must take another card only if the Player has a total of 2, 3, 4, 5, 6 or 7 |
5 | Bank must take another card only if the Player has a total of 4, 5, 6 or 7 |
6 | Bank must take another card only if the Player has a total of 6 or 7 |
7, 8, 9 | The Bank must stick with what they have. |
Payout
After a hand, the gamblers who bet on whether the Bank or Player or a draw would happen are paid. If you bet on the Player winning, you get your bet doubled. So if you bet £100 on the Player winning and they won, you would get £200 back. If you bet on the Bank winning, you get your bet back plus you win 95% of what you bet. So if you bet £100 on the Bank winning and they won, you would get £100 + £95 = £195 back. If you bet on a draw, you get your bet back plus you win 8 times what you bet. So if you bet £100 on a draw, you would get £900 back.
Our first attempt at an algorithm for the game might go like this:
Deal two cards to the player and bank
Add up the totals
Deal a third card to the player, according to the table above
Deal a third card to the bank, according to the table above
Calculate the new totals
Declare the result of the game
This is a good start. Let's try to break the problem down even more using pseudo-code so we can actually use this to code.
Intitialise the variables we need to hold data
Deal two cards each
Print the cards dealt and the totals
If the player's total < 6
print that the player must have another card
deal player another card
add up the new total
print final total
Else
print that the player must stick
If the (bank's total < 3) OR
((bank's total = 3) AND (player's total != 8)) OR
((bank's total = 4) AND ((player's total >2) AND (player's total <= 7))) OR
((bank's total = 5) AND ((player's total >4) AND (player's total <= 7))) OR
((bank's total = 6) AND ((player's total >6) AND (player's total <= 7)))
print that the bank must have another card
deal bank another card
add up the new total
print the final total
Else
print that the bank must stick
If bank > player
print bank won
elseif player > bank
print player won
elseif player = bank
print draw
This is looking much better. Notice the careful use of brackets when deciding whether the bank should get a third card and remember, the above is pseudo-code not Python or any other language. It is language-independent. Although the logic is (possibly) correct, we still need to convert it into an actual programming language. We haven't yet specified how we are actually going to deal a card, or how we are going to deal with 10s, Jacks, Kings, Queens and Aces and how we are going to work out the total. Nor have we written any pseudo-code for the actually placing of bets and tracking the winnings (or loses). We will look at dealing cards in the next section.