Skip to content

Commit

Permalink
Break on SURRENDER, fix some sim settings
Browse files Browse the repository at this point in the history
  • Loading branch information
keithwhor committed Dec 6, 2017
1 parent bc37e09 commit 30750a8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/blackjack.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ class Blackjack {
playerHand.splice(0, playerHand.length);
bets[handIndex] = bet / 2;
bankroll += bet / 2;
break;
}
}
iterationCount++;
Expand All @@ -483,7 +484,7 @@ class Blackjack {

// Reduction step over all player hands to see net outcome
return playerHands.reduce((sum, playerHand, i) => {
return sum + this.handResult(playerHand, dealerHand, bets[i], i, debug);
return sum + this.handResult(playerHand, dealerHand, bets[i], i, true, debug);
}, 0);

}
Expand Down Expand Up @@ -710,7 +711,7 @@ Blackjack.Table = class Table {
options.initialBankroll = options.initialBankroll || 100;
options.targetBankroll = options.targetBankroll || 200;
options.minimumBet = options.minimumBet || 5;
options.strategy = Blackjack.strategies[options.strategy] ?
options.strategy = this.constructor.strategies[options.strategy] ?
options.strategy : this.constructor.defaultStrategy;
options.maxHands = options.maxHands || null;
options.playRequirement = this.constructor.playRequirements[options.playRequirement] ?
Expand Down Expand Up @@ -742,7 +743,7 @@ Blackjack.Table = class Table {
let minimumBet = this.options.minimumBet;
let bettingStrategy = this.options.strategy;
let maxHands = this.options.maxHands;
let fnStrategy = Blackjack.strategies[this.options.strategy];
let fnStrategy = this.constructor.strategies[this.options.strategy];
let fnPlayRequirement = this.constructor.playRequirements[this.options.playRequirement];

let blackjackPayout = this.options.blackjackPayout;
Expand Down Expand Up @@ -773,7 +774,7 @@ Blackjack.Table = class Table {
handCount++;
bankroll += result;
bet = Math.min(fnStrategy(result > 0, bet, minimumBet), bankroll);
if (deck.length < 13) {
if (deck.length < 26) {
deck = Blackjack.shuffle(deckCount);
}
}
Expand Down Expand Up @@ -811,7 +812,7 @@ Blackjack.Table.strategies = {
* Table simulation play requirements: under which circumstances do I continue
* to play hands? (Have not lost bankroll is a given)
*/
Table.playRequirements = {
Blackjack.Table.playRequirements = {
underTarget: (handCount, maxHands, bankroll, initialBankroll, targetBankroll) => {
return bankroll < targetBankroll;
},
Expand Down

0 comments on commit 30750a8

Please sign in to comment.