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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
package casino
import "testing"
// The "list" view doubles as the availability sheet: during the insurance
// window it names the insurance stake and the decline, and during a turn it
// names the wagers the current hand could still add (double/split/surrender).
func TestBlackjackWagerListFollowsTheHand(t *testing.T) {
table := newBlackjackTable(1, TableConfig{ID: "blackjack", Game: GameBlackjack}, newTestRand())
w := &testWallet{credits: 100}
table.players.add("alice", &blackjackPlayer{
Participant: Participant{Name: "alice", HasBet: true, Connected: true, Wallet: w, Wager: Wager{Total: 10}},
hands: []*blackjackHand{{bet: 10, cards: []card{{rank: "10"}, {rank: "8"}}}},
})
table.dealer.cards = []card{{rank: "K"}, {rank: "A"}}
table.phase = blackjackInsurance
rows := table.wagers("alice")
if len(rows) != 2 || rows[0].Bet != "insurance" || rows[1].Bet != "decline" {
t.Fatalf("insurance rows=%+v", rows)
}
if rows[0].Payout != "2:1" || rows[0].Win != "Covers dealer blackjack; the stake costs 5" {
t.Fatalf("insurance wording=%+v", rows[0])
}
// A turn with a splittable pair and surrender available lists both
// wagers; a hit/stand-only hand lists none.
table.phase = blackjackPlaying
table.activePlayer = 0
table.activeHand = 0
table.players.get("alice").hands = []*blackjackHand{{bet: 10, cards: []card{{rank: "8"}, {rank: "8"}}}}
table.dealer.cards = []card{{rank: "K"}, {rank: "7"}}
surrender := true
table.Rules.Surrender = &surrender
if rows := table.wagers("alice"); len(rows) == 0 {
t.Fatal("turn rows missing")
}
table.Rules.Surrender = nil
table.players.get("alice").hands = []*blackjackHand{{bet: 10, cards: []card{{rank: "K"}, {rank: "6"}}}}
rows = table.wagers("alice")
if len(rows) != 3 || rows[0].Bet != "hit" || rows[2].Bet != "double" {
t.Fatalf("plain hand rows=%+v", rows)
}
}
// The betting phase has exactly one wager: no rows, and no "list" hint.
func TestBlackjackBettingPhaseHidesList(t *testing.T) {
table := newBlackjackTable(1, TableConfig{ID: "blackjack", Game: GameBlackjack, BettingTicks: 10}, newTestRand())
table.join("a")
hints := table.hints("a")
for _, c := range hints {
if c.Command == "list" {
t.Fatal("list advertised with a single wager", hints)
}
if c.Command != "rules" {
continue
}
}
foundRules := false
for _, c := range hints {
if c.Command == "rules" {
foundRules = true
}
}
if !foundRules {
t.Fatal("rules hint missing", hints)
}
}
// Craps variants that take one target (pass only) never advertise "list".
func TestCrapsSingleBetVariantsHideList(t *testing.T) {
for _, v := range []string{"simplified", "high_point", "die_rich"} {
tb := variantFixture(v)
tb.join("a")
for _, c := range tb.hints("a") {
if c.Command == "list" {
t.Fatal(v, "list advertised for a single-bet variant")
}
if c.Command == "rules" {
break
}
}
}
}
// Multi-bet variants advertise the "list" hint at every phase.
func TestCrapsMultiBetVariantsAdvertiseList(t *testing.T) {
for _, v := range []string{"bank", "crapless", "new_york", "diceless"} {
tb := variantFixture(v)
tb.join("a")
found := false
for _, c := range tb.hints("a") {
if c.Command == "list" {
found = true
}
}
if !found {
t.Fatal(v, "list hint missing", tb.hints("a"))
}
}
}
|