// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z5 // The learning loop: play a match, debrief it, learn the rival's style, then // spar against that style in a solo room where each round plays as soon as // you reveal. package z5 import ( "strings" "testing" rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v2" "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/rooms/v2" ) var ( alice = address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm") bob = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") ) func as(cur realm, who address) { testing.SetRealm(testing.NewUserRealm(who)) } func main(cur realm) { // a 3-round match: alice plays plans, bob's Hard bot plays for him as(cur, alice) id := rooms.Create(cross(cur), "Alice", rules.Reader, rules.Normal, 3, 60, 15) as(cur, bob) rooms.Join(cross(cur), id, "Bob", rules.Hunter, rules.Hard) 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"} { as(cur, alice) rooms.Seal(cross(cur), id, rooms.PlanHash(plan, "x")) testing.SkipHeights(15) rooms.Advance(cross(cur), id) // to revealing rooms.Reveal(cross(cur), id, plan, "x", "Sweep and magnet.") testing.SkipHeights(15) rooms.Advance(cross(cur), id) // bob's bot plays } st := rooms.StateJSON(id) println("match:", st[strings.Index(st, `"gold":[`):]) db := rooms.Debrief(id, 0) println("debrief rounds:", strings.Count(db, `"round":`), "advice lines:", strings.Count(db, `"advice":[`)) println("final:", db[strings.Index(db, `"final"`):]) style := rooms.LearnStyle(id, 1) i := strings.Index(style, `"profile":"`) + 11 prof := style[i : i+rules.ProfileLen] println("bob's style:", prof) // alice spars against bob's style: the bot never seals, rounds play on her reveal as(cur, alice) sp := rooms.Spar(cross(cur), "Alice", rules.Reader, rules.Normal, prof, 3, 60, 15) for _, plan := range []string{"run SE 100; special", "run E 100; special", "run S 100; special"} { rooms.Seal(cross(cur), sp, rooms.PlanHash(plan, "y")) rooms.Reveal(cross(cur), sp, plan, "y", "Practice.") } sst := rooms.StateJSON(sp) println("spar:", sst[strings.Index(sst, `"phase"`):strings.Index(sst, `,"round"`)], sst[strings.Index(sst, `"gold":[`):]) println(strings.Contains(rooms.Render(""), "Alice vs Sparring bot")) } // Output: // match: "gold":[0,59]} // debrief rounds: 3 advice lines: 3 // final: "final":[0,59],"stuckSeconds":29,"cornerSeconds":41,"robbed":0,"robs":0} // bob's style: c0t4i0f4j6r6a4b2s0d0k3 // spar: "phase":"done" "gold":[3,61]} // true