Advertisement
Guest User

Slot demo

a guest
Feb 11th, 2019
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.27 KB | None | 0 0
  1. <?php
  2. // Our slot will be 3 reels, one win line, with 3 symbols.
  3. // X, BAR and 7.
  4. // 0 = X, 1 = BAR, 2 = 7
  5.  
  6. // This is the layout of the reels, running vertically. There are 20
  7. // symbols on each reel.
  8. $reels = [
  9.    // reel 1 has 10 X's, 7 Bars and 3 7s
  10.    [0,1,0,1,0,1,0,1,2,2,1,0,1,0,0,0,0,2,1,0],
  11.    // reel 2 has 11 X's, 7 Bars and 2 7s
  12.    [1,1,0,0,0,1,0,2,0,1,1,0,0,2,0,1,0,0,1,0],
  13.    // reel 3 has 9 X's, 9 Bars and 2 7s
  14.    [0,0,0,1,1,1,0,1,2,0,0,1,1,2,0,0,1,1,0,1],
  15. ];
  16.  
  17. // Let's map to the symbols:
  18. $symbols = [
  19.     0 => 'X',
  20.     1 => 'B',
  21.     2 => '7',
  22. ];
  23.  
  24. // Match 3 of the same symbol on the winline for a prize.
  25. // Xs will be the lowest win at 2x, BARs will pay 10x, 7s will pay a whopping 100x
  26. $paytable = [
  27.     'X' => 2,
  28.     'B' => 10,
  29.     '7' => 100,
  30. ];
  31.  
  32. // How many spins our game will run for.
  33. $spins = 100000;
  34.  
  35. // Bet size in £/$/whatever
  36. $bet = 1;
  37.  
  38. // How much money have we spun through in bets?
  39. $totalBet = 0;
  40.  
  41. // How much money have we won in total?
  42. $totalWin = 0;
  43.  
  44. // What is the RTP over the number of spins, as a percentage?
  45. $rtp = 0;
  46.  
  47. // Placeholder for counting the occurrences of each of the 3 possible types
  48. // of win.
  49. $wins = [
  50.     'X' => 0,
  51.     'B' => 0,
  52.     '7' => 0,
  53. ];
  54.  
  55. // Game loop - run for $spins
  56. for ($i=0; $i < $spins; $i++) {
  57.     // Let's take the money!
  58.     $totalBet = $totalBet + $bet;
  59.  
  60.     // We start by selecting a genuinely random reel position for each of the 3
  61.     // reels. Remember - there are 20 possible positions on each reel.
  62.     // The positions selected randomly are the symbols which will appear on
  63.     // the win line.
  64.     $reelPositions = [random_int(0, 19), random_int(0, 19), random_int(0, 19)];
  65.  
  66.     // What symbols do these positions map to? This creates the win line.
  67.     $reelSymbols = [
  68.         $symbols[$reels[0][$reelPositions[0]]], // first reel
  69.         $symbols[$reels[1][$reelPositions[1]]], // second
  70.         $symbols[$reels[2][$reelPositions[2]]], // third
  71.     ];
  72.  
  73.     // At this point, $symbols contains something like ['X', 'X', 'B'] or
  74.     // whatever our combination is. Let's display it in the form X-X-B.
  75.     //echo implode('-', $reelSymbols)."\n";
  76.  
  77.     // Now let's calculate if it was a win. To be a win, it must be the same
  78.     // symbol on all 3 reels.
  79.     // One way we can do this is to count how many different symbols are
  80.     // in the win line - if it's 1, they must all be the same.
  81.     if (count(array_unique($reelSymbols)) === 1) {
  82.         // It's a win. Let's compare the symbol on the win line to the paytable
  83.         // and add that amount of money to the total wins.
  84.         $totalWin = $totalWin + $paytable[$reelSymbols[0]];
  85.  
  86.         // Now let's add that symbol to our running count of how many wins
  87.         // of each type took place.
  88.         $wins[$reelSymbols[0]] = $wins[$reelSymbols[0]] + 1;
  89.     }
  90. }
  91.  
  92. // Let's calculate RTP. This is the total wins divided by the total bet, then
  93. // multiplied by 100 to give a percentage.
  94. $rtp = ($totalWin / $totalBet) * 100;
  95.  
  96. // Let's see what the results were:
  97. echo 'Spins: '.$spins."\n";
  98. echo 'Total bet: '.$totalBet."\n";
  99. echo 'Total wins: '.$totalWin."\n";
  100. echo 'Number of X-X-X: '.$wins['X']."\n";
  101. echo 'Number of B-B-B: '.$wins['B']."\n";
  102. echo 'Number of 7-7-7: '.$wins['7']."\n";
  103. echo 'RTP: '.$rtp."\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement