Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<body>
  <div class="container">
    <div class="row justify-content-center" id="react-root"></div>
  </div>
</body>
</html>
              
            
!

CSS

              
                $sprites-url: "https://tower.bet/static/images/slots/verifier/symbols.png"

.payout-wrapper
  display: flex
  flex-direction: row
  justify-content: center
  margin-top: 200px
  position: absolute
  width: 650px
  
.payout
    background-color: rgba(45, 45, 45, 0.65)
    color: #d43545
    font-size: 40px
    font-style: italic
    border-radius: 15px
    padding: 10px 28px
  
.window-wrapper
  width: 100%
  padding: 0 10px
  display: flex
  flex-direction: column
  align-items: center
  form
    width: 83.333333%

.window
  background: #101924
  display: flex
  flex-direction: row
  justify-content: flex-start

  .reel
    display: flex
    flex-direction: column
    justify-content: flex-start
    margin: 5px

  .sprite
    width: 120px
    height: 120px

    &.W1
      background: url($sprites-url) no-repeat -55px -34px
    &.W2
      background: url($sprites-url) no-repeat -542px -34px
    &.W3
      background: url($sprites-url) no-repeat -180px -34px
    &.W4
      background: url($sprites-url) no-repeat -425px -34px
    &.W5
      background: url($sprites-url) no-repeat -302px -34px
    &.A
      background: url($sprites-url) no-repeat -55px -160px
    &.B
      background: url($sprites-url) no-repeat -185px -160px
    &.C
      background: url($sprites-url) no-repeat -305px -160px
    &.D
      background: url($sprites-url) no-repeat -425px -160px
    &.E
      background: url($sprites-url) no-repeat -542px -160px
    &.F
      background: url($sprites-url) no-repeat -302px -400px
    &.G
      background: url($sprites-url) no-repeat -182px -400px
    &.H
      background: url($sprites-url) no-repeat -60px -400px
    &.I
      background: url($sprites-url) no-repeat -182px -280px
    &.J
      background: url($sprites-url) no-repeat -60px -280px
    &.S
      background: url($sprites-url) no-repeat -302px -280px
 
@media only screen and (max-width: 768px)
  .window 
    transform: scale(0.75)
    margin-top: -10%
    
@media only screen and (max-width: 480px)
  .window 
    transform: scale(0.5)
    margin-top: -25%
   
    
              
            
!

JS

              
                const cloneDeep = _.cloneDeep;
const compact = _.compact;
const flatten = _.flatten;

const MAX_NUMBER = '115792089237316195423570985008687907853269984665640564039457584007913129639936'; // 2^256

BigNumber.config({ DECIMAL_PLACES: 10, ROUNDING_MODE: BigNumber.ROUND_DOWN });
const BigNumberRounded = BigNumber.clone({ DECIMAL_PLACES: 0, ROUNDING_MODE: BigNumber.ROUND_DOWN });

const query = new URLSearchParams(window.location.search);

const mainConfig = {
  'window': {
    'reels': {
      '1': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'S': { 'count': 1, 'probability': 1 },
          'W': { 'count': 5, 'probability': 1 }
        }
      },
      '2': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'S': { 'count': 1, 'probability': 2 },
          'W': { 'count': 5, 'probability': 1 }
        }
      },
      '3': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'S': { 'count': 1, 'probability': 1 },
          'W': { 'count': 5, 'probability': 1 }
        }
      },
      '4': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'S': { 'count': 1, 'probability': 2 },
          'W': { 'count': 5, 'probability': 1 }
        }
      },
      '5': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'S': { 'count': 1, 'probability': 1 },
          'W': { 'count': 5, 'probability': 1 }
        }
      }
    }
  },
  'payout': {
    'line': {
      'wild_symbol': 'W',
      'lines': {
        '1': { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1 },
        '2': { '1': 2, '2': 2, '3': 2, '4': 2, '5': 2 },
        '3': { '1': 3, '2': 3, '3': 3, '4': 3, '5': 3 },
        '4': { '1': 4, '2': 4, '3': 4, '4': 4, '5': 4 },
        '5': { '1': 4, '2': 3, '3': 2, '4': 3, '5': 4 },
        '6': { '1': 3, '2': 2, '3': 1, '4': 2, '5': 3 },
        '7': { '1': 1, '2': 2, '3': 3, '4': 2, '5': 1 },
        '8': { '1': 2, '2': 3, '3': 4, '4': 3, '5': 2 },
        '9': { '1': 4, '2': 3, '3': 4, '4': 3, '5': 4 },
        '10': { '1': 3, '2': 2, '3': 3, '4': 2, '5': 3 },
        '11': { '1': 2, '2': 1, '3': 2, '4': 1, '5': 2 },
        '12': { '1': 1, '2': 2, '3': 1, '4': 2, '5': 1 },
        '13': { '1': 2, '2': 3, '3': 2, '4': 3, '5': 2 },
        '14': { '1': 3, '2': 4, '3': 3, '4': 4, '5': 3 },
        '15': { '1': 2, '2': 2, '3': 1, '4': 2, '5': 2 },
        '16': { '1': 3, '2': 3, '3': 2, '4': 3, '5': 3 },
        '17': { '1': 4, '2': 4, '3': 3, '4': 4, '5': 4 },
        '18': { '1': 3, '2': 3, '3': 4, '4': 3, '5': 3 },
        '19': { '1': 2, '2': 2, '3': 3, '4': 2, '5': 2 },
        '20': { '1': 1, '2': 1, '3': 2, '4': 1, '5': 1 },
        '21': { '1': 4, '2': 4, '3': 1, '4': 4, '5': 4 },
        '22': { '1': 4, '2': 4, '3': 2, '4': 4, '5': 4 },
        '23': { '1': 3, '2': 3, '3': 1, '4': 3, '5': 3 },
        '24': { '1': 1, '2': 1, '3': 4, '4': 1, '5': 1 },
        '25': { '1': 1, '2': 1, '3': 3, '4': 1, '5': 1 },
        '26': { '1': 2, '2': 2, '3': 4, '4': 2, '5': 2 },
        '27': { '1': 4, '2': 2, '3': 4, '4': 2, '5': 4 },
        '28': { '1': 3, '2': 1, '3': 3, '4': 1, '5': 3 },
        '29': { '1': 1, '2': 3, '3': 1, '4': 3, '5': 1 },
        '30': { '1': 2, '2': 4, '3': 2, '4': 4, '5': 2 },
        '31': { '1': 1, '2': 2, '3': 2, '4': 2, '5': 1 },
        '32': { '1': 2, '2': 3, '3': 3, '4': 3, '5': 2 },
        '33': { '1': 3, '2': 4, '3': 4, '4': 4, '5': 3 },
        '34': { '1': 4, '2': 3, '3': 3, '4': 3, '5': 4 },
        '35': { '1': 3, '2': 2, '3': 2, '4': 2, '5': 3 },
        '36': { '1': 2, '2': 1, '3': 1, '4': 1, '5': 2 },
        '37': { '1': 4, '2': 1, '3': 4, '4': 1, '5': 4 },
        '38': { '1': 1, '2': 4, '3': 1, '4': 4, '5': 1 },
        '39': { '1': 4, '2': 1, '3': 1, '4': 1, '5': 4 },
        '40': { '1': 1, '2': 4, '3': 4, '4': 4, '5': 1 }
      },
      'payouts': {
        'A': { '3': '0.05', '4': '0.25', '5': '0.625' },
        'B': { '3': '0.05', '4': '0.25', '5': '1' },
        'C': { '3': '0.1', '4': '0.3', '5': '1.25' },
        'D': { '3': '0.125', '4': '0.375', '5': '1.875' },
        'E': { '3': '0.25', '4': '0.5', '5': '2.5' },
        'F': { '3': '0.25', '4': '1.25', '5': '5' },
        'G': { '3': '0.3', '4': '1.5', '5': '7.5' },
        'H': { '3': '0.375', '4': '1.875', '5': '10' },
        'I': { '3': '0.5', '4': '2', '5': '12.5' },
        'J': { '3': '0.5', '4': '3.125', '5': '25' },
        'W': { '3': '0.625', '4': '3.75', '5': '37.5' }
      }
    },
    'scatter': { 'symbol': 'S', 'payouts': { '2': '2', '3': '4', '4': '20', '5': '375' } }
  },
  'bonus': { 'symbol': 'S', 'min_count': 3, 'options': ['first-bonus', 'second-bonus', 'third-bonus'] }
}

