# How can I develop a prediction algorithm for a game of chance?

How can I develop a prediction algorithm in the case of games of chance? Suppose there is a 50:50 chance of winning. Is there way of creating a prediction algorithm?

• You can't predict something that is purely random – Daniel Oliveira May 9 '19 at 0:49
• You can predict how many times u should flip to get more profit, when you start with x value and wanting to finish at y... that's the most similar it gets – Miguel Saraiva May 9 '19 at 1:07
• There isn't really enough here to answer your question - from what you have here it sounds like you just want some statistics, rather than artificial intelligence, so are probably more suited to the cross validated stack exchange – Lio Elbammalf May 9 '19 at 8:52
• If you give more information about the game (use edit to add it), and how you hope your intended code would work (e.g. what are the inputs and outputs?) we could say with more certainty whether this was an AI or a more simple probability question. – Neil Slater May 9 '19 at 9:03
• @nbro: I think the edit here was premature. The OP might be intending to ask something quite different – Neil Slater May 9 '19 at 13:13

That really depends on the nature of the problem. I will assume that you asked this question on the AI stackexchange because you thought that there was a type of AI that would solve the problem. By giving a certain chance that something happens, you also imply that if the number of samples increases, the relative frequency of an outcome will converge to the probability of an outcome. Thus, having AI predict what outcome is more likely if you know that both outcomes are as likely is not necessary. AI is trained to predict without known chances based on a dataset. If you know the odds of the outcome, for example O1 has 60% chance of happening and O2 40% you can predict O1 since it is simply more likely. No algorithm is needed.

If you on the other hand mean that if you know that for each situation there are outcomes with a certain chance and you know some outcomes until now and you want to predict the next one, then I should respond to your question differently. If you don't know much about statistics you could create an AI that would, based on a long dataset of outcomes, try to predict the next outcome based on the configurations of outcomes it has already seen. You might thus in other words try to argue that it is unlikely that for example O1 happens 11 times in a row, and thus that the eleventh outcome will be O2 and this will be detected by the AI. Your argument is true and an AI will probably detect that a certain configuration is unlikely, but that still isn't able to correctly predict the outcome of the next situation. This argument results from something called "Gambler's fallacy" and on its Wikipedia page there is a sentence that is relevant to your argument and summarizes what I'm trying to say by giving an example.

"If a fair coin is flipped 21 times, the probability of 21 heads is 1 in 2,097,152. The probability of flipping a head after having already flipped 20 heads in a row is 1 / 2 ."

Thus to answer your question: an algorithm or AI to predict something with a certain probability which is already known is unnecessary. If you are talking about predicting the outcome of one situation without any other data then its unnecessary since you already know the probablity and thus something to approximate the probability isn't needed. If you are talking about predicting the outcome based on the previous ones and the information what the probabilities are then this is incorrect because this is the "gambler's fallacy". What happened until now and what happens next isn't the same as what is able to happen in general, as a whole.

If you mean something entirely different or my answer doesn't cover what you wanted explained, or my answer is incorrect then please comment on it.

I would also suggest asking this question in the stackexchange about statistics/mathematics etc. Maybe there someone will know more.

Of course, my answer only talks about a purely random situation where no other factors are taken into account. If you are talking about a real game, then one can use thing like characteristics of the people playing, size, shapes of dices, shakers etc., outcomes that already happened to approximate the odds of outcomes and thus always bet on the most likely one.

The first thing to do is to collect the data from the gambling table. If the game is called roulette then the trajectory of the ball is important, if the game is blackjack then the cards which are played in the past should be memorized. And if it's a dice game, than also the values from the past plus some additional features like the size of the shaker have to be stored in a database. If more data are available the quality of the overall system becomes better.

In the next step the data have to transferred into a prediction model. The model is used for a time series prediction, that means it can say in advance on which position the roulette ball will stop. A possible technique for doing so is stochastic regression, another option is deeplearning. The amount of papers about prediction of the outcome of random-variables is small. The reason is, that most serious researchers doesn't want to tell the public what they know about the subject. So it's becomes important to talk with independent scientists who are more open.

What we can say for sure is, that roulette prediction based on Fuzzy set theory aren't working. So called grey box models will predict anything but not the outcome of the wheel. So i would recommend to start the journey in the fascinating subject with regression and test the model in a computer game before try it out in reality.

[1] Diaconescu, Eugen. "The use of NARX neural networks to predict chaotic time series." Wseas Transactions on computer research 3.3 (2008): 182-191.

Yes. The program is simple and derived trivially from the supposition in the question.

Given a new set of random events with a 50/50 chance of either of two outcomes for each event, the prediction can be expressed as the following probability distribution.

$$P_s = \prod_{n = 1}^{N_s} 0.5 = 2^{-N_s} \, \text{,}$$

for any specific sequence $$s$$ of $$N_s$$ events. This is the algorithm to get the distribution.

define getDistribution(fiftyFiftyEventsList)
permutations = enumeratePermutations(fiftyFiftyEventsList)
commonProbability = power(2.0, - events.size)
var distributionMap
for permutation in permutations
distributionMap[permutation] = commonProbability
return distribution



Without more bits of information, the probability distribution cannot be adjustment to produce a more useful prediction.