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
|
package casino
import "testing"
func TestSimplifiedCrapsAll36SettlementsAndHouseEdge(t *testing.T) {
// Total returns for a one-credit wager, including the winning stake.
returns := [13]int{2: 4, 3: 2, 4: 2, 10: 3, 11: 3, 12: 6}
totalReturned, wins := 0, 0
for a := 1; a <= 6; a++ {
for b := 1; b <= 6; b++ {
tb := variantFixture("simplified")
tb.join("a")
w := &testWallet{chips: 100}
tb.bet("a", "pass", 1, w)
want := returns[a+b]
for _, row := range tb.projectionFor(tb.players.get("a")) {
if row.Total == a+b && row.Net != want-1 {
t.Fatalf("preview for %d+%d: got %d, want %d", a, b, row.Net, want-1)
}
}
tb.resolveRoll(a, b)
if w.paid != want || len(w.open) != 0 || tb.players.get("a").HasBet || tb.point != 0 {
t.Fatalf("roll %d+%d: paid %d, want %d; open %v, point %d", a, b, w.paid, want, w.open, tb.point)
}
totalReturned += w.paid
if w.paid > 0 {
wins++
}
}
}
// 36 credits wagered, 35 returned: house edge exactly 1/36 = 2.777...%.
if totalReturned != 35 || wins != 12 {
t.Fatalf("all 36 rolls: returned %d, wins %d", totalReturned, wins)
}
}
|