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_spar_filetest.gno

2.54 Kb · 68 lines
 1// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z5
 2
 3// The learning loop: play a match, debrief it, learn the rival's style, then
 4// spar against that style in a solo room where each round plays as soon as
 5// you reveal.
 6package z5
 7
 8import (
 9	"strings"
10	"testing"
11
12	rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v3"
13	"gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/rooms/v3"
14)
15
16var (
17	alice = address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
18	bob   = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
19)
20
21func as(cur realm, who address) { testing.SetRealm(testing.NewUserRealm(who)) }
22
23func main(cur realm) {
24	// a 3-round match: alice plays plans, bob's Hard bot plays for him
25	as(cur, alice)
26	id := rooms.Create(cross(cur), "Alice", rules.Reader, rules.Normal, 3, 60, 15)
27	as(cur, bob)
28	rooms.Join(cross(cur), id, "Bob", rules.Hunter, rules.Hard)
29	for _, plan := range []string{"run E 40; run SE 100; special", "run N 60; special; run W 100", "run S 100; special; run E 100"} {
30		as(cur, alice)
31		rooms.Seal(cross(cur), id, rooms.PlanHash(plan, "x"))
32		testing.SkipHeights(15)
33		rooms.Advance(cross(cur), id) // to revealing
34		rooms.Reveal(cross(cur), id, plan, "x", "Sweep and magnet.")
35		testing.SkipHeights(15)
36		rooms.Advance(cross(cur), id) // bob's bot plays
37	}
38	st := rooms.StateJSON(id)
39	println("match:", st[strings.Index(st, `"gold":[`):])
40
41	db := rooms.Debrief(id, 0)
42	println("debrief rounds:", strings.Count(db, `"round":`), "advice lines:", strings.Count(db, `"advice":[`))
43	println("final:", db[strings.Index(db, `"final"`):])
44
45	style := rooms.LearnStyle(id, 1)
46	i := strings.Index(style, `"profile":"`) + 11
47	prof := style[i : i+rules.ProfileLen]
48	println("bob's style:", prof)
49
50	// alice spars against bob's style: the bot never seals, rounds play on her reveal
51	as(cur, alice)
52	sp := rooms.Spar(cross(cur), "Alice", rules.Reader, rules.Normal, prof, 3, 60, 15)
53	for _, plan := range []string{"run SE 100; special", "run E 100; special", "run S 100; special"} {
54		rooms.Seal(cross(cur), sp, rooms.PlanHash(plan, "y"))
55		rooms.Reveal(cross(cur), sp, plan, "y", "Practice.")
56	}
57	sst := rooms.StateJSON(sp)
58	println("spar:", sst[strings.Index(sst, `"phase"`):strings.Index(sst, `,"round"`)], sst[strings.Index(sst, `"gold":[`):])
59	println(strings.Contains(rooms.Render(""), "Alice vs Sparring bot"))
60}
61
62// Output:
63// match: "gold":[0,59]}
64// debrief rounds: 3 advice lines: 3
65// final: "final":[0,59],"stuckSeconds":29,"cornerSeconds":41,"robbed":0,"robs":0}
66// bob's style: c0t4i0f4j6r6a4b2s0d0k3
67// spar: "phase":"done" "gold":[3,61]}
68// true