aboutsummaryrefslogtreecommitdiff
path: root/internal/game/casino_hints_test.go
blob: 21739d2d2197aac2b20a021c5b0eeab38a157f30 (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
package game

import (
	"strings"
	"testing"

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

// The default must be the low-noise "once" mode.
func TestCasinoHintsDefaultIsOnce(t *testing.T) {
	if got := player.New("alice").OptionString("casino_hints"); got != "once" {
		t.Fatalf("casino_hints default=%q, want once", got)
	}
}

// casino_hints on shows hints on every menu; once shows them at sit-down only;
// off never does. "what" always lists the live hints regardless.
func TestCasinoHintsOption(t *testing.T) {
	for _, tc := range []struct {
		mode        string
		join, after bool
	}{
		{"on", true, true},
		{"once", true, false},
		{"off", false, false},
	} {
		t.Run(tc.mode, func(t *testing.T) {
			g, sess, conn := uxCasinoGame(t)
			g.Hub = net.NewHub()
			g.Hub.EnterRoom(sess, 1)
			sess.Player.Options = map[string]any{"color": "none", "unicode": true, "casino_hints": tc.mode}
			cfg := casino.TableConfig{ID: "roulette", Game: casino.GameRoulette, Roulette: casino.RouletteConfig{SpinTicks: 8}}
			g.emitCasinoEvents(g.Casino.Join(1, cfg, sess.Player.Name))
			if got := strings.Contains(string(conn.data), "bet N on BET"); got != tc.join {
				t.Fatalf("join hints=%v, want %v: %q", got, tc.join, conn.data)
			}
			sess.ClearPrompt()
			g.executeBet(sess, []string{"2", "2"}, "bet 2 2")
			if !strings.Contains(string(conn.data), "You bet 2 on 2.") {
				t.Fatalf("bet N N did not resolve: %q", conn.data)
			}
			for i := 0; i < 8; i++ {
				conn.data = nil
				g.CasinoTick()
			}
			if got := strings.Contains(string(conn.data), "bet N on BET"); got != tc.after {
				t.Fatalf("post-settlement hints=%v, want %v: %q", got, tc.after, conn.data)
			}
			// "what" is an explicit request: it always lists the live hints
			// and never the room's exits while seated.
			conn.data = nil
			g.executeVerbs(sess, nil, "what")
			text := string(conn.data)
			if !strings.Contains(text, "bet N on BET") || strings.Contains(text, "Exits:") || strings.Contains(text, "north") {
				t.Fatalf("what at the table wrong: %q", text)
			}
		})
	}
}