package brawl import "testing" // A match stopped, packed and restored part-way gives the same result as one // played straight through, for every arena and with bots on both sides. func TestSnapshot(t *testing.T) { for seed := uint32(3); seed < 6; seed++ { straight := NewLength(seed, Reader, Brawler, 900) a1, b1 := NewBot(Hard, seed), NewBot(Normal, seed+1) for !straight.Over() { m0, x0 := a1.Act(straight, 0) m1, x1 := b1.Act(straight, 1) straight.Step(m0, x0, m1, x1) } g := NewLength(seed, Reader, Brawler, 900) a2, b2 := NewBot(Hard, seed), NewBot(Normal, seed+1) for !g.Over() { if g.T%137 == 0 { g = Restore(g.Snapshot()) a2, b2 = RestoreBot(a2.Snapshot()), RestoreBot(b2.Snapshot()) } m0, x0 := a2.Act(g, 0) m1, x1 := b2.Act(g, 1) g.Step(m0, x0, m1, x1) } if g.F[0].Gold != straight.F[0].Gold || g.F[1].Gold != straight.F[1].Gold || g.F[0].X != straight.F[0].X { t.Fatalf("seed %d: restored %d-%d, straight %d-%d", seed, g.F[0].Gold, g.F[1].Gold, straight.F[0].Gold, straight.F[1].Gold) } t.Logf("seed %d: %d-%d, snapshot %d bytes", seed, g.F[0].Gold, g.F[1].Gold, len(g.Snapshot())) } }