kedoska / engine-blackjack

Javascript library to make blackjack engines
GNU General Public License v2.0
33 stars 29 forks source link

Force DONE when player 21 (even soft) #12

Closed kedoska closed 7 years ago

kedoska commented 7 years ago

So, we need to close the game when player hits 21

in regular hand (no split)

    it('should finish the game when player hits 21 (soft)', function () {
      const cards = '♠6 ♠5 ♥3 ♦K ♦1 ♦9'
      const actions = [ 'restore', 'deal', 'hitR', 'hitR' ]
      const rules = {
        decks: 1,
        standOnSoft17: true,
        double: 'any',
        split: true,
        doubleAfterSplit: true,
        showdownAfterAceSplit: true
      }
      const state = executeFlow(rules, cards, actions.map(x => functions[ x ]))
      const { stage, wonOnRight, handInfo: { right } } = state
      assert.equal(right.playerValue.hi, 21, 'Player has 21 on right')
      assert.equal(stage, 'done', 'game is over')
      assert.equal(wonOnRight, 10 * 2, 'Won')
    })
  })