Skip to content

Instantly share code, notes, and snippets.

@00krishna
Created January 21, 2015 03:12
Show Gist options
  • Save 00krishna/8325cef32d1f53719d54 to your computer and use it in GitHub Desktop.
Save 00krishna/8325cef32d1f53719d54 to your computer and use it in GitHub Desktop.
find adjacent cells in 2d grid
def get_adjacent_cells( self, x_coord, y_coord ):
result = {}
for x,y in [(x_coord+i,y_coord+j) for i in (-1,0,1) for j in (-1,0,1) if i != 0 or j != 0]:
if (x,y) in grid.cells:
result[(x,y)] = grid.cells[(x,y)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment