Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

z1_fight_filetest.gno

5.21 Kb · 73 lines
 1// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z1
 2
 3// Starter bots and the realm bot with memory fight each other; results,
 4// ratings and pages are recorded.
 5package z1
 6
 7import (
 8	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena"
 9	_ "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/reader"
10	_ "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter"
11)
12
13func main(cur realm) {
14	println(arena.Fight(cross(cur), "hunter", "brawler"))
15	println(arena.Fight(cross(cur), "reader", "coward"))
16	println(arena.Fight(cross(cur), "brawler", "reader"))
17	println(arena.Fight(cross(cur), "hunter", "brawler")) // new board for the rematch
18	info, _ := arena.GetBot("hunter")
19	println("hunter rating:", info.Rating, "played:", info.Played)
20	println(arena.Render(""))
21}
22
23// Output:
24// #1 hunter 0 - 3 brawler, brawler wins
25// #2 reader 12 - 13 coward, coward wins
26// #3 brawler 0 - 11 reader, reader wins
27// #4 hunter 8 - 2 brawler, hunter wins (friendly)
28// hunter rating: 1184 played: 2
29// # Code Arena
30//
31// Bots are realms. Deploy one, register it, and the chain referees every match by calling each bot's code turn by turn. Every bot's source is public, so you can study a rival before you challenge it.
32//
33// **6 bots** · **4 matches** · [Start a fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=)
34//
35// ## Leaderboard
36//
37// | # | Bot | Elo | W-L-D | |
38// |---|---|---|---|---|
39// | 1 | [coward](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:bot/coward) | 1216 | 1-0-0 | [code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter$source) · [fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=coward) |
40// | 2 | [reader](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:bot/reader) | 1201 | 1-1-0 | [code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/reader$source) · [fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=reader) |
41// | 3 | [realm-crasher](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:bot/realm-crasher) | 1200 | 0-0-0 | [code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots/crasher$source) · [fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=realm-crasher) |
42// | 4 | [trickster](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:bot/trickster) | 1200 | 0-0-0 | [code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter$source) · [fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=trickster) |
43// | 5 | [brawler](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:bot/brawler) | 1199 | 1-2-0 | [code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter$source) · [fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=brawler) |
44// | 6 | [hunter](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:bot/hunter) | 1184 | 1-1-0 | [code](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter$source) · [fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=&b=hunter) |
45//
46// ## Recent matches
47//
48// - [#4 hunter 8 - 2 brawler, hunter wins (friendly)](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:match/4)
49// - [#3 brawler 0 - 11 reader, reader wins](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:match/3)
50// - [#2 reader 12 - 13 coward, coward wins](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:match/2)
51// - [#1 hunter 0 - 3 brawler, brawler wins](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena:match/1)
52//
53// ## Rules
54//
55// - 9×9 board, 50 turns. Bots start in opposite corners; coins are placed point-symmetrically, so neither corner has an advantage. A new pair of coins appears every 5 turns.
56// - Each turn both bots choose at once: `Up`, `Down`, `Left`, `Right`, `Stay`, `Attack` or `Defend`.
57// - Step on a coin to take it. Bots never share a square: if both step onto the same one, priority alternates each turn.
58// - Next to the enemy, `Attack` steals one coin. But attacking into a `Defend` is parried, and the defender takes a coin from you instead.
59// - Most gold after 50 turns wins. Ratings are Elo-style; a pair of bots plays at most one rated match every 1000 blocks, and rematches in between are friendlies.
60//
61// Each turn a bot sees the board, both scores, and what both bots did last turn, so a bot can learn its opponent's habits.
62//
63// ## Build a bot
64//
65// 1. Import [`gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bot`](/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bot) and write a `Move(bot.State) bot.Action` method (a realm bot can keep memory) or a plain function.
66// 2. Register it from your realm's `init`: `arena.RegisterBot(cross(cur), "my-bot", &myBot{})`.
67// 3. [Fight](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena$help&func=Fight&a=my-bot&b=) anyone on the leaderboard.
68//
69// Starter bots to read and beat: [strategies](/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/strategies) · [reader](/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/reader), a realm bot that learns each opponent's habits.
70//
71// ## No escaping a loss
72//
73// A crash inside a realm cancels the whole transaction, so a bot could crash on purpose to cancel a match it is losing. It doesn't work here: the match switches to step mode, one move per transaction, and a bot that can't make its move by the deadline loses by forfeit.