binions
Version:
A Javascript Poker game engine
102 lines (87 loc) • 3.81 kB
text/coffeescript
assert = require 'assert'
NoLimit = require('../src/betting/no_limit')(10,20)
{Player} = require '../src/player'
{Game} = require '../src/game'
kPlayerStartingChips = 1000
describe "General betting expectations", ->
beforeEach ->
= []
callsAll =
update: (game) ->
unless game.state == 'complete'
if game.self.wagered < game.minToCall
game.minToCall - game.self.wagered
else
0
for n in [0..3]
.push new Player(callsAll, kPlayerStartingChips, n)
= 'flop'
= new NoLimit(, )
it "should calculate the correct minimum raise and call amounts at the start of a round", ->
betOptions = .analyze()
assert.equal 10, betOptions['raise']
assert.equal 0, betOptions['call']
it "should allow a check", ->
betOptions = .analyze()
.bet(0, 0, null)
betAction = [0].actions()[0]
assert betAction['type'] == 'check'
it "should allow a player to raise", ->
betOptions = .analyze()
actingPlayer = .nextToAct
raiseAmount = betOptions['call'] + betOptions['raise']
.bet(raiseAmount, 0, null)
betAction = [0].actions()[0]
assert betAction['type'] == 'raise'
assert betAction['bet'] == raiseAmount
assert .options()['call'] == raiseAmount
it "should allow a player to go all-in", ->
.analyze()
allInBet = [0].chips
.bet(allInBet, 0, null)
betAction = [0].actions()[0]
assert betAction['type'] == 'allIn'
assert betAction['bet'] == allInBet
it "should allow a player to raise all-in", ->
.analyze()
.bet(.options()['call'] + .options()['raise'], 0, null)
.bet(.options()['call'] + .options()['raise'], 1, null)
.bet(kPlayerStartingChips, 2, null)
betAction = [2].actions()[0]
assert betAction['type'] == 'allIn'
assert betAction['bet'] == kPlayerStartingChips
it "should not allow a player to bet more chips than they have", ->
.analyze()
.bet(kPlayerStartingChips * 2, 0, null)
betAction = [0].actions()[0]
assert betAction['type'] == 'allIn'
assert betAction['bet'] == kPlayerStartingChips
it "should allow a player to fold", ->
betOptions = .analyze()
raiseAmount = betOptions['call'] + betOptions['raise']
.bet(raiseAmount, 0, null)
.bet(0, 1, null)
betAction = [1].actions()[0]
assert betAction['type'] == 'fold'
it "should allow a re-raise", ->
betOptions = .analyze()
raiseAmount = betOptions['call'] + betOptions['raise']
.bet(raiseAmount, 0, null)
reRaiseAmount = .options()['call'] + .options()['raise']
assert reRaiseAmount > raiseAmount
.bet(reRaiseAmount, 1, null)
betAction = [1].actions()[0]
assert betAction['type'] == 'raise'
it "should prevent a player from calling less than the call amount", ->
betOptions = .analyze()
actingPlayer = .nextToAct
raiseAmount = betOptions['call'] + betOptions['raise']
.bet(raiseAmount, null, null)
.bet(.options()['call'] - 1, null, null)
betAction = [1].actions()[0]
assert betAction['type'] == 'fold'
it "should prevent a player from raising less than the minimum amount", ->
betOptions = .analyze()
actingPlayer = .nextToAct
.bet(betOptions['call'] + betOptions['raise'] - 1, 0, null)
assert ([0].actions()[0])['type'] == 'check'