const firstBonusConfig = {
  'config': {
    'spins_count': 10,
    'symbol': 'W',
    'multiplier': '1',
    'additional': {
      'spins': 1,
      'multiplier': '1'
    },
    'additional_once': {
      'wilds_count_threshold': 15,
      'spins': 5
    }
  },

  'window': {
    'reels': {
      '1': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.93' }
        }
      },
      '2': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.93064' }
        }
      },
      '3': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.93' }
        }
      },
      '4': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.94' }
        }
      },
      '5': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.93' }
        }
      }
    }
  },
  'payout': {
    'line': {
      'wild_symbol': 'W',
      'lines': {
        '1': { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1 },
        '2': { '1': 2, '2': 2, '3': 2, '4': 2, '5': 2 },
        '3': { '1': 3, '2': 3, '3': 3, '4': 3, '5': 3 },
        '4': { '1': 4, '2': 4, '3': 4, '4': 4, '5': 4 },
        '5': { '1': 4, '2': 3, '3': 2, '4': 3, '5': 4 },
        '6': { '1': 3, '2': 2, '3': 1, '4': 2, '5': 3 },
        '7': { '1': 1, '2': 2, '3': 3, '4': 2, '5': 1 },
        '8': { '1': 2, '2': 3, '3': 4, '4': 3, '5': 2 },
        '9': { '1': 4, '2': 3, '3': 4, '4': 3, '5': 4 },
        '10': { '1': 3, '2': 2, '3': 3, '4': 2, '5': 3 },
        '11': { '1': 2, '2': 1, '3': 2, '4': 1, '5': 2 },
        '12': { '1': 1, '2': 2, '3': 1, '4': 2, '5': 1 },
        '13': { '1': 2, '2': 3, '3': 2, '4': 3, '5': 2 },
        '14': { '1': 3, '2': 4, '3': 3, '4': 4, '5': 3 },
        '15': { '1': 2, '2': 2, '3': 1, '4': 2, '5': 2 },
        '16': { '1': 3, '2': 3, '3': 2, '4': 3, '5': 3 },
        '17': { '1': 4, '2': 4, '3': 3, '4': 4, '5': 4 },
        '18': { '1': 3, '2': 3, '3': 4, '4': 3, '5': 3 },
        '19': { '1': 2, '2': 2, '3': 3, '4': 2, '5': 2 },
        '20': { '1': 1, '2': 1, '3': 2, '4': 1, '5': 1 },
        '21': { '1': 4, '2': 4, '3': 1, '4': 4, '5': 4 },
        '22': { '1': 4, '2': 4, '3': 2, '4': 4, '5': 4 },
        '23': { '1': 3, '2': 3, '3': 1, '4': 3, '5': 3 },
        '24': { '1': 1, '2': 1, '3': 4, '4': 1, '5': 1 },
        '25': { '1': 1, '2': 1, '3': 3, '4': 1, '5': 1 },
        '26': { '1': 2, '2': 2, '3': 4, '4': 2, '5': 2 },
        '27': { '1': 4, '2': 2, '3': 4, '4': 2, '5': 4 },
        '28': { '1': 3, '2': 1, '3': 3, '4': 1, '5': 3 },
        '29': { '1': 1, '2': 3, '3': 1, '4': 3, '5': 1 },
        '30': { '1': 2, '2': 4, '3': 2, '4': 4, '5': 2 },
        '31': { '1': 1, '2': 2, '3': 2, '4': 2, '5': 1 },
        '32': { '1': 2, '2': 3, '3': 3, '4': 3, '5': 2 },
        '33': { '1': 3, '2': 4, '3': 4, '4': 4, '5': 3 },
        '34': { '1': 4, '2': 3, '3': 3, '4': 3, '5': 4 },
        '35': { '1': 3, '2': 2, '3': 2, '4': 2, '5': 3 },
        '36': { '1': 2, '2': 1, '3': 1, '4': 1, '5': 2 },
        '37': { '1': 4, '2': 1, '3': 4, '4': 1, '5': 4 },
        '38': { '1': 1, '2': 4, '3': 1, '4': 4, '5': 1 },
        '39': { '1': 4, '2': 1, '3': 1, '4': 1, '5': 4 },
        '40': { '1': 1, '2': 4, '3': 4, '4': 4, '5': 1 }
      },
      'payouts': {
        'A': { '5': '0.625', '4': '0.25', '3': '0.05' },
        'B': { '5': '1', '4': '0.25', '3': '0.05' },
        'C': { '5': '1.25', '4': '0.3', '3': '0.1' },
        'D': { '5': '1.875', '4': '0.375', '3': '0.125' },
        'E': { '5': '2.5', '4': '0.5', '3': '0.25' },
        'F': { '5': '5', '4': '1.25', '3': '0.25' },
        'G': { '5': '7.5', '4': '1.5', '3': '0.3' },
        'H': { '5': '10', '4': '1.875', '3': '0.375' },
        'I': { '5': '12.5', '4': '2', '3': '0.5' },
        'J': { '5': '25', '4': '3.125', '3': '0.5' },
        'W': { '5': '37.5', '4': '3.75', '3': '0.625' }
      }
    },
    'scatter': { 'symbol': 'S', 'payouts': { '5': '62.5', '4': '6.25', '3': '1.875', '2': '0.05' } }
  }
}

