aboutsummaryrefslogtreecommitdiff
path: root/internal/casino/craps_projection.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/casino/craps_projection.go')
-rw-r--r--internal/casino/craps_projection.go35
1 files changed, 31 insertions, 4 deletions
diff --git a/internal/casino/craps_projection.go b/internal/casino/craps_projection.go
index 1377452..65f09ce 100644
--- a/internal/casino/craps_projection.go
+++ b/internal/casino/craps_projection.go
@@ -99,7 +99,9 @@ func crapsBonusComplete(lo, hi int, seen map[int]bool, next int) bool {
// rollTable previews the next roll as one compact line of every total 2-12
// (1-6 on the single-die table): wins are bold green, losses bold red, and
// totals no open wager settles are dim. Hardway and hop bets are pair
-// specific, so the best pair outcome stands in for that total.
+// specific, so the best pair outcome stands in for that total. The line wraps
+// on token boundaries with a hanging indent so the continuation lines line up
+// under the first total.
func (t *crapsTable) rollTable(p *crapsPlayer) string {
if len(p.bets) == 0 {
return ""
@@ -116,8 +118,11 @@ func (t *crapsTable) rollTable(p *crapsPlayer) string {
if t.Config.Craps.variant() == "die_rich" {
lo, hi = 1, 6
}
- var sb strings.Builder
- sb.WriteString("{casino_emphasis}ROLL OUTCOMES{/}:")
+ type outcomeToken struct {
+ tagged string
+ width int
+ }
+ tokens := make([]outcomeToken, 0, hi-lo+1)
for total := lo; total <= hi; total++ {
token := fmt.Sprintf("%d(-)", total)
tag := "dim"
@@ -127,7 +132,29 @@ func (t *crapsTable) rollTable(p *crapsPlayer) string {
case found[total] && best[total] < 0:
token, tag = fmt.Sprintf("%d(%d)", total, best[total]), "casino_result_loss"
}
- fmt.Fprintf(&sb, " {%s}%s{/}", tag, token)
+ tokens = append(tokens, outcomeToken{fmt.Sprintf("{%s}%s{/}", tag, token), len(token)})
+ }
+ const (
+ head = "OUTCOMES:"
+ width = 80
+ )
+ indent := strings.Repeat(" ", len(head)+1)
+ var sb strings.Builder
+ sb.WriteString("{casino_emphasis}" + head + "{/}")
+ lineLen := len(head)
+ for i, tk := range tokens {
+ // The first token always follows the heading; later tokens wrap whole,
+ // never splitting a total from its payout.
+ if i > 0 && lineLen+1+tk.width > width {
+ sb.WriteString("\n" + indent)
+ lineLen = len(indent)
+ sb.WriteString(tk.tagged)
+ lineLen += tk.width
+ continue
+ }
+ sb.WriteByte(' ')
+ sb.WriteString(tk.tagged)
+ lineLen += 1 + tk.width
}
return sb.String()
}