A&B Computing
1st January 1989Categories: Programming (General) | Gambling
Author: Graham Kendall
Published in A&B Computing 6.01
A&B continues our attempts to teach you how to gamble effectively
Place Your Bets Please
In the last issue we looked at the process we need to go through to develop a computerised gambling system. In this issue, we are going to do just that. We will start with roulette as it is probably the easiest thing to program. Before we begin, we should know how roulette is played. We should also be aware of the house edge. As you will recall the house edge is the means whereby the casino guarantees it will win money.
The basics of roulette are very simple, so I won't bother to go into the rules. All we are required to do is to predict which number the ball will land in on the wheel. If it sounds impossible to predict the precise number there are a variety of bets we can make to cover more options. We can try to predict the colour of the number. Our alternatives being red or black. Or we can attempt to predict whether the number is going to be odd or even (zero does not count as even). Another bet we can choose is to say whether the number is going to be between 1 and 18 or 19 and 36. All bets are known as even chance bets and cover eighteen numbers in one bet. You will have noticed that none of them cover the zero.
Another bet allows you to cover twelve numbers with one bet. With this type of bet you can either cover, what are known as, dozens or columns. When you bet on dozens you are covering the numbers 1 to 12, 13 to 24 or 25 to 36. With a column bet you are covering every third number on the wheel. Therefore if you bet on column one you will be betting on the numbers 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31 and 34. By betting on column two you are covering the numbers 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32 and 35. Betting on column three, not surprisingly, allows you to cover the remaining numbers with the exception of zero.
Obviously different bets attract different payouts. If you bet on a single number, and win, you are paid at odds of 35-1. On an even chance bet, where you are covering eighteen numbers, the odds are 1-1 (evens). Betting on twelve numbers (columns or dozens) attract odds of 2-1. Now we understand the fundamentals of roulette we can take a look at the house edge.
For a casino to stay in business it must guarantee to win money. It does this by under paying you when you win. This can best be seen if we look at betting on a single number. If you were to bet on the number 17 and it won you would receive a payout of 35-1. Therefore you would receive 36 chips. This consisting of your original chip plus a payout of 35 chips. As there are thirty seven numbers on a roulette wheel the correct odds for predicting the correct number are actually 36-1. So you can see even when you win you are still losing money as the casino is under paying you.
A similar thing happens when you back twelve numbers (i.e. dozen or column bet) though it is easier to look at the house edge if we look at the effect zero has on such a bet. If you win on a dozen or column bet you are paid at odds of 2-1. However if zero comes up everybody who has placed a column or dozen bet loses their money. If the zero were not on the wheel the odds of 2-1 would be the true odds for this type of bet. With zero on the wheel however the odds are slightly more than 2-1. Therefore, because of the zero the casino has given itself a house edge.
Even chance bets also suffer the same fate when a zero comes up. If it were not for the zero the odds of 1-1 would be correct. When the zero turns up however the casino takes all money placed on even chance bets thus giving itself a house edge. (There is a special rule concerning zero and even chance bets but for now we will assume the casino wins.) So you can see the house edge in roulette comes by virtue of the fact that, there is a zero on the wheel. If no zero was present the even bets would truly be an even bet. Also by removing the zero the payout on a single number of 35-1 would be correct and the dozen and column bets at 2-1 would also be correct.
If we worked out the house edge we would find it comes out at about 2.5%. Compare that to something like horse racing, which can come out at twenty percent or more, and at first sight roulette offers the punters a good chance. In fact at 2.5% the house edge in roulette seems remarkably good value. What we need to bear in mind though is that the 2.5% house edge is working in the casinos favour all the time. Convert this to money and the casino should take 2.5% of all money that passes across the table.
Now we roughly know how roulette works and the house edge we are operating against we can consider whether it is worth taking the plunge and trying to design a computerised gambling system. I would suggest that 2.5% is a sufficiently small house edge to give it our serious consideration. We will throw ourselves it at the deep end and try to devise a system that will enable us to predict the next number that is going to turn up. Our aim is to do that at least once every thirty five spins. If we can achieve that, we will make a profit. If we cannot manage it we will make a loss. At least that part of the mathematics is simple.
To do any form of forecasting we must keep records of past events. The trick is to find the formula that will provide the answer to what is going to happen next, by looking at what has already happened. Our first problem is to decide what information we need to keep. As a starter I decided it would be worth storing whether the previous numbers were red or black, whether they fell in the first, second or third column and finally whether the number fell in the first, second or third dozen.
Having decided what information to record I designed the rest of the program from that starting point. The easiest way for you to understand how I went about this is for you to look at my completed program and you will see how I tackled the problem. Up to line 100 controls the rest of the program. The first time the program is entered PROCINIT is run. If the user decided additional runs are required, the program will not run PROCINIT again, but will run all the other procedures. PROCINIT (line 110-170) DIMs four arrays. A$ will hold the data stored in lines 1050-1410.
Each line of the data holds information about one of the numbers on a roulette wheel. The first item is the number itself. The second item indicates whether the number is red or black. The third item indicates which column the number falls in and the fourth item indicates which dozen the number is in. Once PROCINIT has been processed, the array A$ will hold this information. The array BET$ which is DIMed in PROCINIT is used as a temporary storage area when the program is trying to decide which number it should bet upon. Its use will become clearer a little later.
The two arrays STATS% and STATS1% are used to hold statistical information which is printed out at the end of the program so that you have some indication of how the program arrived at its conclusions. Again you will see their exact use a little later. PROCINIT1 (line 180-240) sets various variables to zero. This procedure is run every time the user requests another run. If the totals were not zeroised, we would be working with cumulative figures which we do not want to do. PROCSPIN (line 250-270) asks the user how many spins the wheel should make. The variable SPIN% is used to hold your answer and is later used to control a loop which spins the wheel. PROCGAME (line 280-460) is the meat of the program. The procedure has a loop in it which is controlled by SPIN%. The first thing the procedure does is to call PROCCHOOSEBET. This procedure results a number in NUMBET%. If the number returned is -1 this indicates the program has decided not to bet on this occasion. In fact this will be the case on the first few spins as the program will not have built up sufficient information to make a decision on which number to bet upon.
If the number returned is not -1 (i.e. the program has decided to bet) then MONEY% is decreased by 10 units. This is the equivalent of us placing a bet. You will have noticed that during the initialisation phase MONEY% was set to zero. Obviously when you go into a casino you would not go in with zero money. However for our purposes it makes the results easier to understand. If we end up with a negative value we have lost money. If we end up with a positive figure we have made money. Breaking even is indicated by MONEY% being equal to zero.
PROCGAME then chooses a number, at random, between 0 and 36. This represents the roulette wheel spinning. If the number returned by PROCCHOOSEBET and the random number match then MONEY% is increased by 360 units and WINS% is increased by 1. WINS% is a variable which we use to hold the total number of wins. MONEY% is increased by 360 which represents the casino paying us out at odds of 35-1 (we also receive our original ten units bet back). If the numbers do not match then LOSSES% is increased by 1. Similar to WINS%, LOSSES% is used to keep a tally on our losses.
The remainder of PROCGAME is concerned with collecting statistics. Each element of STATS% is used to hold the number of times each number occurred. As an example if the number 17 came up then STATS%(17) would be incremented by 1. BPSTATS1% is used similarly, but each element is used to keep a tally of the numbers that were bet upon, NO-BETS% is incremented if a bet was not placed and conversely BETSPLACED% is used to hold the number of times a bet was placed. Each line between 370-440 is looking at one aspect of the number that was spun and logging the information away to various variables. These variables are consulted later in the program when trying to decide which number to bet upon. PROCCHOOSEBET (line 470-610) is another important procedure.
It contains our selection formula. If you read the first article in the series, you will know this is the means whereby we try to ascertain which number we should bet upon. As this procedure is the reason for this article, we will delay its discussion until we have looked at the rest of the program. PROCPRINT (line 620-770) runs once the roulette wheel has completed the requested number of spins. It displays to the screen various information which the user might find useful. Without doubt the most important piece of information is how much money we have won or lose. As I have previously stated if a negative figure is shown, then we have lost money. If we are presented with a positive figure then we have made money.
PROCPRINTSTATS (line 780-870) displays a screen which shows how many times each number appeared. PROCPRINTSTATS1 (line 880-970) does a similar job to PROCPRINTSTATS except the figures shown are the numbers that were actually bet upon. The only other procedures in the program (PROCNEXTSCREEN and PROCPLAYAGAIN) are routines which keep the program running smoothly.
The selection formula we mentioned earlier is written within PROCCHOOSEBET. Now we have the basics of our program built, we can consider our selection formula. It is based on the theory that you can predict the next number by looking at what has happened before. To do that we consult the information we have been collecting. My theory runs something like this. If we have had more red numbers than black then a black number has more chance of appearing on the next spin. Similarly with columns. If we find that one of the columns has appeared less than the other two then that column has more chance of appearing on the next spin on the wheel. The same goes for dozens.
Once we have identified a suitable colour, column and dozen we then try to find a number which fits all three categories. If we can find such a number then we back it. That is the theory. How does PROCCHOOSEBET do this? Firstly, it compares the number of reds that have appeared with the number of blacks that have appeared. If it finds one is less than the other it sets that colour as its preferred choice. For example, if red had occurred more than black then black becomes the preferred choice. In this instance a "B" would be written to element 1 of BET$. A similar exercise is carried out for the dozens and columns In both of these instances it is trying to identify the column and the dozen that has appeared less than the other two.
If any of the above tests fail, for example number of reds equals the number of blacks, then the procedure returns a value of -1. This indicates the procedure does not wish to bet. If the procedure comes up with a preferred colour, column and dozen it can then begin to search for a suitable number on which to bet.
An example might make the process clearer. Let us assume blacks have predominated over reds, column two has appeared less than both column one and three and dozen one has appeared less than both the other dozens. Once the program had came up with its preferred choices the elements of BET$ would contain this information in the form R,2,1. This represents red, column 2 and dozen 1. The procedure now searches through A$ (which holds the details about each number) until it finds a match with BET$. In this particular case a match would be found against number five. As you can see from the DATA lines, the number five is red, it falls in column 2 and is in the first dozen. Once the procedure has found a suitable match, it returns the number in NUMBET%. If no match can be found a value of -1 is returned indicating the program will not make a bet on this spin.
In summary then, what are we doing? Firstly, we are sampling every spin of the wheel and collecting three sets of data. Based on that data we then search for a number which we think has more chance of coming up than any other. If we find such a match we bet upon it. BP Does it work? I will not bore you with lots of results. Suffice to say, it looks promising. Whether you would trust it in a casino though is only a decision you can make.
The selection formula I have given above is only the tip of the iceberg. The ways it can be developed are almost limitless. By some changes to PROCCHOOSEBET and maybe some changes to PROCGAME it will be very easy for you to develop your own selection formula. For example, you may decide that simply comparing reds against blacks is not good enough. You might want one colour to have come up at least ten more times than the other colour before betting.
Another thing you might want to consider is looking at the way the final number to bet upon is decided. If, for example, we were looking for a number that was red, in the first column and in the first dozen we would get the number 1. However number 7 also meets this criteria but as we end our search once we have found a suitable number we will never bet on 7. Would it be more sensible to find all possible numbers and then use some other method to decide between them? 'Or maybe we should spilt our money and bet on all possible numbers?
So far I have designed a system. It is up to you Test, Review and then Amend it. If you do your work correctly you will either come up with a winning formula or reach the conclusion that trying to predict the next number is an impossible task. The only thing I suggest you try is to change line 290 from
FOR CNT%=1 TO SPIN%:PROCCHOOSEBET
to
FOR CNT%=1 TO SPIN%:NUMBET% =RND(37)-1
This has the effect of not letting us have the benefit of our selection formula and making the number we bet upon totally random. If you played a casino under the same conditions you could expect to lose. It will be interesting to compare the random selection of numbers against the best selection formula you can come up with.
This article was converted to a web page from the following pages of A&B Computing 6.01.