package brawl import ( "strconv" "strings" rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v3" "gno.land/p/nt/ufmt/v0" ) var classNames = [5]string{"Hunter", "Brawler", "Coward", "Trickster", "Reader"} func who(g *Ghost) string { if g.Name != "" { return g.Name } s := g.Player.String() if len(s) < 12 { return s } return s[:6] + "…" + s[len(s)-4:] } // Render shows the leaderboard, or one ghost at "ghost/". func Render(path string) string { if strings.HasPrefix(path, "ghost/") { id, err := strconv.Atoi(path[6:]) if err != nil { return "Bad ghost number." } g := findGhost(id) if g == nil { return "No such ghost: it may have dropped off the top 10." } return ufmt.Sprintf("# Ghost #%d\n\n**%s** (%s) scored **%d - %d** against the Hard bot in the %s, block %d. The chain replayed the run before accepting it. You can fight this run as a ghost in the game.\n", g.ID, who(g), classNames[g.Class], g.Gold, g.BotGold, rules.ArenaName(g.Seed), int(g.Height)) } var b strings.Builder b.WriteString("# Code Arena brawl\n\n") b.WriteString("Ranked runs are against the Hard bot. Every score on this board was replayed by the chain before it counted, and each one can be fought as a ghost.\n\n") b.WriteString("## Top 10\n\n") if board[0] == "" { b.WriteString("Nobody yet. Play a ranked run against the Hard bot to get on the board.\n") } else { b.WriteString("| # | Player | Class | Gold | Hard bot | Arena | Ghost |\n|---|---|---|---|---|---|---|\n") for i, enc := range board { if enc == "" { break } g := decode(enc) b.WriteString(ufmt.Sprintf("| %d | %s | %s | %d | %d | %s | [#%d](:ghost/%d) |\n", i+1, who(g), classNames[g.Class], g.Gold, g.BotGold, rules.ArenaName(g.Seed), g.ID, g.ID)) } } b.WriteString(ufmt.Sprintf("\n%d runs so far.\n", runs)) b.WriteString("\nNeed testnet GNOT to play? Get it free at [faucet.gno.land](https://faucet.gno.land).\n") return b.String() }