title: Determining all the adjacent spaces on a 2D grid
body: <p>I can't seems to find a good way to solve this problem I'm working on.</p>
  
  <p>Suppose I have a point on a 2D grid describing the location of a character(board game):</p>
  
  <pre><code>                                 [n,m]
  </code></pre>
  
  <p>Now, on each turn I can move the character depending on the roll of a dice (1,2,3...), and I want to find all possible ways the character can move. </p>
  
  <p>Moving the character once means changing only <code>n</code> or <code>m</code> in which a <strong>diagonal movement counts as 2 movements</strong> (i.e. [n+1,m] moved once, [n+1,m+1] moved twice).</p>
  
  <p>For example, if I roll a 2 then all possible movements are:</p>
  
  <pre><code>                                 [n,m+2]
                          [n-1,m+1][n,m+1][n+1,m+1]
                      [n-2,m][n-1,m][n,m][n+1,m][n+2,m]
                          [n-1,m-1][n,m-1][n+1,m-1]
                                   [n,m-2]
  </code></pre>
  
  <p>I can't seem to get a clear algorithm for this.</p>
  
  <p>What I have so far is another suggestion from <a href="https://stackoverflow.com/questions/8690129/algorithm-to-find-all-points-on-a-2d-grid-some-distance-away-from-another-point">Daniel Lew</a></p>
  
  <pre><code>position = [3,2] #position
  n = 2 #number of moves allowed
  for i in range(position[0]-n,position[0]+n):
      for j in range(position[1]-n,position[1]+n):
          if abs(position[0]-i) + abs(position[1]-j) &lt;= n:
                  print i,j,'works\n'
  </code></pre>
  
  <p>However, it misses the <code>[n][m+2],[n+2,m]</code> (or the way I wrote it misses it).</p>
  
  <p>Any suggestions for concise answers or fixes?</p>