DEV Community

Rajnish Raj
Rajnish Raj

Posted on

Slot Game Math: Probability, Payouts, and RTP Explained

Hello Everyone!

For the past few weeks, I was working on a slot game, from the mathematical model to the backend to the frontend, everything.

So, in this blog, I am going to teach you how to develop a mathematical model of a very simple slot game, and finally we gonna calculate the theoretical RTP(Return to Player).

So, Let's begin.

Define Game rules

Before going into math, we need to define the game's pay rules, so Let's define it first.

  • There will be 3 reels; each reel has 3 rows.
  • There will be a total of 9 symbols, including the wild.
  • Wild symbols can be replaced by the 8 other symbols.
  • There will be 5 payout lines: two diagonals and all the rows.
  • The player bets X amount; then the bet per line will be X.

Slot Game

What is RTP?

RTP (Return to Player) is the average percentage of money a game gives back to players over a very large number of plays.

General formula for RTP :

RTP Formula

Variable description

Mathematical model

We know that there are 3 reels and 3 rows, so we can think of it like a 3x3 board, where the probability of symbols occupying a cell is given.

There are a total of 5 payout lines; let's analyze a single payout line.

There will be 2 cases :

  1. Matching symbols without wild
  2. Matching symbols with the wild.

And in the 2nd case, there will be two more cases :

  1. Matching symbols with one wild
  2. Matching symbols with two wild

If all the 3 symbols are wild, we gonna treat it as a normal symbol.

Let's go into math now.

We need to provide the probability and payout of symbols, but we can change it to reach our desired RTP.

Variable
Variable

Case 1 (Matching symbol in a single payout line without wild.)

Case 2 (Matching symbol in a single payout line with wild.)

Matching symbol in a single payout line with wild.

RTP contribution of a single payout line is

So, now we have to multiply this contribution by 5 to get the theoretical RTP of the game.

Calculating Theoretical RTP



const SYMBOLS = {
  "SEVEN": 5 ,
  "BELL": 8 , 
  "GRAPE": 8 , 
  "WATERMELON": 9  ,
  "ORANGE"    : 8 ,
  "BLUEBERRY" : 8 ,
  "LEMON": 7 ,
  "RASPBERRY" : 6,  
  "WILD"      : 5  
}

const REEL_SIZE = 64;
const PAYOUT_LINES = 5;

const PAYOUTS = {
    "WILD" : 10,
    "SEVEN" : 15,
    "BELL" : 8,
    "GRAPE" : 6,
    "WATERMELON" : 1,
    "ORANGE" : 0.5,
    "BLUEBERRY" : 0.5,
    "LEMON" : 0.5,
    "RASPBERRY" : 0.5,
}

Enter fullscreen mode Exit fullscreen mode
function clacuateRTP() {
  let rtp = 0;

  Object.keys(SYMBOLS).forEach((symbol) => {
    const symbol_prob = SYMBOLS[symbol] / REEL_SIZE;
    const wildProb = SYMBOLS["WILD"] / REEL_SIZE;

    if(symbol == "WILD") {
      const prob_wild = Math.pow(symbol_prob, 3);
      const payout_wild = PAYOUTS[symbol];

      const contribution = prob_wild * payout_wild;

      rtp += contribution * PAYOUT_LINES;

      return
    };

    const prob_without_wild = Math.pow(symbol_prob, 3)
    const prob_with_wild = 3 * wildProb * Math.pow(symbol_prob, 2) +  3 * Math.pow(wildProb, 2) * symbol_prob

    const payout_without_wild = prob_without_wild * PAYOUTS[symbol]
    const payout_with_wild =  prob_with_wild * PAYOUTS[symbol]

    const contribution = (payout_with_wild + payout_without_wild) 

    rtp += contribution * PAYOUT_LINES
  })

Enter fullscreen mode Exit fullscreen mode
"================================================================="
"symbol    ", "symbol prob    ", "contribution    "
"================================================================="
"SEVEN     ", "7.813          ", "0.0500679016    "
"BELL      ", "12.500         ", "0.0632324219    "
"GRAPE     ", "12.500         ", "0.0474243164    "
"WATERMELON", "14.063         ", "0.0099906921    "
"ORANGE    ", "12.500         ", "0.0039520264    "
"BLUEBERRY ", "12.500         ", "0.0039520264    "
"LEMON     ", "10.938         ", "0.0030574799    "
"RASPBERRY ", "9.375          ", "0.0023002625    "
"================================================================="
"TOTAL RTP = ", "94.37274932861328%"
Enter fullscreen mode Exit fullscreen mode

Conclusion

So, that's it for the mathematical model of a simple slot game!

We defined the game rules, broke down the probability calculations for both cases, with and without wilds across all 5 payout lines, and finally calculated a theoretical RTP of ~94.37%.

The best part?
You can tweak the symbol counts and payouts to hit any RTP you want. That's the power of having a proper mathematical model before writing a single line of game code.

Thank you :)

Top comments (0)