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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
package game
import (
"path/filepath"
"strings"
"testing"
"thehouseoficarus/internal/casino"
"thehouseoficarus/internal/color"
"thehouseoficarus/internal/world"
)
func TestCrapsVariantRendering(t *testing.T) {
for _, v := range []string{"simplified", "high_point", "crapless", "new_york", "die_rich", "diceless"} {
for _, unicode := range []bool{false, true} {
for _, mode := range []string{"none", "xterm256"} {
for _, style := range []string{"dark", "light"} {
dice := [2]int{4, 2}
if v == "die_rich" {
dice[1] = 0
}
text := renderCrapsSnapshot(&casino.CrapsSnapshot{Variant: v, Point: 4, Dice: dice}, mode, unicode, style)
plain := plainRoulette(text)
if !strings.Contains(plain, strings.ToUpper(strings.ReplaceAll(v, "_", " "))+" CRAPS") {
t.Fatal(v, "title")
}
if v == "diceless" {
for _, token := range []string{"PACK A", "PACK B", "Cards total: 6", "FIRE"} {
if !strings.Contains(plain, token) {
t.Fatal(v, token)
}
}
if strings.Contains(plain, "Total:") {
t.Fatal("dice rendered instead of cards")
}
} else {
if strings.Contains(plain, "FIRE") || strings.Contains(plain, "ALL SMALL") {
t.Fatal(v, "unsupported bonus display")
}
}
if v == "die_rich" && !strings.Contains(plain, "Total: 4") {
t.Fatal("single die absent")
}
if mode == "xterm256" && (v == "die_rich" || v == "diceless") {
bg := 0
if style == "light" {
bg = 15
}
if !strings.Contains(text, color.BgCode(mode, bg)) {
t.Fatal(v, "style")
}
}
}
}
}
}
for n := 1; n <= 6; n++ {
text := renderCrapsDice([2]int{n, 0}, "none", false, "dark")
if strings.Count(text, "+-------+") != 2 {
t.Fatal("must render exactly one die", text)
}
}
}
func TestShippedCrapsGallery(t *testing.T) {
w := world.New(filepath.Join("..", "..", "data"))
northVariants := []string{"simplified", "high_point", "crapless"}
southVariants := []string{"new_york", "die_rich", "diceless"}
for i, v := range northVariants {
id := 6186 + i
room := loadCrapsRoom(t, w, id, v)
if i > 0 && room.Exits["south"].Room != id-1 {
t.Fatal(id, "missing return exit")
}
if i < len(northVariants)-1 && room.Exits["north"].Room != id+1 {
t.Fatal(id, "unreachable next table")
}
}
for i, v := range southVariants {
id := 6189 + i
room := loadCrapsRoom(t, w, id, v)
if i == 0 && room.Exits["north"].Room != 6185 {
t.Fatal(id, "south gallery unreachable from the bank pit")
}
if i > 0 && room.Exits["north"].Room != id-1 {
t.Fatal(id, "missing return exit")
}
if i < len(southVariants)-1 && room.Exits["south"].Room != id+1 {
t.Fatal(id, "unreachable next table")
}
}
room := loadCrapsRoom(t, w, 6185, "bank")
if room.Exits["west"].Room != 6182 || room.Exits["east"].Room != 6118 {
t.Fatal("pit exits missing", room.Exits)
}
}
func loadCrapsRoom(t *testing.T, w *world.World, id int, variant string) *world.Room {
t.Helper()
room, err := w.LoadRoom(id)
if err != nil {
t.Fatal(err)
}
if len(room.CasinoTables) != 1 {
t.Fatal(id, "missing table")
}
cfg := room.CasinoTables[0]
if cfg.Game != casino.GameCraps || cfg.Craps.Variant != variant {
t.Fatal(id, cfg)
}
if err := cfg.Validate(); err != nil {
t.Fatal(id, err)
}
m := casino.NewManager(1)
m.Join(id, cfg, "a")
if m.Table(id, cfg.ID) == nil {
t.Fatal(id, "table registration")
}
return room
}
|