Skip to content

Commit 6c037ab

Browse files
authored
Fix insurance deviation not firing with soft hands (#124)
The _suggest method returned early for soft hands, which is correct for play deviations (no I18 entries for soft totals) but wrong for insurance, which is independent of the player's hand. A player with A+2 (soft 13) at TC >= 3 was told not to buy insurance. Fix: skip the soft-hand check when the step is WaitingForInsuranceInput. Bump version to 0.35.12.
1 parent 1e4e53c commit 6c037ab

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blackjacktrainer/blackjack-simulator",
3-
"version": "0.35.11",
3+
"version": "0.35.12",
44
"engines": {
55
"node": ">=20"
66
},

src/hi-lo-deviation-checker.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,19 @@ export default class HiLoDeviationChecker {
9292
): Deviation | undefined {
9393
const trueCount = game.shoe.hiLoTrueCount;
9494

95-
if (game.dealer.upcard == null || hand.isSoft) {
95+
if (game.dealer.upcard == null) {
9696
return;
9797
}
9898

99-
const playerTotal =
100-
game.state.step === GameStep.WaitingForInsuranceInput
101-
? 0
102-
: hand.cardTotal;
99+
const isInsurance = game.state.step === GameStep.WaitingForInsuranceInput;
100+
101+
// Soft hands have no play deviations in the I18, but insurance is
102+
// independent of the player's hand.
103+
if (hand.isSoft && !isInsurance) {
104+
return;
105+
}
106+
107+
const playerTotal = isInsurance ? 0 : hand.cardTotal;
103108
const dealersCard = game.dealer.upcard.value;
104109

105110
const deviation =

test/src/game.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,34 @@ describe('Game', function () {
639639
},
640640
);
641641

642+
context(
643+
'when player accepts insurance at TC >= 3 with a soft hand',
644+
function () {
645+
before(function () {
646+
game = setupGame({
647+
settings: {
648+
deckCount: 6,
649+
autoDeclineInsurance: false,
650+
checkDeviations: true,
651+
},
652+
dealerCards: [Rank.Ace, Rank.Nine],
653+
playerCards: [Rank.Ace, Rank.Two],
654+
});
655+
656+
game.step();
657+
game.shoe.hiLoRunningCount = game.shoe.decksRemaining * 3.89;
658+
659+
game.step(Move.AskInsurance);
660+
});
661+
662+
it('should mark insurance as correct (soft hand should not block insurance deviation)', function () {
663+
expect(game.state.sessionMovesCorrect).to.equal(1);
664+
expect(game.state.sessionMovesTotal).to.equal(1);
665+
expect(game.state.playCorrection).to.equal('');
666+
});
667+
},
668+
);
669+
642670
context(
643671
'when player correctly declines insurance at TC < 3 with checkDeviations on',
644672
function () {

0 commit comments

Comments
 (0)