aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/blackjack_split_regression_test.go
blob: 1674d40a4fe1c8cbeb82d9fa821a4aa0e8e06785 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package casino

// Regression: a non-ace split can draw to 21 on the first hand (K,K splits
// into A+K). finishHand must skip that complete hand instead of prompting it,
// which offered hit/double on an unplayable 21 and stalled the round until
// the action timer fired.

import "testing"

func TestBlackjackSplitTwentyOneAdvancesToNextHand(t *testing.T) {
	table := newBlackjackTable(1, TableConfig{ID: "blackjack", Game: GameBlackjack}, newTestRand())
	wallet := &testWallet{credits: 100}
	table.join("alice")
	// Dealer 17; player K,K; the split draws A (hand one) and 5 (hand two).
	table.shoe = tableauShoe(
		card{rank: "10"}, card{rank: "7"},
		card{rank: "K"}, card{rank: "K"},
		card{rank: "A"}, card{rank: "5"}, card{rank: "2"},
	)
	table.shoe.shuffleAt = 0
	table.bet("alice", "", 10, wallet)
	if events := table.action("alice", "split"); len(events) == 0 {
		t.Fatal("split produced no events")
	}
	p := table.players.get("alice")
	if len(p.hands) != 2 {
		t.Fatalf("split failed: %+v", p.hands)
	}
	if total, _ := p.hands[0].total(); total != 21 {
		t.Fatalf("fixture: first split hand totals %d, want 21", total)
	}
	if table.activeHand != 1 {
		t.Fatalf("split 21 stayed active (hand %d, actions %v); the turn must advance to the second hand",
			table.activeHand, table.availableActions(p, p.hands[table.activeHand]))
	}
}