package cagematch import ( "strconv" "strings" "gno.land/p/g1ejwp09wwnu6psem2sdwrh7l7xcldqm6zz3vu2v/cagematch/engine" ) // Render is the gnoweb entry point. Routes: "" home, "f/" a fight. func Render(path string) string { if path == "" { return renderHome() } if strings.HasPrefix(path, "f/") { id, err := strconv.Atoi(strings.TrimPrefix(path, "f/")) if err == nil && id >= 0 && id < len(fights) { return renderFight(fights[id]) } } return "Unknown page. [Cage Match home](:)" } func renderHome() string { var b strings.Builder b.WriteString("# Cage Match\n\n") b.WriteString("**AI fighters battle on-chain.** Every fighter is a small Gno package. ") b.WriteString("Every fight is resolved by this realm, deterministically: the same two fighters always produce the same result, and anyone can replay a fight from its on-chain record.\n\n") b.WriteString("Rules: 9x9 grid, 100 HP, at most 60 rounds. Each round a fighter moves, attacks (12 damage, adjacent tile), charges (next attack 24), or defends (damage halved). Points: win 3, draw 1, loss 0.\n\n") b.WriteString("## Ladder\n\n") if len(ladderOrder) == 0 { b.WriteString("No fights yet. Start one from the Actions tab with `Challenge`.\n") } else { b.WriteString("| Fighter | Points | W | D | L |\n") b.WriteString("| --- | --- | --- | --- | --- |\n") for _, e := range Leaderboard() { b.WriteString("| " + e.Name + " | " + strconv.Itoa(e.Points) + " | " + strconv.Itoa(e.Wins) + " | " + strconv.Itoa(e.Draws) + " | " + strconv.Itoa(e.Losses) + " |\n") } } if len(fights) > 0 { b.WriteString("\n## Recent fights\n\n") start := 0 if len(fights) > 10 { start = len(fights) - 10 } for i := len(fights) - 1; i >= start; i-- { f := fights[i] b.WriteString("- [Fight " + strconv.Itoa(f.ID) + "](:f/" + strconv.Itoa(f.ID) + "): " + f.A + " vs " + f.B + " — **" + winnerName(f) + "** in " + strconv.Itoa(f.Rounds) + " rounds\n") } } return b.String() } func renderFight(f *Fight) string { var b strings.Builder b.WriteString("# Fight " + strconv.Itoa(f.ID) + ": " + f.A + " vs " + f.B + "\n\n") if f.Winner < 0 { b.WriteString("**Draw** after " + strconv.Itoa(f.Rounds) + " rounds.\n\n") } else { b.WriteString("**" + winnerName(f) + " wins** in " + strconv.Itoa(f.Rounds) + " rounds.\n\n") } b.WriteString("Challenged by `" + f.Challenger.String() + "`.\n\n") b.WriteString("| Round | A | B | A HP | B HP | A dmg | B dmg |\n") b.WriteString("| --- | --- | --- | --- | --- | --- | --- |\n") for _, fr := range f.Recap.Frames { b.WriteString("| " + strconv.Itoa(fr.Round) + " | " + pos(fr.APos) + " | " + pos(fr.BPos) + " | " + strconv.Itoa(fr.AHP) + " | " + strconv.Itoa(fr.BHP) + " | " + strconv.Itoa(fr.ADmg) + " | " + strconv.Itoa(fr.BDmg) + " |\n") } b.WriteString("\nThis table is the fight. Replay it with the same two fighters and you get exactly these rows.\n") return b.String() } func pos(p engine.Pos) string { return "(" + strconv.Itoa(p.X) + "," + strconv.Itoa(p.Y) + ")" }