z3_mybot_filetest.gno
1.87 Kb · 61 lines
1// PKGPATH: gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/z3
2
3// Alice picks her saved bot as fallback and misses every round: her side is
4// played by her profile bot, exactly as brawl.ProfileBot plays it.
5package z3
6
7import (
8 "strconv"
9 "strings"
10 "testing"
11
12 rules "gno.land/p/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/brawl/v4"
13 "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/mybots/v4"
14 "gno.land/r/g1ftppd2jpfx0p8cy08th4u9whwvqcpychhlad28/rooms/v4"
15)
16
17var (
18 alice = address("g1wymu47drhr0kuq2098m792lytgtj2nyx77yrsm")
19 bob = address("g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5")
20)
21
22func as(cur realm, who address) { testing.SetRealm(testing.NewUserRealm(who)) }
23
24func main(cur realm) {
25 const prof = "c3t3i0f7j2r8a9b1s7d2k1"
26 as(cur, alice)
27 mybots.Save(cross(cur), "Alice Bot", prof)
28 id := rooms.Create(cross(cur), "Alice", rules.Hunter, rooms.MyBot, 4, 60, 30)
29 as(cur, bob)
30 rooms.Join(cross(cur), id, "Bob", rules.Brawler, rules.Hard)
31 for round := 0; round < 4; round++ {
32 testing.SkipHeights(30)
33 rooms.Advance(cross(cur), id)
34 }
35 in := rooms.InputsJSON(id)
36 seed, _ := strconv.Atoi(in[strings.Index(in, `"seed":`)+7 : strings.Index(in, `,"ticks"`)])
37 a := in[strings.Index(in, `"a":"`)+5:]
38 a = a[:600]
39 // the same match, played straight through by the two bots
40 g := rules.NewLength(uint32(seed), rules.Hunter, rules.Brawler, 600)
41 pa := rules.NewProfileBot(rules.MustProfile(prof), uint32(seed)+1)
42 pb := rules.NewBot(rules.Hard, uint32(seed)+2)
43 same := true
44 for t := 0; t < 600; t++ {
45 m0, a0 := pa.Act(g, 0)
46 m1, a1 := pb.Act(g, 1)
47 if rules.Encode(m0, a0) != a[t] {
48 same = false
49 }
50 g.Step(m0, a0, m1, a1)
51 }
52 println("profile bot played alice's side:", same)
53 st := rooms.StateJSON(id)
54 println(st[strings.Index(st, `"gold"`):])
55 println("straight:", g.F[0].Gold, g.F[1].Gold)
56}
57
58// Output:
59// profile bot played alice's side: true
60// "gold":[13,13]}
61// straight: 13 13