Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

To find neighbours

Name: Anonymous 2011-04-12 10:28

Lets suppose that we have an array which looks like this:


#(#(O O O O)
  #(O O X O)
  #(O O O O))


How would I go about to find the neighbours of 'X
without using loads of if-else ?

Name: Anonymous 2011-04-12 10:37

Let (i,j) be the position of X in the matrix.

#(#([i-1,j-1] [i-1,j] [i-1,j+1])
  #([i,j-1]   [i,j]   [i,j+1])
  #([i+1,j-1] [i+1,j] [i+1,j+1]))


You still need to check for (i,j) = (0,0)|(MAX,MAX)|(0,_)|(MAX,_)|(_,0)|(_,MAX)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List