Skip to content

Instantly share code, notes, and snippets.

@nevyn
Created September 1, 2013 22:25
Show Gist options
  • Save nevyn/6407724 to your computer and use it in GitHub Desktop.
Save nevyn/6407724 to your computer and use it in GitHub Desktop.
#include <vector>
int width = 8, height = 10;
struct Tile {
bool is_wall;
} tiles[height][width];
struct Coordinate {
int x, y;
};
vector<Coordinate> neighbors(Coordinate current) {
vector<Coordinate> neighbors;
Coordinate potentials[] = {
{current.x, current.y-1},
{current.x, current.y+1},
{current.x-1, current.y},
{current.x+1, current.y},
};
for(int i = 0; i < 4; i++) {
Coordinate coordinate = potentials[i];
if(!tiles[coordinate.y][coordinate.x].is_wall)
neighbors.push_back(coordinate);
}
return neighbors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment