Stickin’ It!

Over the past few years, we have become acquainted with slot games featuring variations on the stick’n’respin theme. In one of the most popular of those, a 3×5 machine, the wild symbol is present on Reels 2-4. When it lands in the window, it expands vertically to the entire visible part of the reel. The paylines are then evaluated (both left-to-right and right-to-left!) and the wild reel sticks during a free respin. If during a respin an additional wild symbol appears, it too will expand to the whole reel before line evaluation, and stick for yet another free respin. The process continues until no additional wild symbols appear. Thus, a player can get up to 4 spins with an increasing number of reels covered by wild symbols, all by staking and pressing the PLAY button only once.

As a continuation of the previous post, it is briefly explained below how this can be solved by means of Markov chains. Each spin in a “stick’n’respin cycle” is started with each of Reel 2, Reel 3 and Reel 4 being either wild or not. We will therefore work with 9 states numbered from 0 to 8, where 0-7 represent spinning with one of the possible wild distributions (think binary!) and 8 represents “no more spins”. Knowing the probabilities that a wild symbol appears on a specific reel, we readily get the transition probabilities between the states. Always performing the initial spin in State 0, it turns out that we will surely end up in State 8 no later than prior to the 5th consecutive spin (which is thus not executed).

If we consider a 3-bit binary number, where the least significant bit represents Reel 2, then we get a natural enumeration of the states 0-7. If the “wild probabilities” are, say, 0.02, 0.05 and 0.03, for reels 2, 3 and 4, respectively, and we repeatedly multiply the resulting transition matrix from the left by an initial vector with probability 1 for State 0 and probabilities 0 for all other states, we end up at the following table.

Expanding wild stick'n'respin probabilities

Expanding wild stick’n’respin probabilities

It is then a matter of calculating the conditional averages given that some of Reels 2-4 are wild which, to a large extent, is a matter of copy and paste (once we have the average for State 0). The nth column in the above table contains the probabilities that the nth spin is executed in State k, where k=8 means that the spin is not executed at all.

Another popular concept involving sticky wilds is to let all wild symbols popping up during a freespin session stick in their positions for the remainder of the freespins, thereby overriding any symbol that appears underneath. Assuming a possibly random but fixed number of freespins, we can solve this in a similar manner. Note that we may consider one payline at a time, and expand the average return linearly to all lines. If the wild symbol is present on all five reels, we have to deal with 32 states and need the conditional average for each of them. The corresponding probability table dictates how often the nth freespin is played with wild configuration k. These are then multiplied with the corresponding conditional averages and the sum of the products is the average total session win. Watch out if retriggers are possible!

A third variation on the same theme is to let the triggering scatter symbols turn into wilds and remain in their positions during an entire freespin session. It is standard that three or more scatter symbols are required (anywhere in the symbol window) in order to start the freespins. There are a number of differences compared to the previous concept, the most important ones being that we do not start at State 0, and different paylines are in general affected differently by the wild symbols. For simplicity, we assume that no additional wild symbols can appear during the freespins. Suppose that the game has 20 paylines. Then, given a triggering scatter/sticky wild combination, some of the paylines may not be affected at all while others have one or more wild symbols given.

Paylines are affected differently

Paylines are affected differently

Thus, in general, for each possible triggering combination we get one “line count” for each of the 32 possible wild configurations, adding up to 20. Again, we need the conditional averages for all possible wild configurations. Once those are in place, we weigh them with the line counts mentioned above to get the average total win per spin.

In order to complicate things, the latter two can be combined. It gets a little messier if we allow retriggers, since then we don’t know in advance how many freespins will be played. Also, we need to define whether or not a scatter symbol shall count should it appear underneath a sticky wild. All in all, however, it is usually possible to solve the game analytically with a bit of caution.

Linear Algebra, Cats and Dogs, and Markov Unchained

How can linear algebra be useful when designing a slot machine, other than indirectly through affine transformations when doing animations?

When creating the mathematical model of a slot machine, most calculations are rather straightforward. Sometimes complex, yet usually overviewable. However, in some situations, a mathematical trick or two may come in handy.

Suppose, for instance, that the slot machine features a pick’n’click bonus game in which the player gets to pick a number of boxes to reveal her wins. The bonus game is triggered when three or more DOG symbols appear in the slot machine window in one spin, and the number of picks is determined by how many CAT symbols that have been collected prior to entering the bonus game: 0 or 1 cat – one pick, 2 or 3 cats – two picks, 4 or more cats – three picks. It is then essential to find, not the average number of CAT symbols at the time when the bonus game is triggered, but the probabilities to enter the bonus game with 0 or 1, 2 or 3, at least 4 collected CAT symbols.

Or, we could consider the case where three or more BONUS symbols appearing in the slot machine window triggers the free game feature, where the player is given 10 free games with multiplier 2x. Whenever a PEARL symbol appears in the middle position of the middle reel, the multiplier increases by 1x for subsequent spins, up to at most 5x. We would then need to find the probabilities for spins 1, 2, …, 10 to be played with multipliers 2x, 3x, 4x and 5x, respectively.

It is, of course, possible to run simulations to estimate the sought probabilities. This is, however, not only personally unsatisfactory, but more importantly, some legislations do require that we calculate the exact parameters related to the rtp of the game.

One way of doing this is to set up a Markov chain or Markov process. Briefly, this is a system made up of states between which we transfer with certain probabilities from one observation point or period to the next. These transition probabilities depend only on the current state; they lack memory, in the sense that they are not affected by what has happened before the current state.

The second example above, translated into the language of Markov chains, has four states and ten observation points, the states being “Multiplier m”, where m=2,3,4,5 and the observation points being the ten free game rounds.

Collecting the transition probabilities in a matrix, we can use matrix multiplication to find the probability of being in a certain state after any number of observation points (this is where the linear algebra plays its role!). If the probability of getting a PEARL symbol at the middle position of the middle reel is, say, 1/8, then each column of the following matrix contains the probabilities of transferring from one state to each of the other.

b05matrix01

First spin is always played with multiplier 2, so the corresponding initial state vector looks like this.

b05matrix02

Performing matrix multiplication repeatedly, we end up with the following table, showing the probabilities for playing the nth spin with multiplier m.

 b05table01

It is left as an exercise to make the necessary modifications for the CATS and DOGS example above.

That’s a Bingo!

Creating the math model for a player vs. player Bingo game is easy. What is left of the pot when the commission has been deducted is distributed e.g. according to an hour-glass shape over the winning tickets, perhaps something like the table below.

bingoTable01

Or maybe more of a funnel-shape.

bingoTable02

Mission accomplished?

Well, in most cases not. We may want to add a jackpot which is paid out should a ticket obtain 1 row Bingo within, say, 13 drawn numbers. Or give out free tickets for the next round when the marked numbers on a ticket form a certain pattern. In order to control and fine-tune the playing experience, such as hit rates and average amounts paid for these bonus features, we need to know the probabilities for the respective events to occur.

For simplicity, let’s consider a Mini-Bingo, where each ticket consists of a 3×3 square grid of (nine) numbers between 1 and 21 inclusively. We want to calculate the probability of filling one row within k called numbers, where k ranges from 0 to 21. It does not matter which one of the three horizontal rows we fill, any of them will do.

Obviously, for k<3 the probability is 0 and for k>18 the probability is 1. For general k, we may perform the calculations in two steps, step A and step B.

A. Given that k numbers have been called, where k=0,1,…,21, find the probability that exactly j of them are present on the ticket.

B. Given that exactly j numbers have been marked on the ticket, find the probability that at least one row has been filled. Here, j ranges between 0 and 9.

We can then combine the two steps to find the probability that at least one row has been filled after k called numbers.

Step A is an exercise in elementary combinatorics involving binomial coefficients, while step B is the one that requires some more thought.

Consider first the case j=3, where three of the nine squares are marked. Since each row is formed by three squares, three out of the 84 patterns made up by three marks will qualify, so the sought probability is 3/84 or 1/28. When j=4, out of the 126 different patterns, the qualifying ones are those where three marks cover one of the three rows while the outlier may end up in any of the six remaining positions. Thus 3*6/126=1/7 is the number we are looking for. The case j=5 is similar, three of the marks cover one of the three rows while the other two can be distributed freely over the remaining six squares. The number of qualifying patterns is therefore 3*15, so our probability is 5/14. The same reasoning cannot be used when j=6, however. Since the three outliers may cover a row by themselves, we would count some qualifying patterns twice, namely those which cover precisely two rows. We end up with 3*20-3=57 qualifying patterns consisting of six marks, out of a total of 84 patterns. For j>6, all patterns qualify and for j<3 there are no patterns which could ever fill an entire row. We end up with the following probability table.

bingoTable04

Combining with the result from step A and performing similar calculations for 2 and 3 rows, we get the complete table of Bingo probabilities for this mini scale game.

bingoTable03

Also added is a column for the probabilities of covering the four corners. In addition to the prizes paid for 1, 2, and 3 row Bingo, we could maintain a progressive jackpot funded by 5% of all bets and paid when a ticket fills the corners within 5 called numbers. The average pot when hit is about $60 if the ticket price is $1, and it occurs once every 1200 tickets sold, on average.

Note that, as a byproduct of these calculations, we have the base for a player vs. bank type of Bingo game, where the probabilities are a prerequisite when stitching the win table together.

In the full scale case, where each ticket has 25 squares with numbers between 1 and 75, it is of course inconvenient to do the calculations in step B by hand. I would normally write a computer program working with bit operations, where one bit is assigned to each square in the grid. In a for loop, we let an integer mask range from 0 to 2^25-1. In each step, the number of bits set is our j. If the integer p is the bitmask for a certain win pattern, e.g. a row, we increment the appropriate counters when p&~mask=0. Here, & denotes bitwise AND while ~ denotes bitwise NOT. The code may look something like this.

bingoCode01

Line up!

5 or 15 lines? 25 or 243? The number of paylines does normally not affect the RTP of the game. And if it does, game designers have usually worked hard to make the difference as small as possible. So why do we keep changing it?

Mathematical volatility is one of the key factors affecting the feel of the game. Although there are a number other aspects of the number of paylines, this post focuses on its direct relation to the volatility. We need to set the number of paylines before designing the actual payout structure, or it will be difficult or impossible to give the game the desired momentum.

As we increase the number of paylines, we lower the volatility of the game. A high volatility means that wins tend to get bigger but occur less often. Conversely, a low volatility usually means that we win often but big wins are very rare or non-existent.

Also, even though increasing the number of paylines makes us win more often, it might happen that we increase the risk of winning less than we pay for each spin.

Playing the game with a different number of paylines can give the game an entirely different feel. Most players tend to play the maximum number of available paylines. Therefore game designers typically optimize the payout structure based on the maximum number of lines.

Modeling a game with Slot Designer, we can plot the following charts showing balance (Credit Meter) vs game rounds for typical playing sessions. We start with 3000 credits and play 1000 game rounds with a total of 27 credits per spin, but with different numbers of paylines.

In the first chart, we play 9 lines, 3 credits per line, making this a medium volatility game (σ=2.08).

9 lines/3 credits per line

This graph indicates some reasonable chances at peaks but at the same time the losing streaks aren’t so long.

In the next chart, we see a typical playing session of the exact same game, but on each spin we play 27 credits on only one payline.

1 line/27 credits

As is to be expected in this high volatility game (σ=6.33), the wins are fewer but bigger. In this particular case, we got lucky and hit a big win early during the session, but the losing streak that follows is long. Some players might enjoy the thrill of this game, while others feel they don’t win sufficiently often.

The last chart shows the same game played with one credit on 27 lines, making it a low volatility game (σ=1.15).

27 lines/1 credit per line

This graph is comparatively smooth with only small jumps. Unless there is a big jackpot to play for, this game would feel rather boring to some players, while others might find it entertaining due to the frequent wins.

While being but one of several interrelated factors, different volatilities appeal to different types of players, hence the number of paylines plays an important role in making the game an enjoyable experience!

Gauss, Berry and Esseen went to Monte Carlo


Normal (or Gaussian) probability distributions are very convenient to work with, due to their regular properties. They are widely used in statistical applications such as hypothesis testing and prediction. They become even more useful thanks to the Central Limit Theorem, which translated into the language of slot machines somewhat simplified states that if we hit the spin button sufficiently many times, our average win distribution can be approximated by a Normal distribution. All that is needed to find the best approximating Normal distribution for a certain number of game rounds is the mean value (RTP) and the variance (volatility).

 

For instance, many people have seen expressions like

P( m-d < X < m+d ) = 1-a.

It states that the probability is 1-a that the variable X falls within the distance d from its mean value m. The confidence level a is typically 0.1 (10%) or 0.05 (5%). If X is the RTP, this formula gives an idea of what to expect regarding the player return after a certain number of played game rounds. In the formula above, m is the theoretical RTP, and in view of the Central Limit Theorem, d can be approximated by the corresponding parameter from a Normal distribution which is easy to find.

The approximation by Gaussian distributions is also heavily relied upon in the testing phase of a game. A simple statistical method for finding bugs is to calculate the standard deviation for one game round and use expressions similar to the above formula to make predictions regarding the RTP after, say, a million game rounds. If too few or too many groups of a million game rounds have RTP outside the interval (m-d,m+d), then it’s a good idea to start looking for mistakes in the code or the configuration. This is also useful for finding situations with several bugs whose effect on the RTP cancel each other out to some extent – if the bugs have effect on the variance, it should show when grouping the game rounds and comparing the partial results.

So far, so good. But what is “sufficiently many”? The Berry-Esseen Theorem extends the Central Limit Theorem and says, again rather simplified, that the more skewed the distribution is, the more game rounds we may need to play for the Normal distribution to be a good enough approximation. And the probability distributions of games tend to be rather skewed.

As an example, we consider a scratch ticket game with a virtual batch of 200’000 tickets. We repeatedly simulate one million game rounds, which thus corresponds to five full cycles of the game, and compare the result with the best possible Normal distribution. In the diagram below, the Monte Carlo method has been applied 10’001 times on 1’000’000 game rounds, thus over ten billion game rounds have been simulated.

Approximation by Normal distribution 1

The curves show the inverse of the cumulative distribution function for the respective methods. The Monte Carlo curve is of course more jagged than the Normal distribution curve, but they seem to match pretty well. Zooming in at 95%, however, shows a discrepancy of more than one percent. And we all know the importance of one percent!

Approximation by Normal distribution 2

For a multi-line slot machine, the situation is a bit more complicated. It is usually easy to calculate the variance for
the base game when playing only one payline. It gets a bit more tricky to find the variance for the entire game if bonus features are involved. Most importantly, since two separate paylines are not statistically independent, we cannot calculate the variance for play on all lines by just dividing the one line variance by the number of paylines.

The Central Limit Theorem is certainly very useful also for us working with games, but I would recommend to use it with a bit of care!