title: Check Adjacency in Triangle Array
body: <p>For a school project i had to code the cracker barrel triangle peg game, <a href="http://www.joenord.com/puzzles/peggame/3_mid_game.jpg" rel="nofollow">http://www.joenord.com/puzzles/peggame/3_mid_game.jpg</a> heres a link to what it is. I made a triangle symmetric matrix to represent the board</p>
  
  <pre><code>|\
  |0\
  |12\
  |345\
  |6789\.... 
  
  public int get( int row, int col ) 
      {
          if (row &gt;= col) // prevents array out of bounds 
              return matrix[row][col];
          else
              return matrix[col][row];
      }       // 
  </code></pre>
  
  <p>and here is my <code>get()</code> function that's the form of the matrix. if i try to access <code>get(Row, Column)</code> and <code>row&gt;column</code> i access <code>get(column, row)</code> its set that way in all my methods. This way its easier to prevent out of bounds stuff from happening. empty spots in the triangle are set to 0, all pegs are set to 1. There's unrelated reason why i didn't use a <code>Boolean</code> array. The project is a AI project and to develop a heuristic search algorithm i need access to the number of pegs adjacent to each other. I can easily prevent most duplicates by simply dividing by total/2 since it will count every adjacent in both directions. I don't know how to prevent duplicate checks when i cross that middle line. It only matters on the 0 2 5 and 9 positions. If i really wanted to i could write a separate set of rules for those positions, but that doesn't feel like good coding and is not functional for different sized triangles. any input is welcome and if you need more information feel free to ask. </p>