The test game. The examples use one test game. It is not a real product. It has 5 reels and each reel shows 3 symbols. Three scatter symbols start 10 free spins. In the free spins, a multiplier grows by 2.29 after each winning spin.
A book is the record of one round. It contains the events of the round and the payout. A weight sets how frequently the game selects the book. Each metric in this series is a calculation on the books and the weights.
The series sorts the metrics into 4 levels. The level tells how much of a book the metric reads. Level 0 reads only the payout. Level 1 reads the events also. This post shows these 2 levels. In the formulas, X is the payout of one round and c is the price of the round.
Level 0The payout only
RTP = E[X] / c = Σ wᵢ xᵢ / Σ wᵢThe RTP is the part of all stakes that the game pays back in a long run. The regulator and the business use it. In one session, the result of a player can be far from the RTP.
Multiply the payout of each book by its weight, and add the products. Divide by the sum of the weights, and then by the price of the round.
c- The price of the round, in stakes. A base spin has the price 1.
xᵢ- The payout of book i, in stakes.
/- Divide the left side by the right side. It is the same as ÷.
Example. 3 books pay 0×, 2× and 5×, and their weights are 7, 2 and 1. At a price of 1 stake, the RTP is (7 × 0 + 2 × 2 + 1 × 5) ÷ 10 = 0.9, or 90%.
mean_payout = sum(b.weight * b.payout for b in books) / sum(b.weight for b in books)
rtp = mean_payout / priceUse it. Set the target first, and let the optimiser change the weights until the RTP is equal to the target.
σ = SD(X) / cThe volatility is the standard deviation of the payout of one round. A game with frequent medium wins and a game with rare large wins can have the same volatility. Its main use is the calculation of the convergence length.
For each round, subtract the mean payout from the payout, and multiply the difference by itself. Find the mean of these squares, then its square root, and divide by the price of the round.
SD(X)- The standard deviation of the payout. It measures how far the payout of a single round is from the mean payout.
Example. 4 rounds pay 0×, 0×, 0× and 4×, and the mean payout is 1×. The squares are 1, 1, 1 and 9, their mean is 3, and the square root of 3 is 1.73.
mean = sum(r.payout for r in rounds) / len(rounds)
squares = [(r.payout - mean) ** 2 for r in rounds]
volatility = (sum(squares) / len(squares)) ** 0.5 / priceUse it. To decrease the volatility, move a part of the RTP from the rare large wins to the frequent small wins.
n = (1.96 · σ / ε)²The convergence length is the number of rounds before the measured RTP is near the true RTP. If the volatility doubles, the convergence length becomes 4 times larger. A session is much shorter. As a result, a player cannot feel the RTP in a session.
Multiply the volatility by 1.96, divide by the error that you accept, and multiply the result by itself. This is the number of rounds that a simulation must run.
ε- The error that you accept. An error of 1% is 0.01.
·- Multiply the left side by the right side.
( … )²- Multiply the value in the brackets by itself.
Example. For the test game and an error of 1%, 1.96 × 9.48 ÷ 0.01 = 1858, and 1858 × 1858 is 3.45 million rounds.
error = 0.01 # 1%
rounds_needed = (1.96 * volatility / error) ** 2Use it. Simulate this number of rounds or more before you trust a measured RTP.
n rounds, the measured RTP is within ε of the true RTP in 95% of cases if n ≥ (1.96 · σ / ε)².A simulation gives a measured RTP that is not exactly the true RTP. With the number of rounds of the formula, the difference is smaller than the error in 95 of 100 runs.
Example: the true RTP is 96% and the error is 1%. In 95 of 100 runs, the measured RTP is between 95% and 97%.
- The measured RTP is the mean of
nindependent payouts. Each payout has the standard deviationσ. - The central limit theorem says that this mean is almost normal. Its standard error is
σ / √n. - A normal value is within 1.96 standard errors of its mean in 95% of cases.
- The condition is
1.96 · σ / √n ≤ ε. - Solve for
n. The result isn ≥ (1.96 · σ / ε)².
hit = P(X > 0) real = P(X ≥ c) LDW = P(0 < X < c)The hit rate counts each spin that pays more than 0. But 40% of all spins pay less than the stake. The game shows a win and the balance of the player decreases. Only 15% of the spins pay the stake or more.
For the hit rate, count the rounds that pay more than 0, and divide by the number of all rounds. For the real-win rate, count only the rounds that pay the price of the round or more. For the third rate, count only the rounds that pay more than 0 and less than the price.
hit = len([r for r in rounds if r.payout > 0]) / len(rounds)
real = len([r for r in rounds if r.payout >= price]) / len(rounds)
ldw = len([r for r in rounds if 0 < r.payout < price]) / len(rounds)Use it. To decrease the losses disguised as wins, increase the smallest pays to the stake or remove them.
for each win size b: P(X in b) and E[X · 1(X in b)] / E[X]The win tiers give 2 numbers for each win size. The first number is how frequently the win size occurs. The second number is the part of the RTP that the win size pays. Compare the 2 columns in Figure 1.
Sort the rounds into groups by the size of the payout. For each group, calculate 2 parts: its part of all rounds, and its part of the sum of all payouts.
b- One win size, for example from 2× to 5×.
1(X in b)- 1 if the payout is in the win size b. If not, 0.
tier = [r for r in rounds if low <= r.payout < high]
frequency = len(tier) / len(rounds)
rtp_part = sum(r.payout for r in tier) / sum(r.payout for r in rounds)Use it. Look for a rare win size that pays a large part of the RTP. Most players do not get that part: move weight from its books to books with smaller wins.
H = −Σ s_b · log(s_b) / log(B) s_b = the part of the RTP in tier b B = the number of tiers that payThe tier entropy is 1 if each tier that pays gives the same part of the RTP. It is near 0 if one tier pays almost all of the RTP. It gives one number for the spread of the RTP across the win sizes.
For each win size that pays, multiply its part of the RTP by the logarithm of that part. Add the results, change the sign, and divide by the logarithm of the number of these win sizes.
log( x )- The logarithm of x. You do not calculate it by hand: the program below has a function for it.
B- The number of win sizes that pay. The rounds with no win are not a win size here.
−Σ- Add all the values, and then change the sign of the sum.
Example. 2 win sizes that pay 50% and 50% of the RTP give a tier entropy of 1. If they pay 90% and 10%, the tier entropy is 0.47.
from math import log
shares = [rtp_part(tier) for tier in tiers] # the tiers that pay; the shares add up to 1
entropy = -sum(s * log(s) for s in shares if s > 0) / log(len(tiers))Use it. If the value is near 0, move RTP from the win size that pays most of it to the others.
tail(x) = E[X · 1(X ≥ x)] / E[X]The tail share is the part of the RTP that comes from wins of x or more. A player who never sees a win of 100× does not receive this part. In the test game, this part is 27% of the RTP.
Select a win size, for example 100×. Add the payouts of all rounds that pay this size or more, and divide by the sum of all payouts.
x- The win size that you select.
1(X ≥ x)- 1 if the payout is x or more. If not, 0.
Example. The RTP of the test game is 96.0%, but it is 70.0% for a player who gets no win of 100× or more.
large = [r for r in rounds if r.payout >= 100]
tail_share = sum(r.payout for r in large) / sum(r.payout for r in rounds)Use it. Set a range for the tail share at 100× in the optimiser, for example from 20% to 30%.
gap = the number of spins between 2 real winsThe real-win rate tells how frequently a real win occurs. The dry spell tells how long the player waits for the next real win. A real win pays the stake or more.
After each real win, count the rounds with no real win before the next real win. Sort these counts: the median is the count in the middle. 9 of 10 dry spells are not longer than the 90th percentile.
gaps, gap = [], 0
for r in rounds:
if r.payout >= price: gaps.append(gap); gap = 0
else: gap += 1
gaps.sort()
median, p90 = gaps[len(gaps) // 2], gaps[len(gaps) * 9 // 10]Use it. Set a maximum for the 90th percentile, and increase the real-win rate until the game obeys it.
P(gap = k) = p · (1 − p)ᵏ. Here p is the real-win rate.If the rounds are independent, you can calculate the dry spells from the real-win rate. Take the chance of no real win 1 time for each spin of the dry spell, and multiply these values. Then multiply the result by the chance of a real win.
Example: the real-win rate is 0.2, and the chance of no real win is 0.8. The chance of a dry spell of 2 spins is 0.8 × 0.8 × 0.2 = 0.128.
- A dry spell of
kspins iskspins with no real win and then 1 real win. - The rounds are independent. Multiply the chances:
(1 − p)ᵏ · p. - The chance of a dry spell longer than
kspins is(1 − p)ᵏ⁺¹. - The median is the smallest
kwith(1 − p)ᵏ⁺¹ ≤ 0.5. It is nearln(0.5) / ln(1 − p).
The real-win rate of the test game is 15.0%. The formula gives a median of 4 spins and a 90th percentile of 14 spins. The simulation gives 4 spins and 14 spins.
What Level 0 cannot see
Part 1 showed an experiment with 2 games. The first game showed the total of 10 free spins in one step. The second game showed the same 10 spins one by one. Each Level 0 metric had the same value for the 2 games.
The players did not see the same round. Level 0 is sufficient for a certificate. It is not sufficient for a description of the game.
Why an optimiser can use these metrics
Each metric above is a weighted mean of one number for each book. That property has a use.
Σ wᵢ fᵢ / Σ wᵢ is a linear constraint on the weights.Each metric above reads 1 fixed number from each book and takes the weighted mean. A target for such a metric is a simple rule: each weight × a fixed number, and the sum must be 0. An optimiser can obey many rules of this type at the same time.
Example: 2 books pay 0× and 4×, and the target for the mean payout is 1×. The weights 3 and 1 obey the rule: 3 × (0 − 1) + 1 × (4 − 1) = 0.
- Book
ihas the weightwᵢ. The metric reads one fixed numberfᵢfrom the book. - The target is
Σ wᵢ fᵢ / Σ wᵢ = τ. - Multiply the 2 sides by
Σ wᵢ. The result isΣ wᵢ fᵢ = τ · Σ wᵢ. - Move all terms to the left side:
Σ wᵢ · (fᵢ − τ) = 0. - Each
fᵢ − τis a constant. The equation is linear in the weights.
For the RTP, fᵢ is the payout. For the hit rate, fᵢ is 1 if the book pays and 0 if it does not. A linear program can hold many such targets at the same time. An example is: "RTP 96%, tail share at 100× between 20% and 30%".
Level 1The events in the round
Level 1 metrics read what occurs in the round. Each metric is also a weighted mean of one number for each book. As a result, the proof of linearity applies to Level 1 too.
p_T = P(the feature starts) share = E[X from the feature] / E[X]The feature pays 45% of the RTP. The base game pays the remaining part and returns only 53% of the stakes. Half of the players wait more than 104 spins for the feature. One player in 10 waits more than 346 spins.
For the trigger rate, count the spins that start the feature, and divide by the number of all spins. For the feature share, add all the money that the features pay, and divide by the sum of all payouts.
p_T- The trigger rate.
trigger_rate = len([r for r in rounds if r.has_feature]) / len(rounds)
feature_share = sum(r.feature_win for r in rounds) / sum(r.payout for r in rounds)Use it. To make the wait for the feature shorter, increase the trigger rate and decrease the mean feature win.
cost = (1 − RTP of the base game) / p_T refund = P(feature win ≥ cost)The player loses money in the base game before each feature. The wait cost is the mean loss before one trigger. The refund is the chance that the feature pays the wait cost back. In the test game, only 28% of the features do that.
Subtract the RTP of the base game from 1: this is the mean loss of 1 base spin. Divide it by the trigger rate to get the mean loss before 1 feature. The refund is the part of the features that pay this cost or more.
Example. A base spin of the test game loses 0.472× on average, and the feature starts 1 time in 150.6 spins. The wait cost is 0.472 × 150.6 = 71.1×.
wait_cost = (1 - base_rtp) / trigger_rate
paid_back = [f for f in features if f.win >= wait_cost]
refund = len(paid_back) / len(features)Use it. If the refund is low, increase the RTP of the base game or the trigger rate.
dud = P(feature win < 10c) ratio = E[feature win] / median(feature win)A dud is a feature that pays less than 10×. The mean feature pays 65× and the median feature pays 35×. A high ratio tells that a small number of large features hold the mean up.
The dud rate is the part of the features that pay less than 10 times the price of the round. For the ratio, divide the mean feature win by the median: half of the features pay less than the median.
wins = sorted(f.win for f in features)
dud_rate = len([w for w in wins if w < 10 * price]) / len(wins)
median = wins[len(wins) // 2]
ratio = (sum(wins) / len(wins)) / medianUse it. Set a maximum for the dud rate. If the ratio is much above 1, select a multiplier law that grows more slowly.
effective multiplier = Σ feature wins / Σ the same wins at multiplier 1The effective multiplier shows how much of the feature value the multiplier makes. Here the multiplier makes the wins 8.3 times larger on average. If this number is high, the multiplier step is the strongest control of the feature.
Add the wins of all free spins. Then calculate the same wins with a multiplier of 1, and add them. Divide the first sum by the second sum.
paid = sum(spin.win for f in features for spin in f.spins)
at_one = sum(spin.win / spin.multiplier for f in features for spin in f.spins)
effective_multiplier = paid / at_oneUse it. If this number is high, make only small changes to the step of the multiplier.
tease = P(2 scatters on reels 1 to 4) conversion = P(trigger | tease)A tease shows the player that the feature is possible before the last reel stops. The conversion is the part of the teases that start the feature. In the test game, 80% of the teases end with a payout smaller than the stake.
The tease rate is the part of all spins that show 2 scatters on reels 1 to 4. For the conversion, use only the spins with a tease. Count the spins that start the feature, and divide by the number of teases.
teases = [r for r in rounds if r.has_tease]
tease_rate = len(teases) / len(rounds)
conversion = len([r for r in teases if r.has_feature]) / len(teases)Use it. If the conversion is low, set a minimum for it or decrease the tease rate.
centroid = Σ t · win_t / (n · Σ win_t)The centroid shows when the money arrives in the feature. A value near 0 is the first free spin and 1 is the last free spin. A multiplier that grows moves the centroid toward the end. In the test game, most of the money arrives in the second half of the feature.
Give each free spin a number, from 1 for the first free spin. Multiply the win of each free spin by its number, and add the products. Divide by the sum of the wins, and then by the number of free spins.
win_t- The win of free spin t.
n- In this formula, the number of free spins in the feature.
Example. A feature of 4 free spins pays 2× in spin 1 and 6× in spin 4. The centroid is (1 × 2 + 4 × 6) ÷ (4 × 8) = 0.81.
spins = feature.spins # then take the mean of all features
weighted = sum(t * spin.win for t, spin in enumerate(spins, start=1))
centroid = weighted / (len(spins) * sum(spin.win for spin in spins))Use it. To move money to the start of the feature, increase the start value of the multiplier and decrease its step.
Growth laws and length elasticity
A feature can increase a multiplier while it runs. The designer selects the law: flat, step, additive or geometric. One number compares the laws. It tells how much the value of the feature changes when the feature becomes longer.
ε = d log E[feature value] / d log (number of free spins)The length elasticity. If ε = 1, the value is proportional to the length. If ε = 2, the value is proportional to the square of the length.Make the feature a small amount longer, and calculate its mean value again. The elasticity is the growth of the value in percent, divided by the growth of the length in percent. With an elasticity of 2, 1% more free spins give about 2% more value.
ε- The length elasticity. In this formula, ε is not the error of the convergence length.
d log x- A small change of x, as a part of x. A change from 100 to 101 is 0.01.
Example. With the additive law of Figure 4, 8 free spins have the value 41.67× and 12 free spins have 90.57×. The program below gives an elasticity of 1.91 for these numbers.
from math import log
# value(n): the mean feature win with n free spins
short, long = 8, 12
elasticity = log(value(long) / value(short)) / log(long / short)Use it. If the elasticity is 2 or more, set a limit on retriggers, because long features hold most of the value.
With a flat multiplier, 2 times the free spins give 2 times the value. With a multiplier that grows by a fixed amount after each win, they give almost 4 times the value in a long feature.
Example: a spin wins with a chance of 0.5, and the mean win is 1×. With a flat multiplier, 10 free spins have the value 5× and 20 free spins have 10×. If the multiplier grows by 1 after each win, the values are 16.25× and 57.5×.
- Let
nbe the number of free spins. A spin wins with the chancep. The mean win at multiplier 1 isw. - Flat law: each spin has the expected value
p · w. The feature value isV(n) = n · p · w. Vis proportional ton. Thend log V / d log n = 1.- Additive law: the multiplier is
1 + s · kafterkwinning spins. Before spint, the expectedkisp · (t − 1). - The spins are independent. Add the expected values:
V(n) = p · w · (n + s · p · n · (n − 1) / 2). - For large
n, the term withn²is the largest. Thend log V / d log ngoes toward 2.
Measured at 10 free spins: flat 1.00, step 1.91, additive 1.91, geometric 2.70. The additive law is between 1 and 2, as the proof predicts. A geometric law has no upper limit.
A high elasticity makes each extra free spin more valuable. Then retriggers have a large effect and a small number of long features hold most of the value. The mean-to-median ratio is 1.52 for the flat law and 2.22 for the geometric law.
Level 1 explains the structure of the game. It does not show what the player sees during a round. For that, the model must contain what the player expects at each moment.
Do it with an AI agent
You do not write the calculations. You give the instructions, and you read the checks. Each check is a relation between the metrics of this post. A correct result obeys it.
Read my books and my weights. The price of a round is 1 stake. Calculate the RTP, the volatility, the hit rate, the real-win rate and the rate of losses disguised as wins. Use each weight as the frequency of its book. A real win pays the stake or more. A loss disguised as a win pays more than 0 and less than the stake.
You get. 5 numbers. The real-win rate plus the rate of losses disguised as wins must be equal to the hit rate. In the test game, 15.0% + 39.9% = 54.9%.
Sort the rounds into win sizes with these limits: 1×, 2×, 5×, 20×, 100× and 1000×. Rounds that pay 0 are a separate win size. For each win size, print its frequency and its part of the RTP. Print also the tail share at 100×: the part of the RTP from wins of 100× or more.
You get. A table with 2 columns, as in Figure 1. Each column adds up to 100%. The tail share at 100× is equal to the sum of the RTP parts of the win sizes from 100×. In the test game, it is 27.1%.
Draw 1 million rounds from my books in sequence, each book with the chance that its weight gives. A real win pays the stake or more. Count the rounds with no real win between 2 real wins. Print the median and the 90th percentile of these counts. Then predict the same 2 values from the real-win rate. Use the geometric distribution for independent rounds.
You get. 2 values from the simulation and 2 values from the prediction. In the test game, the simulation gives 4 and 14 spins, and the prediction gives 4 and 14 spins. A large difference shows that the rounds of your game are not independent.
Find each feature in my books. Calculate the trigger rate, the mean feature win, the feature share of the RTP, the wait cost and the refund. For the wait cost, subtract the RTP of the base game from 1, and divide by the trigger rate. The RTP of the base game counts no feature wins. The refund is the part of the features that pay the wait cost or more.
You get. 5 numbers. The RTP of the base game plus the trigger rate × the mean feature win must be equal to the RTP. In the test game, 52.8% + 43.2% = 96.0%.
Next: Part 3. Why the unknown excites: what the brain does with the events of a round.