aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/craps_clock_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-10-02 17:51:46 -0400
committerhistoria <[not public]>2026-10-02 17:51:46 -0400
commitcac16d1725c46c82a2e62b84c93f7090b2ce0746 (patch)
treee54f6624bdeb47421587656757ef3ce4fd7ebb3f /internal/casino/craps_clock_test.go
parent4f40f116ba884111c9a66849e620ff9fbc67530a (diff)
downloadthehouseoficarus-cac16d1725c46c82a2e62b84c93f7090b2ce0746.tar.gz
feat: craps table color improvements, die improvements
Diffstat (limited to 'internal/casino/craps_clock_test.go')
-rw-r--r--internal/casino/craps_clock_test.go75
1 files changed, 36 insertions, 39 deletions
diff --git a/internal/casino/craps_clock_test.go b/internal/casino/craps_clock_test.go
index f9ad445..97758f8 100644
--- a/internal/casino/craps_clock_test.go
+++ b/internal/casino/craps_clock_test.go
@@ -3,7 +3,6 @@ package casino
import (
"strings"
"testing"
- "time"
)
func crapsEventText(events []Event) string {
@@ -24,11 +23,11 @@ func TestCrapsMultiplayerClockAndLateBets(t *testing.T) {
if tb.view().ShootIn != 10 || tb.view().DealerIn != 70 {
t.Fatal(tb.view())
}
- if text := crapsEventText(tb.tickElapsed(6 * time.Second)); strings.Contains(text, "Last call") {
+ if text := crapsEventText(tb.advance(6)); strings.Contains(text, "Last call") {
t.Fatal("early warning")
}
- events := tb.tickElapsed(time.Second)
- if !strings.Contains(crapsEventText(events), "Last call for bets! 3 seconds until alice can shoot!") {
+ events := tb.advance(1)
+ if !strings.Contains(crapsEventText(events), "Last call for bets! 3 ticks until alice can shoot!") {
t.Fatal(events)
}
if !events[0].Public {
@@ -38,7 +37,7 @@ func TestCrapsMultiplayerClockAndLateBets(t *testing.T) {
if tb.dice != [2]int{} {
t.Fatal("early shoot")
}
- tb.tickElapsed(3 * time.Second)
+ tb.advance(3)
if tb.view().ShootIn != 0 || tb.view().DealerIn != 60 {
t.Fatal(tb.view())
}
@@ -50,15 +49,15 @@ func TestCrapsMultiplayerClockAndLateBets(t *testing.T) {
if len(tb.players.get("alice").bets) != 1 {
t.Fatal("late removal rejected")
}
- if strings.Contains(crapsEventText(tb.tickElapsed(59*time.Second)), "Last call") {
+ if strings.Contains(crapsEventText(tb.advance(59)), "Last call") {
t.Fatal("warning repeated")
}
if tb.dice != [2]int{} {
t.Fatal("early forced roll")
}
- tb.tickElapsed(time.Second)
+ tb.advance(1)
if tb.dice == [2]int{} {
- t.Fatal("60 second dealer fallback missing")
+ t.Fatal("dealer fallback missing")
}
}
func TestCrapsSoloAndRosterTransitions(t *testing.T) {
@@ -66,12 +65,12 @@ func TestCrapsSoloAndRosterTransitions(t *testing.T) {
tb.join("alice")
w := &testWallet{chips: 1000}
tb.bet("alice", "fire", 1, w)
- tb.tickElapsed(500 * time.Second)
+ tb.advance(500)
if tb.dice != [2]int{} || tb.view().DealerIn != 0 || tb.view().ShootIn != 0 {
t.Fatal("solo deadline", tb.view())
}
tb.action("alice", "roll")
- tb.tickElapsed(3 * time.Second)
+ tb.advance(3)
if tb.dice == [2]int{} {
t.Fatal("solo could not roll")
}
@@ -79,7 +78,7 @@ func TestCrapsSoloAndRosterTransitions(t *testing.T) {
if tb.view().ShootIn != 10 {
t.Fatal("join did not give bettors a window")
}
- tb.tickElapsed(4 * time.Second)
+ tb.advance(4)
tb.bet("alice", "field", 10, w)
if tb.view().ShootIn != 6 {
t.Fatal("bet extended timer")
@@ -104,15 +103,15 @@ func TestCrapsAutorollPaceAndStop(t *testing.T) {
w := &testWallet{chips: 1000}
tb.bet("alice", "fire", 1, w)
tb.action("alice", "autoroll")
- tb.tickElapsed(2999 * time.Millisecond)
+ tb.advance(2)
if tb.dice != [2]int{} {
t.Fatal("autoroll fired early")
}
- tb.tickElapsed(time.Millisecond)
+ tb.advance(1)
if tb.dice == [2]int{} {
t.Fatal("autoroll did not fire")
}
- if p := tb.players.get("alice"); p.HasBet && p.autoElapsed != 0 {
+ if p := tb.players.get("alice"); p.HasBet && p.autoTicks != 0 {
t.Fatal("pace not reset")
}
handle := &Table{tableBase: tb.tableBase, game: tb}
@@ -121,7 +120,7 @@ func TestCrapsAutorollPaceAndStop(t *testing.T) {
t.Fatal("stop failed")
}
before := tb.dice
- tb.tickElapsed(500 * time.Second)
+ tb.advance(500)
if tb.dice != before || !tb.hasParticipant("alice") {
t.Fatal("stop rolled or departed")
}
@@ -134,12 +133,12 @@ func TestCrapsAutorollPaceAndStop(t *testing.T) {
w = &testWallet{chips: 100}
tb.bet("alice", "field", 10, w)
tb.action("alice", "autoroll")
- tb.tickElapsed(3 * time.Second)
+ tb.advance(3)
if tb.players.get("alice").autoRoll || tb.players.get("alice").HasBet {
t.Fatal("autoroll survived last bet")
}
before = tb.dice
- tb.tickElapsed(3 * time.Second)
+ tb.advance(3)
if tb.dice != before {
t.Fatal("extra roll after completion")
}
@@ -151,11 +150,11 @@ func TestCrapsAutorollRespectsOtherPlayers(t *testing.T) {
w := &testWallet{chips: 100}
tb.bet("alice", "field", 10, w)
tb.action("alice", "autoroll")
- tb.tickElapsed(3 * time.Second)
+ tb.advance(3)
if tb.dice != [2]int{} {
t.Fatal("autoroll stole multiplayer betting time")
}
- tb.tickElapsed(7 * time.Second)
+ tb.advance(7)
if tb.dice == [2]int{} {
t.Fatal("autoroll failed when ready")
}
@@ -166,38 +165,36 @@ func TestCrapsAutorollRespectsOtherPlayers(t *testing.T) {
w = &testWallet{chips: 100}
tb.bet("bob", "field", 10, w)
tb.action("bob", "autoroll")
- tb.tickElapsed(11 * time.Second)
+ tb.advance(11)
if tb.dice != [2]int{} {
t.Fatal("non-shooter autorolled")
}
}
-func TestCrapsManagerUsesElapsedCadence(t *testing.T) {
- for _, step := range []time.Duration{100 * time.Millisecond, 600 * time.Millisecond, time.Second} {
- m := NewManager(4)
- cfg := TableConfig{ID: "c", Game: GameCraps}
- m.Join(1, cfg, "alice")
- w := &testWallet{chips: 100}
- m.Bet(1, "c", "alice", "field", 10, w)
- m.Action(1, "c", "alice", "autoroll")
- tb := m.Table(1, "c").game.(*crapsTable)
- for elapsed := step; elapsed < 3*time.Second; elapsed += step {
- m.TickElapsed(step)
- if tb.dice != [2]int{} {
- t.Fatal("early", step)
- }
- }
- m.TickElapsed(step)
- if tb.dice == [2]int{} {
- t.Fatal("wrong cadence", step)
+func TestCrapsManagerTickCadence(t *testing.T) {
+ m := NewManager(4)
+ cfg := TableConfig{ID: "c", Game: GameCraps}
+ m.Join(1, cfg, "alice")
+ w := &testWallet{chips: 100}
+ m.Bet(1, "c", "alice", "field", 10, w)
+ m.Action(1, "c", "alice", "autoroll")
+ tb := m.Table(1, "c").game.(*crapsTable)
+ for tick := 1; tick < crapsAutoTicks; tick++ {
+ m.Tick()
+ if tb.dice != [2]int{} {
+ t.Fatal("early tick", tick)
}
}
+ m.Tick()
+ if tb.dice == [2]int{} {
+ t.Fatal("autoroll did not fire on schedule")
+ }
}
func TestCrapsConsolidatedResultsAndBetNumbers(t *testing.T) {
tb := crapsFixture()
tb.join("alice")
w := &testWallet{chips: 1000}
events := tb.bet("alice", "pass", 10, w)
- if !strings.Contains(crapsEventText(events), "ROLL OUTCOMES") {
+ if !strings.Contains(crapsEventText(events), "OUTCOMES") {
t.Fatal("no post-bet roll table")
}
tb.bet("alice", "dontpass", 10, w)