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

import (
	"strings"
	"testing"

	"thehouseoficarus/internal/casino"
)

// A room with one table of each kind, so look targets and aliases resolve.
const lookCasinoRoom = `name: Look Room
casino_tables:
  - id: bjtable
    game: blackjack
    blackjack:
      decks: 2
      blackjack_payout: 2
  - id: crock
    game: craps
    craps:
      variant: simplified
  - id: wheel
    game: roulette
  - id: pgtable
    game: paigow
    pai_gow:
      variant: classic
      envy: true
`

func TestLookCasinoTableDetailsAndBoards(t *testing.T) {
	g, sess, conn := casinoCrapsGame(t, lookCasinoRoom)

	// Craps: details only. The graphical felt and the full rule dump are gone.
	conn.data = nil
	if !g.lookCasinoTable(sess, "craps", casino.GameCraps) {
		t.Fatal("look craps did not match")
	}
	text := stripANSI(string(conn.data))
	for _, want := range []string{"Craps", "Limits", "Seats", "State", "Rules", "Simplified Craps", "Seated"} {
		if !strings.Contains(text, want) {
			t.Fatalf("look craps missing %q: %s", want, text)
		}
	}
	for _, gone := range []string{"PASS ONLY", "bet N on pass", "HOUSE EDITION"} {
		if strings.Contains(text, gone) {
			t.Fatalf("look craps showed invariant content %q: %s", gone, text)
		}
	}

	// Roulette: details plus the live wheel (tracker, layout, and history).
	conn.data = nil
	if !g.lookCasinoTable(sess, "roulette", casino.GameRoulette) {
		t.Fatal("look roulette did not match")
	}
	text = stripANSI(string(conn.data))
	if !strings.Contains(text, "Roulette / Single zero") || !strings.Contains(text, "single-zero wheel") {
		t.Fatalf("look roulette missing variant summary: %s", text)
	}
	if !strings.Contains(text, "History: last") {
		t.Fatalf("look roulette missing the live board: %s", text)
	}
	if strings.Contains(text, "Roulette payouts") {
		t.Fatalf("look roulette still dumps the payout reference: %s", text)
	}
}

func TestLookCasinoTableAliasesAndFeltGames(t *testing.T) {
	g, sess, conn := casinoCrapsGame(t, lookCasinoRoom)

	// Play shortcuts resolve through look too, and the felt games keep their
	// per-table rule card.
	for target, want := range map[string]string{"bj": "BLACKJACK PAYS 2 TO 1", "paigow": "FORTUNE", "pai": "FORTUNE"} {
		conn.data = nil
		g.doLookTarget(sess, target)
		text := stripANSI(string(conn.data))
		if !strings.Contains(text, want) {
			t.Fatalf("look %s missing %q: %s", target, want, text)
		}
	}
	if g.lookCasinoTable(sess, "bj", casino.GameCraps) {
		t.Fatal("look craps matched a blackjack target")
	}
}

func TestLookCasinoUsesLiveNormalizedConfig(t *testing.T) {
	// The room fixture omits max_players and limits; look must report the
	// defaults EnsureTable fills in, not zero values.
	g, sess, conn := casinoCrapsGame(t, "name: Bare\ncasino_tables:\n  - id: wheel\n    game: roulette\n")
	conn.data = nil
	if !g.lookCasinoTable(sess, "wheel", casino.GameRoulette) {
		t.Fatal("look by fixture id did not match")
	}
	text := stripANSI(string(conn.data))
	if !strings.Contains(text, "Seats    0/8") || !strings.Contains(text, "Limits   1-") {
		t.Fatalf("look missed normalized config: %s", text)
	}
}

func TestPaigowGameNameAndRoomListing(t *testing.T) {
	g, sess, _ := casinoCrapsGame(t, "name: Pai Gow\ncasino_tables:\n  - id: fortune\n    game: paigow\n    pai_gow:\n      envy: true\n")
	g.executePlay(sess, []string{"paigow"}, "play paigow")
	table, ok := g.Casino.Participation(sess.Player.Name)
	if !ok || table == nil || table.Config.Game != casino.GamePaiGow {
		t.Fatalf("play paigow did not join: %v %v", ok, table)
	}
	if string(table.Config.Game) != "paigow" {
		t.Fatalf("game name = %q, want paigow", table.Config.Game)
	}
	// The room listing advertises the short name and no longer leaks limits.
	room, err := g.World.LoadRoom(sess.Player.RoomID)
	if err != nil {
		t.Fatal(err)
	}
	text := stripANSI(strings.Join(g.showRoomCasinos(sess, room), "\n"))
	if !strings.Contains(text, "play paigow") || !strings.Contains(text, "Pai Gow Poker | 1/6 seated") {
		t.Fatalf("room listing wrong: %s", text)
	}
	if strings.Contains(text, "Limits") {
		t.Fatalf("room listing still shows limits: %s", text)
	}
}