package brawl import "testing" // noisy makes a full match of inputs: hold a direction for a few ticks, // press a button now and then. func noisy(seed uint32) string { b := make([]byte, Ticks) s := seed dir, hold := 0, 0 for t := 0; t < Ticks; t++ { s = s*1103515245 + 12345 r := int(s >> 8) if hold == 0 { dir = r % 17 hold = 3 + r%8 } hold-- act := None if r%7 == 0 { act = 1 + (r>>4)%4 } b[t] = Encode(dir, act) } return string(b) } func TestInputsOnly(t *testing.T) { a, b := noisy(1), noisy(2) if len(a) != Ticks || len(b) != Ticks { t.Fatal("length") } } func TestFullMatch(t *testing.T) { a, b := noisy(1), noisy(2) ga, gb := Play(42, Hunter, Brawler, a, b) t.Logf("gold %d - %d", ga, gb) if ga+gb == 0 { t.Fatal("nobody scored") } } func TestDeterministic(t *testing.T) { a, b := noisy(5), noisy(6) x1, y1 := Play(7, Coward, Reader, a, b) x2, y2 := Play(7, Coward, Reader, a, b) if x1 != x2 || y1 != y2 { t.Fatal("replay differs") } } func TestWallsHold(t *testing.T) { for seed := uint32(0); seed < 6; seed++ { g := New(seed, Coward, Brawler) a, b := noisy(seed+10), noisy(seed+20) for i := 0; i < Ticks; i++ { m0, a0 := in(a, i) m1, a1 := in(b, i) g.Step(m0, a0, m1, a1) for s := 0; s < 2; s++ { f := g.F[s] cx, cy := f.X/U, f.Y/U if g.floor(cx, cy) == Wall { lx, ly := f.X-cx*U, f.Y-cy*U if lx > 100 && lx < 900 && ly > 100 && ly < 900 { t.Fatalf("seed %d tick %d: fighter %d inside a wall", seed, i, s) } } } } } } func TestLayouts(t *testing.T) { for arena := uint32(0); arena < 3; arena++ { g := New(arena, Hunter, Hunter) n := 0 for c := 0; c < Cells; c++ { k := g.Floor[c] if k == Empty { continue } n++ if g.Floor[Cells-1-c] != k { t.Fatalf("%s: square %d not mirrored", ArenaName(arena), c) } x, y := c%Size, c/Size if (x-1)*(x-1)+(y-1)*(y-1) <= 10 || (x-13)*(x-13)+(y-13)*(y-13) <= 10 { t.Fatalf("%s: square %d,%d too close to a start", ArenaName(arena), x, y) } if abs(x-Mid) <= 1 && abs(y-Mid) <= 1 { t.Fatalf("%s: square %d,%d in the middle", ArenaName(arena), x, y) } } want := 0 for _, l := range layouts[arena] { want += len(l) } if n != want { t.Fatalf("%s: %d squares, want %d (overlap?)", ArenaName(arena), n, want) } } }