aboutsummaryrefslogtreecommitdiff
path: root/internal/game/roulette_test.go
blob: fb773a3fc1932479a75517329f179259bf1b6e82 (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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package game

import (
	"strings"
	"testing"

	"thehouseoficarus/internal/casino"
	"thehouseoficarus/internal/combat"
	"thehouseoficarus/internal/net"
	"thehouseoficarus/internal/player"
	"thehouseoficarus/internal/world"
)

func TestRouletteNumericTargetsAndRendering(t *testing.T) {
	for _, double := range []bool{false, true} {
		g := &Game{Casino: casino.NewManager(1), Combat: combat.NewTracker(), Deps: Deps{World: world.New(t.TempDir())}}
		cfg := casino.TableConfig{ID: "roulette", Game: casino.GameRoulette, Roulette: casino.RouletteConfig{DoubleZero: double}}
		g.Casino.Join(1, cfg, "alice")
		conn := &casinoTestConn{}
		sess := &net.Session{Player: player.New("alice"), Conn: conn}
		g.loggedInChars = map[string]*net.Session{"alice": sess}
		for _, target := range []string{"0", "17", "00", "red", "row2"} {
			conn.data = nil
			g.executeBet(sess, []string{"10", "on", target}, "bet 10 on "+target)
			expected := "You don't have enough chips and credits"
			if target == "00" && !double {
				expected = "Unknown roulette target"
			}
			if !strings.Contains(string(conn.data), expected) {
				t.Fatalf("target=%s double=%v: %s", target, double, conn.data)
			}
		}
		conn.data = nil
		g.executeTableStatus(sess, nil, "table")
		// The table command shows the wheel board alone: no payout reminder.
		text := string(conn.data)
		if !strings.Contains(text, "History") || strings.Contains(text, "Blackjack") || strings.Contains(text, "35:1") {
			t.Fatal("wrong felt", text)
		}
		snapshot := &casino.RouletteSnapshot{DoubleZero: double, Phase: "playing", Players: []string{"alice"}}
		if got := g.renderCasinoSnapshot(sess, snapshot); got != renderRouletteSnapshot(snapshot, g.colorMode(sess), sess.Player.OptionBool("unicode"), sess.Player.OptionInt("card_size")) {
			t.Fatal("snapshot not rendered", got)
		}
		if !g.seesCasinoDetails(sess, casino.Event{RoomID: 1, TableID: "roulette", Snapshot: snapshot}) {
			t.Fatal("player cannot see wheel")
		}
	}
}

func TestRouletteCombinationTargetParsing(t *testing.T) {
	for _, double := range []bool{false, true} {
		g := &Game{Casino: casino.NewManager(1)}
		cfg := casino.TableConfig{ID: "roulette", Game: casino.GameRoulette, Roulette: casino.RouletteConfig{DoubleZero: double}}
		g.Casino.Join(1, cfg, "alice")
		conn := &casinoTestConn{}
		sess := &net.Session{Player: player.New("alice"), Conn: conn}
		g.loggedInChars = map[string]*net.Session{"alice": sess}
		// Multi-token targets are joined for roulette, with or without "on".
		valid := [][]string{
			// A numeric target needs no "on": "bet 10 17" == "bet 10 on 17".
			{"10", "17"},
			{"10", "on", "17"},
			{"10", "on", "split", "1", "2"},
			{"10", "on", "split", "1-2"},
			{"10", "split", "1-2"},
			{"10", "split", "1", "2"},
			{"10", "on", "street", "1", "2", "3"},
			{"10", "on", "street", "3", "1", "2"},
			{"10", "on", "corner", "1", "2", "4", "5"},
			{"10", "on", "corner", "5", "1", "4", "2"},
			{"10", "on", "line", "1", "2", "3", "4", "5", "6"},
			{"10", "on", "trio", "0", "1", "2"},
			{"10", "on", "basket"},
		}
		if double {
			valid = append(valid, []string{"10", "on", "split", "0", "00"})
		}
		for _, args := range valid {
			conn.data = nil
			g.executeBet(sess, args, "bet "+strings.Join(args, " "))
			if !strings.Contains(string(conn.data), "You don't have enough chips and credits") {
				t.Fatalf("double=%v args=%v: expected wallet failure, got %q", double, args, conn.data)
			}
		}
		// Non-adjacent or wrong-shaped combinations must not reach the wallet.
		invalid := [][]string{
			{"10", "on", "split", "1", "5"},
			{"10", "on", "street", "2", "3", "4"},
			{"10", "on", "corner", "1", "2", "3", "4"},
			{"10", "on", "line", "1", "2", "3", "4", "5", "7"},
			{"10", "on", "trio", "0", "1", "5"},
		}
		if !double {
			invalid = append(invalid, []string{"10", "on", "split", "0", "00"})
		}
		for _, args := range invalid {
			conn.data = nil
			g.executeBet(sess, args, "bet "+strings.Join(args, " "))
			if !strings.Contains(string(conn.data), "Unknown roulette target") {
				t.Fatalf("double=%v args=%v: expected target rejection, got %q", double, args, conn.data)
			}
		}
	}
}

func TestRouletteRacetrackTargetParsing(t *testing.T) {
	// A racetrack single-zero table accepts the call and neighbours syntaxes.
	g := &Game{Casino: casino.NewManager(1)}
	cfg := casino.TableConfig{ID: "roulette", Game: casino.GameRoulette, Roulette: casino.RouletteConfig{Racetrack: true}}
	g.Casino.Join(1, cfg, "alice")
	conn := &casinoTestConn{}
	sess := &net.Session{Player: player.New("alice"), Conn: conn}
	g.loggedInChars = map[string]*net.Session{"alice": sess}
	valid := [][]string{
		{"10", "on", "voisins"},
		{"10", "on", "voisins", "du", "zero"},
		{"10", "on", "tiers"},
		{"10", "on", "orphelins"},
		{"10", "on", "zero"},
		{"10", "on", "jeu", "zero"},
		{"10", "on", "jeuzero"},
		{"10", "on", "0"},
		{"10", "on", "neighbors", "17"},
		{"10", "on", "neighbors", "of", "17"},
	}
	for _, args := range valid {
		conn.data = nil
		g.executeBet(sess, args, "bet "+strings.Join(args, " "))
		if !strings.Contains(string(conn.data), "You don't have enough chips and credits") {
			t.Fatalf("args=%v: expected wallet failure, got %q", args, conn.data)
		}
	}
	// The same names are unknown on a single-zero table without the option.
	plain := &Game{Casino: casino.NewManager(1)}
	plain.Casino.Join(1, casino.TableConfig{ID: "roulette", Game: casino.GameRoulette}, "bob")
	conn2 := &casinoTestConn{}
	sess2 := &net.Session{Player: player.New("bob"), Conn: conn2}
	plain.loggedInChars = map[string]*net.Session{"bob": sess2}
	for _, args := range [][]string{{"10", "on", "voisins"}, {"10", "on", "neighbors", "17"}} {
		conn2.data = nil
		plain.executeBet(sess2, args, "bet "+strings.Join(args, " "))
		if !strings.Contains(string(conn2.data), "Unknown roulette target") {
			t.Fatalf("non-racetrack args=%v: expected rejection, got %q", args, conn2.data)
		}
	}
}

func TestCasinoTestPortalAuthoredContract(t *testing.T) {
	g, rooms, _ := loadVesta(t)
	found := false
	for _, obj := range rooms[1001].Objects {
		found = found || obj.ID == "casino_test_portal"
	}
	if !found {
		t.Fatal("portal missing from starting room")
	}
	obj, err := g.ObjectStore.Load("casino_test_portal")
	if err != nil {
		t.Fatal(err)
	}
	if len(obj.OnUse) != 1 || len(obj.OnUse[0].Steps) != 2 {
		t.Fatal("unexpected portal sequence")
	}
	steps := obj.OnUse[0].Steps
	if len(steps[0].DropTable) != 1 || steps[0].DropTable[0].ItemID != "chips" || steps[0].DropTable[0].Quantity != 1000 {
		t.Fatal("portal does not grant 1000 chips")
	}
	if steps[1].Teleport != 6100 || rooms[6100] == nil {
		t.Fatal("wrong casino destination")
	}
	for _, id := range []int{6182, 6183, 6184} {
		cfg := rooms[id].CasinoTables[0]
		if err := cfg.Validate(); err != nil {
			t.Fatal(err)
		}
		if cfg.Game != casino.GameRoulette || cfg.Roulette.DoubleZero != (id == 6183) {
			t.Fatal("wrong roulette rules", id)
		}
		if cfg.Roulette.Racetrack != (id == 6184) {
			t.Fatal("wrong racetrack setting", id)
		}
	}
}

// A wager must not re-send the betting board; the board arrives on join,
// after settlement via the next-spin menu, or on an explicit "table".
func TestRouletteBetDoesNotResendBoard(t *testing.T) {
	g, sess, conn := uxCasinoGame(t)
	cfg := casino.TableConfig{ID: "roulette", Game: casino.GameRoulette}
	g.emitCasinoEvents(g.Casino.Join(1, cfg, sess.Player.Name))
	if !strings.Contains(string(conn.data), "1to12") {
		t.Fatalf("join did not draw the board: %q", conn.data)
	}
	conn.data = nil
	g.executeBet(sess, []string{"10", "on", "red"}, "bet 10 on red")
	text := string(conn.data)
	if strings.Contains(text, "1to12") {
		t.Fatalf("placing a wager redrew the board: %q", text)
	}
	if !strings.Contains(text, "You bet 10 on red") {
		t.Fatalf("missing wager confirmation: %q", text)
	}
}