diff options
| author | historia <[not public]> | 2026-09-29 19:48:32 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-29 19:48:32 -0400 |
| commit | ffc7b582e9c14fdc2e579b9239b5ff7ad9a0d90a (patch) | |
| tree | e286210755094b41025f2947e412e05e59ec2ac9 /internal/game/render_roulette_tracker.go | |
| parent | 624626b9a10ae47cf7d5f6e91765570ed759bd74 (diff) | |
| download | thehouseoficarus-ffc7b582e9c14fdc2e579b9239b5ff7ad9a0d90a.tar.gz | |
feat: roulette history tracker
Diffstat (limited to 'internal/game/render_roulette_tracker.go')
| -rw-r--r-- | internal/game/render_roulette_tracker.go | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/internal/game/render_roulette_tracker.go b/internal/game/render_roulette_tracker.go new file mode 100644 index 0000000..c432924 --- /dev/null +++ b/internal/game/render_roulette_tracker.go @@ -0,0 +1,98 @@ +package game + +import ( + "fmt" + "sort" + "strconv" + "strings" + + "thehouseoficarus/internal/casino" + "thehouseoficarus/internal/color" +) + +// The tracker is descriptive, not predictive. All statistics share the same +// bounded history window; zero pockets count in the percentage denominator. +func renderRouletteTracker(s *casino.RouletteSnapshot, mode string, unicode bool) string { + const width = 72 // same 74-column footprint as the betting board + b := rouletteBorders(unicode) + ink := func(text string) string { return rouletteInk(mode, text) } + pocket := func(n string) string { + bg, name := roulettePocketColor(n) + if mode == "none" || mode == "" { + n += name[:1] + } + return roulettePaint(mode, rouletteCenter(n, 4), bg) + } + accent := func(text string, fg int) string { + return color.Render(mode, color.ColorSpec{Fg: fg, Bg: -1, Bold: true}, text) + } + counts := map[string]int{} + colors := [3]int{} // black, red, green + for _, n := range s.History { + counts[n]++ + bg, _ := roulettePocketColor(n) + colors[bg]++ + } + var recent []string + for i := len(s.History) - 1; i >= 0 && len(recent) < 8; i-- { + recent = append(recent, pocket(s.History[i])) + } + recentText := "-- awaiting the first spin --" + if len(recent) > 0 { + recentText = strings.Join(recent, " ") + ink(" newest first") + } + // Numeric tie-breaking keeps the display stable. Cold includes pockets + // not yet hit, but we never label an unhit pocket as hot. + numbers := []string{"0"} + if s.DoubleZero { + numbers = append(numbers, "00") + } + for n := 1; n <= 36; n++ { + numbers = append(numbers, strconv.Itoa(n)) + } + ranked := func(hot bool) string { + if len(s.History) == 0 { + return ink("--") + } + order := append([]string(nil), numbers...) + sort.SliceStable(order, func(i, j int) bool { + if hot { + return counts[order[i]] > counts[order[j]] + } + return counts[order[i]] < counts[order[j]] + }) + var cells []string + for _, n := range order { + if len(cells) == 3 || hot && counts[n] == 0 { + break + } + cells = append(cells, pocket(n)+ink(fmt.Sprintf("(%d)", counts[n]))) + } + return strings.Join(cells, " ") + } + percentage := func(label string, bg int) string { + value := "--" + if len(s.History) > 0 { + value = fmt.Sprintf("%.1f%%", 100*float64(colors[bg])/float64(len(s.History))) + } + return roulettePaint(mode, " "+label+" "+value+" ", bg) + } + hot := accent("Hot: ", 9) + ranked(true) + cold := accent("Cold: ", 14) + ranked(false) + ranking := hot + ink(strings.Repeat(" ", 34-color.VisibleLen(hot))+" | ") + cold + spinLabel := "spins" + if len(s.History) == 1 { + spinLabel = "spin" + } + title := fmt.Sprintf(" History: last %d %s ", len(s.History), spinLabel) + row := func(text string) string { + return ink(b.v+" ") + text + ink(strings.Repeat(" ", width-1-color.VisibleLen(text))+b.v) + } + return strings.Join([]string{ + ink(b.tl+b.h) + accent(title, 14) + ink(strings.Repeat(b.h, width-1-len(title))+b.tr), + row(ink("Recent: ") + recentText), + row(ranking), + row(percentage("Red", 1) + ink(" | ") + percentage("Black", 0) + ink(" | ") + percentage("Zero", 2)), + ink(b.bl + strings.Repeat(b.h, width) + b.br), + }, "\n") +} |
