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.

z5_tamper_and_rules_filetest.gno

1.87 Kb · 41 lines
 1// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z5
 2
 3// A bot can't change the board through its copy of it, invalid moves count
 4// as staying put, and registration rules are enforced.
 5package z5
 6
 7import (
 8	"gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/testbots"
 9	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/arena"
10	_ "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/bots/starter"
11)
12
13func main(cur realm) {
14	arena.RegisterStrategy(cross(cur), "tamper", testbots.Tamper)
15	arena.RegisterStrategy(cross(cur), "garbage", testbots.Garbage)
16	println(arena.Fight(cross(cur), "tamper", "hunter"))
17	println(arena.Fight(cross(cur), "garbage", "hunter"))
18
19	try := func(name string, f func()) { println(name+":", revive(f)) }
20	try("duplicate", func() { arena.RegisterStrategy(cross(cur), "hunter", testbots.Idle) })
21	try("bad name", func() { arena.RegisterStrategy(cross(cur), "Bad Name", testbots.Idle) })
22	try("self fight", func() { arena.Fight(cross(cur), "hunter", "hunter") })
23	try("unknown", func() { arena.Fight(cross(cur), "hunter", "nobody") })
24	arena.RegisterStrategy(cross(cur), "idle-1", testbots.Idle)
25	arena.RegisterStrategy(cross(cur), "idle-2", testbots.Idle)
26	arena.RegisterStrategy(cross(cur), "idle-3", testbots.Idle)
27	try("sixth bot", func() { arena.RegisterStrategy(cross(cur), "idle-4", testbots.Idle) })
28	try("submit on pending", func() { arena.SubmitMove(cross(cur), 1) })
29	try("replay finished", func() { arena.Play(cross(cur), 1) })
30}
31
32// Output:
33// #1 tamper 0 - 23 hunter, hunter wins
34// #2 garbage 0 - 20 hunter, hunter wins
35// duplicate: bot name already taken: hunter
36// bad name: bot names may only use a-z, 0-9 and inner dashes
37// self fight: a bot can't fight itself
38// unknown: unknown bot: nobody
39// sixth bot: this realm already registered the maximum number of bots
40// submit on pending: match is not in step mode
41// replay finished: match already finished