Skip to content

Instantly share code, notes, and snippets.

@TimToady
Created March 24, 2012 18:21
Show Gist options
  • Save TimToady/2185853 to your computer and use it in GitHub Desktop.
Save TimToady/2185853 to your computer and use it in GitHub Desktop.
use Test;
{
my @grid = [ Bool.pick xx 5 ] xx 5;
my @neigh = [ ] xx 5;
for ^5 X ^5 -> $i, $j {
@neigh[$i][$j] = gather take-rw @grid[$i + .[0]][$j + .[1]]
if 0 <= $i + .[0] < 5 and 0 <= $j + .[1] < 5
for [-1,-1],[+0,-1],[+1,-1],
[-1,+0],( ),[+1,+0],
[-1,+1],[+0,+1],[+1,+1];
}
ok @grid[1][1] =:= @neigh[2][2][0], "Neighbor is same object as in grid";
ok @neigh[1][1].elems == 8, "There are eight neighbors";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment