Skip to content

Instantly share code, notes, and snippets.

@Rojoss
Created April 7, 2016 14:23
Show Gist options
  • Save Rojoss/e45d8f6bd49c2ba1d7674e6a028c49e0 to your computer and use it in GitHub Desktop.
Save Rojoss/e45d8f6bd49c2ba1d7674e6a028c49e0 to your computer and use it in GitHub Desktop.
Vector2[] findShapesInGrid(Vector2[,] grid, Vector2[,] shape) {
ArrayList matches = new ArrayList();
int x,y;
for (x = 0; x < grid.GetLength(0); x++) {
for (y = 0; y < grid.GetLength(1); y++) {
if (isShape(x,y,grid,shape)) {
matches.add(new Vector2(x,y));
}
}
}
return matches;
}
bool isShape(int x, int y, Vector2[] grid, Vector2[,] shape) {
int i,j;
for (i = 0; i < shape.GetLength(0); i++) {
for (j = 0; j < shape.GetLength(1); j++) {
if (shape[i,j] != grid[x+i,y+j]) {
return false;
}
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment