Skip to content

Commit

Permalink
Variety of bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieHess committed Aug 2, 2015
1 parent db2abe9 commit b8205c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
17 changes: 12 additions & 5 deletions ai/aggro-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
});
}
};
2 changes: 1 addition & 1 deletion ai/weak-bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
13 changes: 10 additions & 3 deletions src/player-interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,29 @@ 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 {
availableActions.push('check');
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;
}
Expand Down
1 change: 1 addition & 0 deletions src/texas-holdem.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class TexasHoldem {
setupPlayers() {
for (let player of this.players) {
player.isInHand = player.chips > 0;
player.isAllIn = false;
player.isBettor = false;
}

Expand Down

0 comments on commit b8205c9

Please sign in to comment.