aboutsummaryrefslogtreecommitdiff
path: root/internal/game/render_craps.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/game/render_craps.go
parent4f40f116ba884111c9a66849e620ff9fbc67530a (diff)
downloadthehouseoficarus-cac16d1725c46c82a2e62b84c93f7090b2ce0746.tar.gz
feat: craps table color improvements, die improvements
Diffstat (limited to 'internal/game/render_craps.go')
-rw-r--r--internal/game/render_craps.go203
1 files changed, 108 insertions, 95 deletions
diff --git a/internal/game/render_craps.go b/internal/game/render_craps.go
index 7ec015a..ce9825f 100644
--- a/internal/game/render_craps.go
+++ b/internal/game/render_craps.go
@@ -20,8 +20,7 @@ const (
crapsMarked
crapsPuckOn
crapsPuckOff
- crapsFire
- crapsAts
+ crapsBonus
)
var crapsPaint = []color.ColorSpec{
@@ -32,8 +31,7 @@ var crapsPaint = []color.ColorSpec{
{Fg: 0, Bg: 220, Bold: true},
{Fg: 0, Bg: 15, Bold: true},
{Fg: 15, Bg: 0, Bold: true},
- {Fg: 229, Bg: 124, Bold: true}, // fire tracker: yellow on red
- {Fg: 229, Bg: 24, Bold: true}, // ATS tracker: yellow on blue
+ {Fg: 229, Bg: 24, Bold: true}, // Fire/ATS tracker: yellow on blue
}
type crapsCell struct {
@@ -94,8 +92,39 @@ func (c *crapsCanvas) text(x, y int, s string, ink int) {
func (c *crapsCanvas) center(x1, x2, y int, s string, ink int) {
c.text(x1+(x2-x1+1-color.VisibleLen(s))/2, y, s, ink)
}
+
+// crapsJoints maps a union of box edges (N=1, E=2, S=4, W=8) to its glyph.
+var crapsJoints = map[uint8]rune{3: '└', 6: '┌', 9: '┘', 12: '┐', 7: '├', 11: '┴', 13: '┤', 14: '┬', 15: '┼'}
+
+// crapsEdgeRune is the box glyph for a cell's edges, downgraded to ASCII when
+// unicode is off.
+func crapsEdgeRune(cell crapsCell, unicode bool) rune {
+ if cell.edges == 0 {
+ return ' '
+ }
+ var r rune
+ switch {
+ case cell.edges&5 == 0:
+ r = '─'
+ case cell.edges&10 == 0:
+ r = '│'
+ default:
+ r = crapsJoints[cell.edges]
+ }
+ if !unicode {
+ switch r {
+ case '─':
+ r = '-'
+ case '│':
+ r = '|'
+ default:
+ r = '+'
+ }
+ }
+ return r
+}
+
func (c *crapsCanvas) render(mode string, unicode bool) string {
- joints := map[uint8]rune{3: '└', 6: '┌', 9: '┘', 12: '┐', 7: '├', 11: '┴', 13: '┤', 14: '┬', 15: '┼'}
var out strings.Builder
for _, row := range c.cells {
var run strings.Builder
@@ -113,27 +142,7 @@ func (c *crapsCanvas) render(mode string, unicode bool) string {
}
r := cell.glyph
if r == 0 {
- r = ' '
- if cell.edges != 0 {
- switch {
- case cell.edges&5 == 0:
- r = '─'
- case cell.edges&10 == 0:
- r = '│'
- default:
- r = joints[cell.edges]
- }
- if !unicode {
- switch r {
- case '─':
- r = '-'
- case '│':
- r = '|'
- default:
- r = '+'
- }
- }
- }
+ r = crapsEdgeRune(cell, unicode)
}
run.WriteRune(r)
}
@@ -174,48 +183,38 @@ func crapsDrawPuck(c *crapsCanvas, x, y int, on, unicode bool) {
c.text(x, y+2, d, ink)
}
func renderCrapsTrackers(s *casino.CrapsSnapshot, mode string, unicode bool) string {
- c := newCrapsCanvas(12)
- // Section backgrounds first: fire red, ATS blue, yellow lettering on top.
- c.fill(0, 0, 76, 5, crapsFire)
- c.fill(0, 5, 76, 11, crapsAts)
+ c := newCrapsCanvas(7)
+ // The whole Fire/ATS tracker sits on one blue field.
+ c.fill(0, 0, 76, 6, crapsBonus)
c.box(0, 0, 76, 2)
- c.box(0, 5, 38, 8)
- c.box(38, 5, 76, 8)
- c.text(3, 1, "FIRE", crapsFire)
+ c.box(0, 4, 38, 6)
+ c.box(38, 4, 76, 6)
+ c.text(3, 1, "FIRE", crapsBonus)
for i, n := range []int{4, 5, 6, 8, 9, 10} {
- ink, mark := crapsFire, " "
+ ink := crapsBonus
if crapsHas(s.Made, n) {
- ink, mark = crapsMarked, "*"
+ ink = crapsMarked
}
- c.text(15+i*9, 1, fmt.Sprintf("[%2d%s]", n, mark), ink)
+ c.text(15+i*9, 1, fmt.Sprintf("[%2d]", n), ink)
}
bounds := []int{0, 25, 50, 76}
for i, payout := range []string{"24:1", "249:1", "999:1"} {
lo, hi := bounds[i], bounds[i+1]
- c.box(lo, 2, hi, 5)
- c.center(lo+1, hi-1, 3, fmt.Sprintf("%d DISTINCT POINTS", i+4), crapsFire)
- c.center(lo+1, hi-1, 4, payout, crapsFire)
+ c.box(lo, 2, hi, 4)
+ c.center(lo+1, hi-1, 3, fmt.Sprintf("%d POINTS %s", i+4, payout), crapsBonus)
}
- c.text(2, 6, "ALL SMALL", crapsAts)
- c.text(40, 6, "TALL", crapsAts)
+ c.text(2, 5, "SMALL", crapsBonus)
+ c.text(40, 5, "TALL", crapsBonus)
for i, n := range []int{2, 3, 4, 5, 6, 8, 9, 10, 11, 12} {
x := 12 + i*5
if i >= 5 {
x = 48 + (i-5)*5
}
- ink, mark := crapsAts, " "
+ ink := crapsBonus
if crapsHas(s.Seen, n) {
- ink, mark = crapsMarked, "*"
+ ink = crapsMarked
}
- c.text(x, 6, fmt.Sprintf("%2d%s ", n, mark), ink)
- }
- c.center(1, 37, 7, "* = rolled", crapsAts)
- c.center(39, 75, 7, "* = rolled", crapsAts)
- for i, row := range [][2]string{{"SMALL", "34:1"}, {"ALL", "175:1"}, {"TALL", "34:1"}} {
- lo, hi := bounds[i], bounds[i+1]
- c.box(lo, 8, hi, 11)
- c.center(lo+1, hi-1, 9, row[0], crapsAts)
- c.center(lo+1, hi-1, 10, row[1], crapsAts)
+ c.text(x, 5, fmt.Sprintf("[%2d]", n), ink)
}
return c.render(mode, unicode)
}
@@ -261,14 +260,16 @@ func renderCrapsFelt(s *casino.CrapsSnapshot, mode string, unicode bool) string
c.box(0, 22, 50, 25)
c.center(1, 49, 24, "FREE ODDS / BEHIND THE LINE", crapsInk)
// Centre action: four bonus spots, four hardways, six propositions, horn/hop.
- bonus := []struct {
- label, pays string
- }{{"FIRE", "24x"}, {"SMALL", "34:1"}, {"ALL", "175:1"}, {"TALL", "34:1"}}
+ // The Fire and ATS spots share one blue field.
+ bonus := []struct{ label, pays string }{{"FIRE", "24x"}, {"SMALL", "34:1"}, {"ALL", "175:1"}, {"TALL", "34:1"}}
xs := []int{50, 56, 63, 69, 76}
- for i, spot := range bonus {
+ for i := range bonus {
c.box(xs[i], 0, xs[i+1], 5)
- c.center(xs[i]+1, xs[i+1]-1, 2, spot.label, crapsGold)
- c.center(xs[i]+1, xs[i+1]-1, 4, spot.pays, crapsMuted)
+ }
+ c.fill(50, 0, 76, 5, crapsBonus)
+ for i, spot := range bonus {
+ c.center(xs[i]+1, xs[i+1]-1, 2, spot.label, crapsBonus)
+ c.center(xs[i]+1, xs[i+1]-1, 4, spot.pays, crapsBonus)
}
for i, n := range []int{4, 6, 8, 10} {
x, y := 50+(i%2)*13, 5+(i/2)*4
@@ -315,12 +316,12 @@ func renderHighPointFelt(s *casino.CrapsSnapshot, mode string, unicode bool) str
c.box(0, 0, 76, 15)
c.center(1, 75, 1, "HIGH POINT CRAPS", crapsGold)
c.center(1, 75, 2, "COME-OUT 2 OR 3: IGNORED | 11 OR 12: WINS", crapsInk)
- nums := []int{4, 5, 6, 8, 9, 10}
- labels := []string{"4", "5", "SIX", "8", "NINE", "10"}
+ nums := []int{4, 5, 6, 7, 8, 9, 10}
+ labels := []string{"4", "5", "SIX", "7", "8", "NINE", "10"}
for i, n := range nums {
- x := 2 + i*12
- c.box(x, 5, x+11, 10)
- c.center(x+1, x+10, 9, labels[i], crapsGold)
+ x := 3 + i*10
+ c.box(x, 5, x+10, 10)
+ c.center(x+1, x+9, 9, labels[i], crapsGold)
if s.Point == n {
crapsDrawPuck(c, x+3, 6, true, unicode)
}
@@ -392,47 +393,59 @@ func renderDieRichFelt(s *casino.CrapsSnapshot, mode string, unicode bool) strin
return c.render(mode, unicode)
}
-// renderCrapsDice paints each face as a white tile with black pips. The tile
-// is five interior rows tall (three pip rows plus white padding top and
-// bottom) inside a box outline, so the face reads as a square die.
+// renderCrapsDice uses half-block caps and white backgrounds to make a
+// square tile in a terminal's roughly 1:2 character cells. Pips are inset;
+// monochrome clients get an outlined face rather than disconnected dots.
func renderCrapsDice(dice [2]int, mode string, unicode bool) string {
if dice[0] < 1 || dice[0] > 6 || dice[1] < 0 || dice[1] > 6 {
return ""
}
- patterns := [][3]string{{}, {" ", " o ", " "}, {"o ", " ", " o"}, {"o ", " o ", " o"}, {"o o", " ", "o o"}, {"o o", " o ", "o o"}, {"o o", "o o", "o o"}}
- pip := "o"
- if unicode {
- pip = "●"
- }
- top, bottom, v := "+-------+", "+-------+", "|"
- if unicode {
- top, bottom, v = "╭───────╮", "╰───────╯", "│"
- }
- spec := color.ColorSpec{Fg: 0, Bg: 15, Bold: true}
+ patterns := [7][3]string{
+ {},
+ {" ", " ● ", " "},
+ {" ● ", " ", " ● "},
+ {" ● ", " ● ", " ● "},
+ {" ● ● ", " ", " ● ● "},
+ {" ● ● ", " ● ", " ● ● "},
+ {" ● ● ", " ● ● ", " ● ● "},
+ }
+ colored := mode != "" && mode != "none"
+ face := color.ColorSpec{Fg: 0, Bg: 15}
+ cap := color.ColorSpec{Fg: 15, Bg: -1}
var out strings.Builder
- for row := 0; row < 7; row++ {
+ for row := 0; row < 5; row++ {
out.WriteString(" ")
for i, n := range dice {
if n == 0 {
continue
}
- var line string
- switch row {
- case 0:
- line = top
- case 6:
- line = bottom
- case 1, 5:
- line = v + " " + v
- default:
- line = v + " " + strings.ReplaceAll(patterns[n][row-2], "o", pip) + " " + v
- }
- out.WriteString(color.Render(mode, spec, line))
- if i == 0 {
+ if i > 0 {
out.WriteString(" ")
}
+ line := ""
+ spec := face
+ if row == 0 || row == 4 {
+ line = " "
+ if unicode && colored {
+ line, spec = "▄▄▄▄▄▄▄", cap
+ if row == 4 {
+ line = "▀▀▀▀▀▀▀"
+ }
+ } else if !colored {
+ line = "+-----+"
+ }
+ } else {
+ line = patterns[n][row-1]
+ if !colored {
+ line = "|" + strings.TrimPrefix(strings.TrimSuffix(line, " "), " ") + "|"
+ }
+ if !unicode {
+ line = strings.ReplaceAll(line, "●", "o")
+ }
+ }
+ out.WriteString(color.Render(mode, spec, line))
}
- if row == 3 {
+ if row == 2 {
out.WriteString(color.Render(mode, color.ColorSpec{Fg: 229, Bg: -1, Bold: true}, fmt.Sprintf(" Total: %d", dice[0]+dice[1])))
}
out.WriteByte('\n')
@@ -506,16 +519,16 @@ func renderCrapsSnapshot(s *casino.CrapsSnapshot, mode string, unicode bool, sty
hint = ""
if s.Variant == "simplified" {
if s.ShootIn > 0 {
- hint = fmt.Sprintf("The dice roll in %ds.", s.ShootIn)
+ hint = fmt.Sprintf("The dice roll in %dt.", s.ShootIn)
}
} else if s.ShootIn > 0 {
- hint = fmt.Sprintf("Bets open. Shooter ready in %ds.", s.ShootIn)
+ hint = fmt.Sprintf("Bets open. Shooter ready in %dt.", s.ShootIn)
} else if s.DealerIn > 0 {
- hint = fmt.Sprintf("Shooter ready. Dealer rolls in %ds; bets still open.", s.DealerIn)
+ hint = fmt.Sprintf("Shooter ready. Dealer rolls in %dt; bets still open.", s.DealerIn)
}
}
if s.AutoRoll {
- hint = fmt.Sprintf("AUTOROLL / Shooter's next roll in %ds", s.AutoIn)
+ hint = fmt.Sprintf("AUTOROLL / Shooter's next roll in %dt", s.AutoIn)
}
if hint != "" {
out.WriteString(subtle(" "+hint) + "\n")