package mybots import ( "strconv" "strings" rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v3" ) var classNames = [5]string{"Hunter", "Brawler", "Coward", "Trickster", "Reader"} func short(addr string) string { if len(addr) < 12 { return addr } return addr[:6] + "…" + addr[len(addr)-4:] } func pct(v int) string { return strconv.Itoa((v*111+5)/10) + "%" } // Describe says what a profile does, one plain line per trait. func Describe(profile string) []string { p := rules.MustProfile(profile) keep := "never runs away" if p.Keep > 0 { keep = "when ahead, runs from a rival closer than " + strconv.Itoa(p.Keep) + " squares" } return []string{ "plays " + classNames[p.Class], "changes its plan every " + strconv.Itoa(p.Think/10) + "." + strconv.Itoa(p.Think%10) + "s", "stands still " + strconv.Itoa(p.Idle*5) + "% of the time", "chases a rival who carries gold " + pct(p.Chase) + " of the time", "goes for the jackpot " + pct(p.Jackpot) + " of the time", "looks for gold up to " + strconv.Itoa(p.Reach) + " squares away", "swings at a rival in reach: " + pct(p.Attack) + " a tick", "blocks a rival in reach: " + pct(p.Block) + " a tick", "fires its special when it pays " + pct(p.Special) + " of the time", "dodges right after being robbed " + pct(p.Dodge) + " of the time", keep, } } // Render lists the bots, or shows one at "bot/
". func Render(path string) string { var b strings.Builder if strings.HasPrefix(path, "bot/") { addr := path[4:] name, p, ok := record(addr) if !ok { return "No bot for " + short(addr) + "." } b.WriteString("# " + name + "\n\n") b.WriteString("The bot " + short(addr) + " taught by playing. It:\n\n") for _, l := range Describe(p) { b.WriteString("- " + l + "\n") } b.WriteString("\nProfile: `" + p + "`\n") return b.String() } b.WriteString("# Player bots\n\n") b.WriteString("Bots the brawler learned from how people play. Each one is a profile of eleven numbers, not code, stored as one short string. ") b.WriteString("Play a few runs, then save yours from the end screen with `Save(name, profile)`; anyone can fight it, and rooms can use it as your fallback.\n\n") if bots.Size() == 0 { b.WriteString("No bots yet.\n") return b.String() } b.WriteString("| Bot | Class | Chases | Owner |\n|---|---|---|---|\n") bots.IterateByOffset(0, 50, func(k string, v any) bool { name, p, _ := record(k) pr := rules.MustProfile(p) b.WriteString("| [" + name + "](:bot/" + k + ") | " + classNames[pr.Class] + " | " + pct(pr.Chase) + " | " + short(k) + " |\n") return false }) if n := bots.Size(); n == 1 { b.WriteString("\n1 bot.\n") } else { b.WriteString("\n" + strconv.Itoa(n) + " bots.\n") } b.WriteString("\nNeed testnet GNOT to play? Get it free at [faucet.gno.land](https://faucet.gno.land).\n") return b.String() }