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

import (
	"strings"
	"testing"

	"thehouseoficarus/internal/casino"
)

func TestVideoPokerCommandsAndLook(t *testing.T) {
	g, sess, conn := casinoCrapsGame(t, "name: Poker\ncasino_tables:\n  - id: vp\n    game: video_poker\n")
	g.executePlay(sess, []string{"vp"}, "play vp")
	conn.data = nil
	g.executeRules(sess, nil, "rules")
	if text := stripANSI(string(conn.data)); !strings.Contains(text, "Jacks or Better") {
		t.Fatal(text)
	}
	g.executeBet(sess, []string{"max"}, "bet max")
	g.executeTableAction(sess, "deal")
	if classifyCommand("531") != ClassInstant {
		t.Fatal("numeric holds rejected by dispatch")
	}
	g.executeCommand(sess, "531", nil, "531")
	table, _ := g.Casino.Participation(sess.Player.Name)
	snap := table.Status(sess.Player.Name)[0].Snapshot.(*casino.VideoPokerSnapshot)
	if snap.Held != ([5]bool{true, false, true, false, true}) {
		t.Fatalf("numeric holds: %+v", snap.Held)
	}
	conn.data = nil
	room, _ := g.World.LoadRoom(1)
	g.showCasinoGameLook(sess, sess.Player, room)
	text := stripANSI(string(conn.data))
	for _, want := range []string{"1 HELD", "3 HELD", "5 HELD", "draw"} {
		if !strings.Contains(text, want) {
			t.Fatalf("look missing %q: %s", want, text)
		}
	}
	after := table.Status(sess.Player.Name)[0].Snapshot.(*casino.VideoPokerSnapshot)
	if after.Held != snap.Held {
		t.Fatal("look altered holds")
	}
	conn.data = nil
	g.executeList(sess, nil, "list")
	if text := stripANSI(string(conn.data)); !strings.Contains(text, "No wagers are available") || strings.Contains(text, "COINS PER HAND") {
		t.Fatal(text)
	}
	g.executeCommand(sess, "1", []string{"3", "5"}, "1 3 5")
	if got := table.Status(sess.Player.Name)[0].Snapshot.(*casino.VideoPokerSnapshot).Held; got != ([5]bool{}) {
		t.Fatalf("holds did not toggle off: %v", got)
	}
	g.executeCommand(sess, "d", nil, "d")
	if table.Status(sess.Player.Name)[0].Snapshot.(*casino.VideoPokerSnapshot).Drawing || len(sess.Player.PendingWagers) != 0 {
		t.Fatal("d did not draw")
	}
	g.executeCommand(sess, "game", []string{"deuces", "wild"}, "game deuces wild")
	conn.data = nil
	g.executeTableStatus(sess, []string{"rules"}, "table rules")
	if text := stripANSI(string(conn.data)); !strings.Contains(text, "Deuces Wild / 25/15/9/5/3/2") || !strings.Contains(text, "4000") || !strings.Contains(text, "COINS PER HAND") {
		t.Fatal(text)
	}
}
func TestBlackjackListUsesRealActionCommands(t *testing.T) {
	g, sess, conn := casinoCrapsGame(t, "name: BJ\ncasino_tables:\n  - id: bj\n    game: blackjack\n")
	g.executePlay(sess, []string{"bj"}, "play bj")
	// Deal until a hand has available action rows (a natural can settle immediately).
	table, _ := g.Casino.Participation(sess.Player.Name)
	for i := 0; i < 10 && len(table.Wagers(sess.Player.Name)) == 0; i++ {
		g.executeBet(sess, []string{"1"}, "bet 1")
	}
	if len(table.Wagers(sess.Player.Name)) == 0 {
		t.Fatal("no action rows")
	}
	conn.data = nil
	g.executeList(sess, nil, "list")
	text := stripANSI(string(conn.data))
	if strings.Contains(text, "bet <amount> on") || !strings.Contains(text, "Available actions") {
		t.Fatal(text)
	}
}