const secondBonusConfig = {
  'config': {
    'spins_count': 10,
    'lock': {
      'symbol': 'W'
    },
    'multiplier': '2',
    'additional_once': {
      'spins': 5
    }
  },

  'window': {
    'reels': {
      '1': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.76' }
        }
      },
      '2': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.76458' }
        }
      },
      '3': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.76' }
        }
      },
      '4': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.76' }
        }
      },
      '5': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.76' }
        }
      }
    }
  },
  'payout': {
    'line': {
      'wild_symbol': 'W',
      'lines': {
        '1': { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1 },
        '2': { '1': 2, '2': 2, '3': 2, '4': 2, '5': 2 },
        '3': { '1': 3, '2': 3, '3': 3, '4': 3, '5': 3 },
        '4': { '1': 4, '2': 4, '3': 4, '4': 4, '5': 4 },
        '5': { '1': 4, '2': 3, '3': 2, '4': 3, '5': 4 },
        '6': { '1': 3, '2': 2, '3': 1, '4': 2, '5': 3 },
        '7': { '1': 1, '2': 2, '3': 3, '4': 2, '5': 1 },
        '8': { '1': 2, '2': 3, '3': 4, '4': 3, '5': 2 },
        '9': { '1': 4, '2': 3, '3': 4, '4': 3, '5': 4 },
        '10': { '1': 3, '2': 2, '3': 3, '4': 2, '5': 3 },
        '11': { '1': 2, '2': 1, '3': 2, '4': 1, '5': 2 },
        '12': { '1': 1, '2': 2, '3': 1, '4': 2, '5': 1 },
        '13': { '1': 2, '2': 3, '3': 2, '4': 3, '5': 2 },
        '14': { '1': 3, '2': 4, '3': 3, '4': 4, '5': 3 },
        '15': { '1': 2, '2': 2, '3': 1, '4': 2, '5': 2 },
        '16': { '1': 3, '2': 3, '3': 2, '4': 3, '5': 3 },
        '17': { '1': 4, '2': 4, '3': 3, '4': 4, '5': 4 },
        '18': { '1': 3, '2': 3, '3': 4, '4': 3, '5': 3 },
        '19': { '1': 2, '2': 2, '3': 3, '4': 2, '5': 2 },
        '20': { '1': 1, '2': 1, '3': 2, '4': 1, '5': 1 },
        '21': { '1': 4, '2': 4, '3': 1, '4': 4, '5': 4 },
        '22': { '1': 4, '2': 4, '3': 2, '4': 4, '5': 4 },
        '23': { '1': 3, '2': 3, '3': 1, '4': 3, '5': 3 },
        '24': { '1': 1, '2': 1, '3': 4, '4': 1, '5': 1 },
        '25': { '1': 1, '2': 1, '3': 3, '4': 1, '5': 1 },
        '26': { '1': 2, '2': 2, '3': 4, '4': 2, '5': 2 },
        '27': { '1': 4, '2': 2, '3': 4, '4': 2, '5': 4 },
        '28': { '1': 3, '2': 1, '3': 3, '4': 1, '5': 3 },
        '29': { '1': 1, '2': 3, '3': 1, '4': 3, '5': 1 },
        '30': { '1': 2, '2': 4, '3': 2, '4': 4, '5': 2 },
        '31': { '1': 1, '2': 2, '3': 2, '4': 2, '5': 1 },
        '32': { '1': 2, '2': 3, '3': 3, '4': 3, '5': 2 },
        '33': { '1': 3, '2': 4, '3': 4, '4': 4, '5': 3 },
        '34': { '1': 4, '2': 3, '3': 3, '4': 3, '5': 4 },
        '35': { '1': 3, '2': 2, '3': 2, '4': 2, '5': 3 },
        '36': { '1': 2, '2': 1, '3': 1, '4': 1, '5': 2 },
        '37': { '1': 4, '2': 1, '3': 4, '4': 1, '5': 4 },
        '38': { '1': 1, '2': 4, '3': 1, '4': 4, '5': 1 },
        '39': { '1': 4, '2': 1, '3': 1, '4': 1, '5': 4 },
        '40': { '1': 1, '2': 4, '3': 4, '4': 4, '5': 1 }
      },
      'payouts': {
        'A': { '5': '0.625', '4': '0.25', '3': '0.05' },
        'B': { '5': '1', '4': '0.25', '3': '0.05' },
        'C': { '5': '1.25', '4': '0.3', '3': '0.1' },
        'D': { '5': '1.875', '4': '0.375', '3': '0.125' },
        'E': { '5': '2.5', '4': '0.5', '3': '0.25' },
        'F': { '5': '5', '4': '1.25', '3': '0.25' },
        'G': { '5': '7.5', '4': '1.5', '3': '0.3' },
        'H': { '5': '10', '4': '1.875', '3': '0.375' },
        'I': { '5': '12.5', '4': '2', '3': '0.5' },
        'J': { '5': '25', '4': '3.125', '3': '0.5' },
        'W': { '5': '37.5', '4': '3.75', '3': '0.625' }
      }
    },
    'scatter': { 'symbol': 'S', 'payouts': { '5': '62.5', '4': '6.25', '3': '1.875', '2': '0.05' } }
  }
}

const thirdBonusConfig = {
  'config': {
    'spins_count': 10,
    'lock': {
      'symbol': 'W'
    },
    'multiplier': '1'
  },

  'window': {
    'reels': {
      '1': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.77' }
        }
      },
      '2': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.78' }
        }
      },
      '3': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.77' }
        }
      },
      '4': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.78' }
        }
      },
      '5': {
        'visible_slots': 4,
        'symbols': {
          'A': { 'count': 8, 'probability': 1 },
          'B': { 'count': 8, 'probability': 1 },
          'C': { 'count': 8, 'probability': 1 },
          'D': { 'count': 8, 'probability': 1 },
          'E': { 'count': 8, 'probability': 1 },
          'F': { 'count': 6, 'probability': 1 },
          'G': { 'count': 6, 'probability': 1 },
          'H': { 'count': 6, 'probability': 1 },
          'I': { 'count': 5, 'probability': 1 },
          'J': { 'count': 5, 'probability': 1 },
          'W': { 'count': 2, 'probability': '0.77' }
        }
      }
    }
  },
  'payout': {
    'line': {
      'wild_symbol': 'W',
      'lines': {
        '1': { '1': 1, '2': 1, '3': 1, '4': 1, '5': 1 },
        '2': { '1': 2, '2': 2, '3': 2, '4': 2, '5': 2 },
        '3': { '1': 3, '2': 3, '3': 3, '4': 3, '5': 3 },
        '4': { '1': 4, '2': 4, '3': 4, '4': 4, '5': 4 },
        '5': { '1': 4, '2': 3, '3': 2, '4': 3, '5': 4 },
        '6': { '1': 3, '2': 2, '3': 1, '4': 2, '5': 3 },
        '7': { '1': 1, '2': 2, '3': 3, '4': 2, '5': 1 },
        '8': { '1': 2, '2': 3, '3': 4, '4': 3, '5': 2 },
        '9': { '1': 4, '2': 3, '3': 4, '4': 3, '5': 4 },
        '10': { '1': 3, '2': 2, '3': 3, '4': 2, '5': 3 },
        '11': { '1': 2, '2': 1, '3': 2, '4': 1, '5': 2 },
        '12': { '1': 1, '2': 2, '3': 1, '4': 2, '5': 1 },
        '13': { '1': 2, '2': 3, '3': 2, '4': 3, '5': 2 },
        '14': { '1': 3, '2': 4, '3': 3, '4': 4, '5': 3 },
        '15': { '1': 2, '2': 2, '3': 1, '4': 2, '5': 2 },
        '16': { '1': 3, '2': 3, '3': 2, '4': 3, '5': 3 },
        '17': { '1': 4, '2': 4, '3': 3, '4': 4, '5': 4 },
        '18': { '1': 3, '2': 3, '3': 4, '4': 3, '5': 3 },
        '19': { '1': 2, '2': 2, '3': 3, '4': 2, '5': 2 },
        '20': { '1': 1, '2': 1, '3': 2, '4': 1, '5': 1 },
        '21': { '1': 4, '2': 4, '3': 1, '4': 4, '5': 4 },
        '22': { '1': 4, '2': 4, '3': 2, '4': 4, '5': 4 },
        '23': { '1': 3, '2': 3, '3': 1, '4': 3, '5': 3 },
        '24': { '1': 1, '2': 1, '3': 4, '4': 1, '5': 1 },
        '25': { '1': 1, '2': 1, '3': 3, '4': 1, '5': 1 },
        '26': { '1': 2, '2': 2, '3': 4, '4': 2, '5': 2 },
        '27': { '1': 4, '2': 2, '3': 4, '4': 2, '5': 4 },
        '28': { '1': 3, '2': 1, '3': 3, '4': 1, '5': 3 },
        '29': { '1': 1, '2': 3, '3': 1, '4': 3, '5': 1 },
        '30': { '1': 2, '2': 4, '3': 2, '4': 4, '5': 2 },
        '31': { '1': 1, '2': 2, '3': 2, '4': 2, '5': 1 },
        '32': { '1': 2, '2': 3, '3': 3, '4': 3, '5': 2 },
        '33': { '1': 3, '2': 4, '3': 4, '4': 4, '5': 3 },
        '34': { '1': 4, '2': 3, '3': 3, '4': 3, '5': 4 },
        '35': { '1': 3, '2': 2, '3': 2, '4': 2, '5': 3 },
        '36': { '1': 2, '2': 1, '3': 1, '4': 1, '5': 2 },
        '37': { '1': 4, '2': 1, '3': 4, '4': 1, '5': 4 },
        '38': { '1': 1, '2': 4, '3': 1, '4': 4, '5': 1 },
        '39': { '1': 4, '2': 1, '3': 1, '4': 1, '5': 4 },
        '40': { '1': 1, '2': 4, '3': 4, '4': 4, '5': 1 }
      },
      'payouts': {
        'A': { '5': '0.625', '4': '0.25', '3': '0.05' },
        'B': { '5': '1', '4': '0.25', '3': '0.05' },
        'C': { '5': '1.25', '4': '0.3', '3': '0.1' },
        'D': { '5': '1.875', '4': '0.375', '3': '0.125' },
        'E': { '5': '2.5', '4': '0.5', '3': '0.25' },
        'F': { '5': '5', '4': '1.25', '3': '0.25' },
        'G': { '5': '7.5', '4': '1.5', '3': '0.3' },
        'H': { '5': '10', '4': '1.875', '3': '0.375' },
        'I': { '5': '12.5', '4': '2', '3': '0.5' },
        'J': { '5': '25', '4': '3.125', '3': '0.5' },
        'W': { '5': '37.5', '4': '3.75', '3': '0.625' }
      }
    },
    'scatter': { 'symbol': 'S', 'payouts': { '5': '62.5', '4': '6.25', '3': '1.875', '2': '0.05' } }
  }
}

const REASON_SPINS_LIMIT = 'spins_limit'

class PermutationWindowStrategy {
  constructor(config) {
    config = cloneDeep(config)
    this.startMin = new BigNumber(0)
    this.startMax = new BigNumber(MAX_NUMBER)

    const reelsKeys = Object.keys(config.reels)
    this.reels = reelsKeys.reduce((accumulator, key) => {
      const reel = cloneDeep(config.reels[key])
      const symbolCharCodes = Object.keys(reel.symbols)
      const probabilityBySymbol = symbolCharCodes.reduce((accumulator, symbolCharCode) => {
        const symbol = reel.symbols[symbolCharCode]
        symbol.probabilityGMP = new BigNumber('1000000').multipliedBy(symbol.probability).toFixed(0)
        accumulator[symbolCharCode] = new BigNumberRounded(symbol.probabilityGMP).multipliedBy(symbol.count).toFixed()
        reel.symbols[symbolCharCode] = symbol

        return accumulator
      }, {})

      reel.probability_by_symbol = probabilityBySymbol
      reel.total_probability = symbolCharCodes.reduce((accumulator, symbolCharCode) => {
        const probability = probabilityBySymbol[symbolCharCode]
        return accumulator.plus(probability)
      }, new BigNumberRounded(0)).toFixed()

      accumulator[key] = reel
      return accumulator
    }, {})
  }

  getWindow(number) {
    const slotWindow = []
    let min = this.startMin
    let max = this.startMax
    let slots = []

    const reels = Object.keys(this.reels)
    reels.forEach((key) => {
      const reel = cloneDeep(this.reels[key]);
      [min, max, slots] = this.numberToReel(reel.symbols, reel.probability_by_symbol, reel.total_probability, reel.visible_slots, min, max, number)
      slotWindow[key] = slots
    })

    return compact(slotWindow)
  }

