diff --git a/ai/aggro-bot.js b/ai/aggro-bot.js index 69131dd..a9a0d89 100644 --- a/ai/aggro-bot.js +++ b/ai/aggro-bot.js @@ -13,10 +13,17 @@ class AggroBot { // TOO STRONK getAction(availableActions, previousActions) { - let action = availableActions.indexOf('raise') > -1 ? - { name: 'raise' } : - { name: 'bet' }; - let delay = 1000 + (Math.random() * 500); - return rx.Observable.timer(delay).map(() => action); + let desiredAction = 'call'; + + if (availableActions.indexOf('raise') > -1) { + desiredAction = 'raise'; + } else if (availableActions.indexOf('bet') > -1) { + desiredAction = 'bet'; + } + + let delay = 2000 + (Math.random() * 2000); + return rx.Observable.timer(delay).map(() => { + return { name: desiredAction }; + }); } }; diff --git a/ai/weak-bot.js b/ai/weak-bot.js index bd1eec2..c7fd8d8 100644 --- a/ai/weak-bot.js +++ b/ai/weak-bot.js @@ -16,7 +16,7 @@ class WeakBot { let action = availableActions.indexOf('check') > -1 ? { name: 'check' } : { name: 'call' }; - let delay = 1000 + (Math.random() * 3000); + let delay = 2000 + (Math.random() * 4000); return rx.Observable.timer(delay).map(() => action); } }; diff --git a/src/player-interaction.js b/src/player-interaction.js index 28509cd..7717e0e 100644 --- a/src/player-interaction.js +++ b/src/player-interaction.js @@ -129,15 +129,15 @@ class PlayerInteraction { // Returns an array of strings static getAvailableActions(player, previousActions) { let actions = _.values(previousActions); - let playerBet = actions.some(a => a.name === 'bet'); - let playerRaised = actions.some(a => a.name === 'raise'); + let betActions = _.filter(actions, a => a.name === 'bet' || a.name === 'raise'); + let hasBet = betActions.length > 0; let availableActions = []; if (player.hasOption) { availableActions.push('check'); availableActions.push('raise'); - } else if (playerBet || playerRaised) { + } else if (hasBet) { availableActions.push('call'); availableActions.push('raise'); } else { @@ -145,6 +145,13 @@ class PlayerInteraction { availableActions.push('bet'); } + // Prevent players from raising when they don't have enough chips. + let raiseIndex = availableActions.indexOf('raise'); + if (raiseIndex > -1 && + _.max(betActions, a => a.amount).amount >= player.chips) { + availableActions.splice(raiseIndex, 1); + } + availableActions.push('fold'); return availableActions; } diff --git a/src/texas-holdem.js b/src/texas-holdem.js index 4370e5f..1cf843f 100644 --- a/src/texas-holdem.js +++ b/src/texas-holdem.js @@ -110,6 +110,7 @@ class TexasHoldem { setupPlayers() { for (let player of this.players) { player.isInHand = player.chips > 0; + player.isAllIn = false; player.isBettor = false; }