// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z7 // Rules v3 in a room: PlanPreview models the rival by the plan they revealed // last round (their bot before that), PlanPreviewVs picks the model, guard // plays, and Compile points smart plans at Seal. package z7 import ( "strings" "testing" rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v3" "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/rooms/v3" ) var ( alice = address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm") bob = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5") ) func as(cur realm, who address) { testing.SetRealm(testing.NewUserRealm(who)) } // models lists the "rival" field of each preview. func models(pv string) string { out := []string{} for _, part := range strings.Split(pv, `"rival":"`)[1:] { out = append(out, part[:strings.Index(part, `"`)]) } return strings.Join(out, ",") } func round(cur realm, id int, pa, pb string) { as(cur, alice) rooms.Seal(cross(cur), id, rooms.PlanHash(pa, "a")) as(cur, bob) rooms.Seal(cross(cur), id, rooms.PlanHash(pb, "b")) as(cur, alice) rooms.Reveal(cross(cur), id, pa, "a", "A") as(cur, bob) rooms.Reveal(cross(cur), id, pb, "b", "B") } func main(cur realm) { as(cur, alice) id := rooms.Create(cross(cur), "Alice", rules.Reader, rules.Normal, 3, 72, 40) as(cur, bob) rooms.Join(cross(cur), id, "Bob", rules.Brawler, rules.Hard) // round 1: Bob has revealed nothing yet, so "last" falls back to his bot println("round 1:", models(rooms.PlanPreview(id, 0, "guard on; auto 240 || auto 240"))) round(cur, id, "guard on; auto 240", "chase 120; if near 1.45: attack; auto 120") // round 2: "last" replays Bob's round-1 plan; "bot" and a profile are chosen println("round 2:", models(rooms.PlanPreview(id, 0, "guard on; auto 240"))) println("vs bot:", models(rooms.PlanPreviewVs(id, 0, "guard on; auto 240", "bot"))) style := rooms.LearnStyle(id, 1) println("vs profile:", models(rooms.PlanPreviewVs(id, 0, "guard on; auto 240", style))) println(revive(func() { rooms.PlanPreviewVs(id, 0, "auto 240", "nonsense") }) != nil) round(cur, id, "guard on; collect 200; guard off; auto 40", "auto 240") round(cur, id, "guard on; auto 240", "guard on; auto 240") st := rooms.StateJSON(id) println(st[strings.Index(st, `"phase"`):][:15], st[strings.Index(st, `"gold":[`):]) println(revive(func() { rooms.Compile("collect 30", 50) })) } // Output: // round 1: bot,bot // round 2: last // vs bot: bot // vs profile: profile // true // "phase":"done", "gold":[19,28]} // plan step "collect 30": Compile only turns run, wait and buttons into keys; seal and reveal a smart plan (collect ...) as plain text