  numberToReel(symbols, probabilityBySymbol, totalProbability, slotsCount, min, max, number) {
    symbols = ksort(symbols)
    let reel = []
    let symbol
    let i = 0
    while (i++ < slotsCount) {
      [min, max, symbol] = this.numberToValue(probabilityBySymbol, totalProbability, min, max, number)
      reel[i] = symbol
      
      probabilityBySymbol[symbol] = new BigNumberRounded(probabilityBySymbol[symbol]).minus(symbols[symbol].probabilityGMP)
      totalProbability = new BigNumberRounded(totalProbability).minus(symbols[symbol].probabilityGMP)

      if (symbols[symbol].count === 1) {
        delete symbols[symbol]
      } else {
        symbols[symbol].count--
      }
    }

    reel = compact(reel)

    return this.randomizeReel(reel, min, max, number)
  }

  randomizeReel(symbols, min, max, number) {
    const reel = []
    let position

    const count = symbols.length
    const probabilityByPosition = new Array(count)
    probabilityByPosition.fill('1', 0, count)
    let reelsLeft = new BigNumber(count)

    for (let i = 0; i < count - 1; i++) {
      [min, max, position] = this.numberToValue(probabilityByPosition, reelsLeft, min, max, number)
      reelsLeft--
      reel[position] = symbols[i]
      delete probabilityByPosition[position]
    }
    const probabilityPositionIndex = probabilityByPosition.findIndex((probability) => probability !== undefined)
    reel[probabilityPositionIndex] = symbols[count - 1]

    return [min, max, reel]
  }

  numberToValue(probabilityByValue, totalProbability, min, max, number) {
    if (new BigNumberRounded(number).isLessThan(min) || new BigNumberRounded(number).isGreaterThan(max) || (Object.keys(probabilityByValue).length === 0)) {
      throw new Error('Number generation failed.')
    }

    let lastValue
    let newMin = min
    let newMax = min

    const rangeLength = new BigNumberRounded(max).minus(min)
    const step = new BigNumberRounded(rangeLength).dividedBy(totalProbability)

    for (const value in probabilityByValue) {
      const probability = probabilityByValue[value]
      newMax = new BigNumberRounded(newMax).plus(new BigNumberRounded(step).multipliedBy(probability))

      lastValue = value
      if (new BigNumberRounded(number).isLessThan(newMax)) {
        return [newMin, newMax, value]
      }

      newMin = newMax
    }

    return [newMin, newMax, lastValue]
  }
}

class LeftmostPayoutStrategy {
  constructor(config) {
    this.config = config
  }

  getPayouts(window) {
    return {
      line: this.getLinePayouts(window),
      scatter: this.getScatterPayouts(window)
    }
  }

  getLinePayouts(window) {
    const payouts = {}
    const lines = this.config.line.lines
    for (const index in lines) {
      const line = lines[index]
      const symbols = this.getSymbolsForLine(window, line)
      const payout = this.getPayoutForLine(symbols)
      if (payout) {
        payout.line = line
        payouts[index] = payout
      }
    }

    return payouts
  }

  getScatterPayouts(window) {
    const scatterSymbol = this.config.scatter.symbol || null
    if (!scatterSymbol) {
      return []
    }

    let payouts = []
    const count = flatten(window).filter((symbol) => symbol === 'S').length
    const payout = this.config.scatter.payouts[count] || null
    if (payout) {
      payouts.push({
        'symbol': scatterSymbol,
        'count': count,
        'payout': payout
      })
    }

    return payouts
  }

  getSymbolsForLine(window, line) {
    const symbols = []
    for (const column in line) {
      const row = line[column]
      symbols.push(window[column - 1][row - 1])
    }

    return compact(symbols)
  }

  getPayoutForLine(symbols) {
    const wild = 'W';
    let biggestPayout = null;
    let lastSymbol = null;
    let count = 0;
    for (const index in symbols) {
      const symbol = symbols[index];
      count++;

      if (!lastSymbol) {
        lastSymbol = symbol;
      } else if (lastSymbol === wild) {
        lastSymbol = symbol;
      } else if (symbol !== lastSymbol && symbol !== wild) {
        break;
      }

      let payout = this.config.line.payouts[lastSymbol] && this.config.line.payouts[lastSymbol][count];
      if (payout) {
        if (!biggestPayout || (parseFloat(payout) > parseFloat(biggestPayout.payout))) {
          biggestPayout = {
            symbol: lastSymbol,
            count: count,
            payout: payout,
          }
        }
      }
    }

    return biggestPayout;
  }
}

class BaseBonusManager {
  static STATE_KEY_SPINS_COUNT = 'spins_count'
  static STATE_KEY_CURRENT_SPIN_NUMBER = 'current_spin_number'

  constructor() {
    this.config = null
    this.payoutStrategy = null
    this.windowStrategy = null
  }

  getConfig() {
    return this.config
  }

  runBonus(serverSeed, clientSeed, nonce) {
    const config = this.getConfig()

    if (typeof nonce === 'string') {
      nonce = parseInt(nonce)
    }

    const spins = []

    let state = this.getInitialState(config)

    const bonus = { totalPayout: new BigNumber(0) }

    while (!this.getStopReason(state)) {
      const number = this.getNumber(serverSeed, clientSeed, nonce)
      const slotWindow = this.getWindow(number)
      const statefulWindow = this.getStatefulWindow(slotWindow, state)
      const newState = this.getNewState(statefulWindow, state)
      const payouts = this.getPayouts(statefulWindow)
      const statefulPayouts = this.getStatefulPayouts(payouts, newState)

      const bonusSpin = {}
      bonusSpin.nonce = nonce
      bonusSpin.state = state // previous state
      bonusSpin.new_state = newState
      bonusSpin.window = slotWindow
      bonusSpin.stateful_window = statefulWindow
      bonusSpin.payouts = payouts
      bonusSpin.stateful_payouts = statefulPayouts
      let totalPayout = new BigNumber(0)
      for (const lineIndex in statefulPayouts.line) {
        const line = statefulPayouts.line[lineIndex]
        totalPayout = totalPayout.plus(line.payout)
      }
      bonusSpin.payout = totalPayout.toString()
      spins.push(bonusSpin)

      state = newState
      nonce++
      bonus.totalPayout = bonus.totalPayout.plus(bonusSpin.payout)
    }

    bonus.finishNonce = nonce
    bonus.spins = spins
    bonus.totalPayout = bonus.totalPayout.toString()

    return bonus
  }

  getWindowStrategy() {
    if (!this.windowStrategy) {
      this.windowStrategy = new PermutationWindowStrategy(this.getConfig().window || [])
    }

    return this.windowStrategy
  }

  getPayoutStrategy() {
    if (!this.payoutStrategy) {
      this.payoutStrategy = new LeftmostPayoutStrategy(this.getConfig().payout || [])
    }

    return this.payoutStrategy
  }

  getWindow(number) {
    return this.getWindowStrategy().getWindow(number)
  }

  getPayouts(statefulWindow) {
    return this.getPayoutStrategy().getPayouts(statefulWindow)
  }

  getInitialState() {
    return { [BaseBonusManager.STATE_KEY_CURRENT_SPIN_NUMBER]: 0 }
  }

  getNewState(mergedWindow, state) {
    const newState = cloneDeep(state)

    newState[BaseBonusManager.STATE_KEY_SPINS_COUNT] -= 1
    newState[BaseBonusManager.STATE_KEY_CURRENT_SPIN_NUMBER] += 1

    return newState
  }

  getStopReason(state) {
    const spinsCount = state[BaseBonusManager.STATE_KEY_SPINS_COUNT] || 0
    if (spinsCount <= 0) {
      return REASON_SPINS_LIMIT
    }

    return null
  }

  getNumber(serverSeed, clientSeed, nonce) {
    return generate(serverSeed, clientSeed, nonce)
  }
}

class FirstBonusManager extends BaseBonusManager {
  constructor() {
    super()

    this.config = cloneDeep(firstBonusConfig)
    this.name = 'First Bonus'
  }

  getInitialState (config) {
    const baseInitialState = super.getInitialState(config)
    baseInitialState.wilds_count = 0

    return { ...baseInitialState, spins_count: config.config.spins_count, multiplier: config.config.multiplier }
  }

  getStatefulWindow(window, state) {
    return cloneDeep(window)
  }

  getStatefulPayouts(payouts, newState) {
    const minMultiplier = '1'
    const multiplier = new BigNumber(newState.multiplier || minMultiplier)

    if (multiplier.isGreaterThan(minMultiplier)) {
      for (const payoutIndex in payouts.line) {
        const linePayout = payouts.line[payoutIndex]
        const newPayout = new BigNumber(linePayout.payout)
          .multipliedBy(multiplier)
          .toNumber()

        payouts.line[payoutIndex].payout = newPayout
      }
    }

    return payouts
  }

  getNewState(mergedWindow, state) {
    const newState = super.getNewState.call(this, mergedWindow, state)
    const config = this.getConfig().config

    let bonusSymbolsCount = 0
    for (const reelIndex in mergedWindow) {
      const symbols = mergedWindow[reelIndex]
      for (const rowIndex in symbols) {
        const symbol = symbols[rowIndex]
        if (this.isBonusSymbol(symbol)) {
          bonusSymbolsCount++
        }
      }
    }

    if (bonusSymbolsCount > 0) {
      newState.multiplier = new BigNumber(config.additional.multiplier)
        .multipliedBy(bonusSymbolsCount)
        .plus(newState.multiplier)
        .toNumber()
      newState.spins_count = newState.spins_count + bonusSymbolsCount
      newState.wilds_count = newState.wilds_count + bonusSymbolsCount
    }

    const additionalOnceReceived = newState.additional_once || false
    if (!additionalOnceReceived && newState.wilds_count >= config.additional_once.wilds_count_threshold) {
      newState.spins_count = newState.spins_count + config.additional_once.spins
      newState.additional_once = true
    }

    return newState
  }

  isBonusSymbol(symbol) {
    return symbol === this.getConfig().config.symbol
  }
}

class SecondBonusManager extends BaseBonusManager {
  constructor() {
    super()

    this.config = secondBonusConfig
    this.name = 'Second Bonus'
  }

  getInitialState (config) {
    const baseInitialState = super.getInitialState(config)

    return { ...baseInitialState, spins_count: config.config.spins_count }
  }

  getStatefulWindow(window, state) {
    const reels = cloneDeep(window)

    for (const reelIndex in reels) {
      const reel = reels[reelIndex]
      for (const rowIndex in reel) {
        const symbol = reel[rowIndex]
        if (state && !state.locked) {
          state.locked = {}
        }
        if (!state.locked[reelIndex]) {
          state.locked[reelIndex] = {}
        }
        const lockedSymbol = state.locked[reelIndex][rowIndex] || null
        if (lockedSymbol) {
          reels[reelIndex][rowIndex] = lockedSymbol
        } else if (this.shouldLock(symbol)) {
          state.locked[reelIndex][rowIndex] = symbol
        }
      }
    }

    return reels
  }

  getStatefulPayouts(payouts, newState) {
    const config = this.getConfig().config

    for (const payoutIndex in payouts.line) {
      const linePayout = payouts.line[payoutIndex]
      const newPayout = new BigNumber(linePayout.payout)
        .multipliedBy(config.multiplier)
        .toNumber()
      payouts.line[payoutIndex].payout = newPayout
    }

    return payouts
  }

  getNewState(statefulWindow, state) {
    const newState = super.getNewState.call(this, statefulWindow, state)
    const config = this.getConfig().config

    for (const reelIndex in statefulWindow) {
      const symbols = statefulWindow[reelIndex]
      for (const rowIndex in symbols) {
        const symbol = symbols[rowIndex]
        if (this.shouldLock(symbol)) {
          if (!newState.locked[reelIndex]) {
            newState.locked[reelIndex] = {}
          }
          if (!newState.locked[reelIndex][rowIndex]) {
            newState.locked[reelIndex][rowIndex] = { symbol }
          }
        }
      }
    }

    const additionalOnceReceived = newState.additional_once || false
    const lockedReelsCount = (newState.locked || []).length
    const reelsCount = statefulWindow.length
    if (!additionalOnceReceived && lockedReelsCount === reelsCount) {
      newState.spins_count = newState.spins_count + config.additional_once.spins
      newState.additional_once = true
    }

    return newState
  }

  shouldLock(symbol) {
    return symbol === this.getConfig().config.lock.symbol
  }
}

class ThirdBonusManager extends BaseBonusManager {
  constructor() {
    super()

    this.config = thirdBonusConfig
    this.name = 'Third Bonus'
  }

  getInitialState (config) {
    const baseInitialState = super.getInitialState(config)

    return { ...baseInitialState, spins_count: config.config.spins_count }
  }

  getStatefulWindow(window, state) {
    const reels = cloneDeep(window)

    if (state && !state.locked) {
      state.locked = {}
    }

    for (const reelIndex in reels) {
      const reel = reels[reelIndex]
      for (const rowIndex in reel) {
        const symbol = reel[rowIndex]
        if (!state.locked[reelIndex]) {
          state.locked[reelIndex] = {}
        }
        const lockedSymbol = (state.locked[reelIndex][rowIndex] && state.locked[reelIndex][rowIndex].symbol) || null
        if (lockedSymbol) {
          reels[reelIndex][rowIndex] = lockedSymbol
        } else if (this.shouldLock(symbol)) {
          state.locked[reelIndex][rowIndex] = symbol
        }
      }
    }

    return reels
  }

  getStatefulPayouts(payouts, newState) {
    payouts = cloneDeep(payouts)
    for (const payoutIndex in payouts.line) {
      const linePayout = payouts.line[payoutIndex]
      let newPayout = new BigNumber(linePayout.payout)
      let position = 1

      for (const reelIndex in linePayout.line) {
        const rowIndex = linePayout.line[reelIndex]

        if (position > linePayout.count) {
          break
        }

        const lock = (newState.locked && newState.locked[reelIndex - 1] && newState.locked[reelIndex - 1][rowIndex - 1]) || null
        if (lock) {
          newPayout = newPayout.multipliedBy(lock.x || 1)
        }

        position++
      }

      payouts.line[payoutIndex].payout = newPayout.toNumber()
    }

    return payouts
  }

  getNewState(statefulWindow, state) {
    const newState = super.getNewState.call(this, statefulWindow, state)

    for (const reelIndex in statefulWindow) {
      const symbols = statefulWindow[reelIndex]
      for (const rowIndex in symbols) {
        const symbol = symbols[rowIndex]
        if (this.shouldLock(symbol)) {
          if (newState && !newState.locked) {
            newState.locked = {}
          }
          if (!newState.locked[reelIndex]) {
            newState.locked[reelIndex] = {}
          }
          if (!newState.locked[reelIndex][rowIndex]) {
            newState.locked[reelIndex][rowIndex] = {}
          }
          newState.locked[reelIndex][rowIndex] = {}
          newState.locked[reelIndex][rowIndex].symbol = symbol
        }
      }
    }

    newState.locked = newState.locked || {}

    for (const reelIndex in newState.locked) {
      const lockedRows = newState.locked[reelIndex]
      const lockedRowsCount = Object.keys(lockedRows).length
      for (const rowIndex in lockedRows) {
        newState.locked[reelIndex][rowIndex].x = lockedRowsCount
      }
    }

    return newState
  }

  shouldLock(symbol) {
    return symbol === this.getConfig().config.lock.symbol
  }
}

function SvgPathGenerator(path) {
    if (!(this instanceof SvgPathGenerator)) {
        return new SvgPathGenerator(path);
    }

    this.currentPath = (path || '') + ' ';
    this.isRelative = false;
}

SvgPathGenerator.prototype.toString = function() {
    return this.end();
};

SvgPathGenerator.prototype.moveTo = function() {
    this._appendData('M', arguments);
    return this;
};

SvgPathGenerator.prototype.close = SvgPathGenerator.prototype.closePath = function() {
    this._appendData('Z', []);
    return this;
};

SvgPathGenerator.prototype.lineTo = function() {
    this._appendData('L', arguments);
    return this;
};

SvgPathGenerator.prototype.horizontalLineTo = function(x) {
    this._appendData('H', [x]);
    return this;
};

SvgPathGenerator.prototype.verticalLineTo = function(y) {
    this._appendData('V', [y]);
    return this;
};

SvgPathGenerator.prototype.curveTo = function() {
    this._appendData('C', arguments);
    return this;
};

SvgPathGenerator.prototype.smoothCurveTo = function() {
    this._appendData('S', arguments);
    return this;
};

SvgPathGenerator.prototype.bezierCurveTo = function() {
    this._appendData('Q', arguments);
    return this;
};

SvgPathGenerator.prototype.smoothBezierCurveTo = function() {
    this._appendData('T', arguments);
    return this;
};

SvgPathGenerator.prototype.ellipticalArc = function() {
    this._appendData('A', arguments);
    return this;
};


SvgPathGenerator.prototype.relative = function() {
    this.isRelative = true;
    return this;
};

SvgPathGenerator.prototype.end = function() {
    return this.currentPath.trim();
};


SvgPathGenerator.prototype._appendData = function(symbol, args) {
    args = Array.prototype.slice.call(args);

    if(this.isRelative) {
        symbol = symbol.toLowerCase();
        this.isRelative = false;
    }

    this.currentPath += symbol + ' ' + args.join(' ') + ' ';
};

const Reel = ({ position, symbols }) => {
  const slots = symbols.map((symbol) => {
    symbol = symbol === 'W' ? `W${position}` : symbol
    return <div className={`sprite ${symbol}`} />
  })
  return <div className="reel">{slots}</div>
}

const App = () => {
  const onPreviousSpin = React.useCallback(() => {
    setBonusSpinIndex((index) => {
      return index - 1;
    });
  });
  const onNextSpin = React.useCallback(() => {
     setBonusSpinIndex((index) => {
      return index + 1;
    });
  });
  
  const [serverSeed, setServerSeed] = React.useState(query.get("serverSeed") || "");
  const serverSeedChanged = React.useCallback(e => setServerSeed(e.target.value), [
    setServerSeed
  ]);
  
  const [clientSeed, setClientSeed] = React.useState(query.get("clientSeed") || "");
  const clientSeedChanged = React.useCallback(e => setClientSeed(e.target.value), [
    setClientSeed
  ]);

  const [nonce, setNonce] = React.useState(query.get("nonce") || '0');
  const nonceChanged = React.useCallback(e => setNonce(e.target.value), [
    setNonce
  ]);
  
  const [bonus, setBonus] = React.useState(query.get("bonus") || "");
  
  const [bonusServerSeed, setBonusServerSeed] = React.useState(query.get("bonusServerSeed") || "");
  const bonusServerSeedChanged = React.useCallback(e => {
    setBonusSpinIndex(0);
    setBonusServerSeed(e.target.value);
  }, [setBonusServerSeed]);
  
  const [bonusClientSeed, setBonusClientSeed] = React.useState(query.get("bonusClientSeed") || "");
  const bonusClientSeedChanged = React.useCallback(e => { 
    setBonusSpinIndex(0);
    setBonusClientSeed(e.target.value) 
  }, [setBonusClientSeed]);
  
  const [bonusNonce, setBonusNonce] = React.useState(query.get("bonusNonce") || '0');
  const bonusNonceChanged = React.useCallback(e => {
    setBonusSpinIndex(0);
    setBonusNonce(e.target.value)
  }, [setBonusNonce]);
  
  const [bonusSpinIndex, setBonusSpinIndex] = React.useState(0);
  
  function isValidInputData (serverSeed, clientSeed, nonce, strictNonce = true) {
    return typeof serverSeed === 'string' && typeof clientSeed === 'string' && typeof nonce === 'string' && serverSeed.length > 0 && clientSeed.length > 0 && (!strictNonce || nonce.length > 0);
  }

  let bonusManager = null;
  let bonusResult = null;
  let slotWindow = null;
  let linePayouts = null;
  let bonusSlotWindow = null;
  let bonusLinePayouts = null;
  let bonusPayout = null;

  let totalPayout = new BigNumber(0);
  let bonusSpinPayout = new BigNumber(0);
  if (isValidInputData(serverSeed, clientSeed, nonce)) {
    const number = generate(serverSeed, clientSeed, nonce);
    const windowStrategy = new PermutationWindowStrategy(mainConfig.window);
    const payoutStrategy = new LeftmostPayoutStrategy(mainConfig.payout);
    slotWindow = windowStrategy.getWindow(number);
    const payouts = payoutStrategy.getPayouts(slotWindow);
    linePayouts = payouts.line;
    if (payouts.scatter.length) {
      totalPayout = totalPayout.plus(new BigNumber(payouts.scatter[0].payout));
    }
    for (const line in linePayouts) {
      totalPayout = totalPayout.plus(new BigNumber(linePayouts[line].payout));
    }
  }
  
  if (isValidInputData(bonusServerSeed, bonusClientSeed, bonusNonce, false)) {
    if (bonus === 'first-bonus') {
      bonusManager = new FirstBonusManager();
    } else if (bonus === 'second-bonus') {
      bonusManager = new SecondBonusManager();
    } else if (bonus === 'third-bonus') {
      bonusManager = new ThirdBonusManager();
    }

    if (bonusManager) {
      bonusResult = bonusManager.runBonus(bonusServerSeed, bonusClientSeed, bonusNonce);
      // totalPayout = new BigNumber(bonusResult.totalPayout);
      
      const bonusSpin = bonusResult.spins[bonusSpinIndex > 0 ? bonusSpinIndex : 0]
      bonusSpinPayout = new BigNumber(bonusSpin.payout);
      bonusSlotWindow = bonusSpin.stateful_window || bonusSpin.window;
      bonusLinePayouts = bonusSpin.stateful_payouts.line;
      bonusPayout = bonusSpinPayout.toFixed();
    }
  }
  
  const payout = totalPayout.toFixed();

  return (
    <div className="window-wrapper">
      <h1>Tower.BET Slots Bet Verifier</h1>
      <br/>
      
      <React.Fragment>
        <h3>Bet</h3>
        <form>
          <div className="form-group">
            <label htmlFor="hash">Server Seed</label>
            <input
              className="form-control"
              type="text"
              id="server-seed"
              placeholder="Server Seed"
              value={serverSeed}
              onChange={serverSeedChanged}
            />
          </div>
          <div className="form-group">
            <label htmlFor="hash">Client Seed</label>
            <input
              className="form-control"
              type="text"
              id="client-seed"
              placeholder="Client Seed"
              value={clientSeed}
              onChange={clientSeedChanged}
            />
          </div>
          <div className="form-group">
            <label htmlFor="count">Nonce</label>
            <input
              className="form-control"
              type="number"
              id="nonce"
              placeholder="Nonce"
              value={nonce}
              onChange={nonceChanged}
            />
          </div>
        </form>
        <br/>
      </React.Fragment>
      
      {slotWindow &&
      <div className="window">
        {slotWindow.map((reel, index) => <Reel position={index + 1} symbols={reel} />)}
          <svg width="600px" style={{ position: "absolute", width: "100%", height: "100%" }}>
            {(() => {
              const result = [];
              for (const index in linePayouts) {
                const line = linePayouts[index].line;
                result.push(generatePath(line));
              }
              return result.map((result) => {
                return <path d={result}
           style={{ fill:"none", stroke: "#a7313d", strokeWidth: 3 }} />});
          })()}
        </svg>
        <div className="payout-wrapper">
          <div className="payout">x{payout}</div>
        </div>
      </div>}
      
      <hr />

      {bonusResult &&
      <React.Fragment>
        <h3>{bonusManager.name}</h3>
        <form className="col-md-10">
          <div className="form-group">
            <label htmlFor="hash">Bonus Server Seed</label>
            <input
              className="form-control"
              type="text"
              id="bonus-server-seed"
              placeholder="Bonus Server Seed"
              value={bonusServerSeed}
              onChange={bonusServerSeedChanged}
            />
          </div>
          <div className="form-group">
            <label htmlFor="hash">Bonus Client Seed</label>
            <input
              className="form-control"
              type="text"
              id="bonus-client-seed"
              placeholder="Bonus Client Seed"
              value={bonusClientSeed}
              onChange={bonusClientSeedChanged}
            />
          </div>
          <div className="form-group">
            <label htmlFor="count">Bonus Nonce</label>
            <input
              className="form-control"
              type="number"
              id="bonus-nonce"
              placeholder="Bonus Nonce"
              value={bonusNonce}
              onChange={bonusNonceChanged}
            />
          </div>
        </form>
        <div className="btn-group" role="group">
          <button className="btn btn-success" disabled={bonusSpinIndex < 1} onClick={onPreviousSpin}>
            Previous spin
          </button>
          <button className="btn btn-info" disabled={true} style={{ minWidth: '50px' }}>
            {bonusSpinIndex + 1}
          </button>
          <button className="btn btn-success" disabled={bonusSpinIndex >= bonusResult.spins.length - 1} onClick={onNextSpin}>
            Next spin
          </button>
        </div>
        <br/>
        {bonusSlotWindow &&
        <div className="window">
          {bonusSlotWindow.map((reel, index) => <Reel position={index + 1} symbols={reel} />)}
            <svg width="600px" style={{ position: "absolute", width: "100%", height: "100%" }}>
              {(() => {
                const result = [];
                for (const index in bonusLinePayouts) {
                  const line = bonusLinePayouts[index].line;
                  result.push(generatePath(line));
                }
                return result.map((result) => {
                  return <path d={result}
            style={{ fill:"none", stroke: "#a7313d", strokeWidth: 3 }} />});
            })()}
          </svg>
          <div className="payout-wrapper">
            <div className="payout">x{bonusPayout}</div>
          </div>
        </div>}
      </React.Fragment>}
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById("react-root"));

function generate(serverSeed, clientSeed, nonce) {
  const hash = CryptoJS.SHA256(serverSeed + clientSeed + nonce).toString();

  return new BigNumber(hash, 16).toFixed();
}

function ksort(obj) {
  const keys = Object.keys(obj).sort()
  const sortedObj = {}

  for (const i in keys) {
    sortedObj[keys[i]] = obj[keys[i]]
  }

  return sortedObj
}

function generatePath(line) {
  const MARGIN = 10
  const CELL_WIDTH = 120
  const CELL_HEIGHT = 120

  const path = new SvgPathGenerator()
  for (const xPosition in line) {
    const yPosition = line[xPosition]
    const newPosition = {
      x: (CELL_WIDTH + MARGIN) * xPosition - (CELL_WIDTH + MARGIN) / 2,
      y: CELL_HEIGHT * yPosition - (CELL_HEIGHT + MARGIN) / 2
    }
    if (parseInt(xPosition) === 1) {
      path.moveTo(newPosition.x, newPosition.y)
    } else {
      path.lineTo(newPosition.x, newPosition.y)
    }
  }
  path.end()

  return path.currentPath
}

              
            
!
999px

Console