title: Programming Chess Rook Movement
body: <p>I am trying to create a board game where all the pieces are able to move the same as a rook in chess. (i.e. Horizontally or vertically as many spaces as they wish)</p>
  
  <p>My board is a simple 2d integer array, with values of 0,1,2 depending on whether the space is empty, has a red piece or a black piece.</p>
  
  <p>My code for the movement so far is shown below, it creates a true or false value if the move is allowed or not:</p>
  
  <pre class="lang-java prettyprint-override"><code>int[][] board;
  
  public boolean validMove(int fromRow, int fromCol, int toRow, int toCol) {
      if (pieceAt(toRow, toCol) != EMPTY) {
          return false;
      } else if (fromRow - toRow == 0 &amp;&amp; fromCol - toCol != 0) {
          return true;
      } else if (fromCol - toCol == 0 &amp;&amp; fromRow - toRow != 0) {
          // Trying to add piece collision code
          for (int i = fromRow; i &lt; toRow; i++) {
              if (pieceAt(toCol, i) != EMPTY)
                  return false;
          }
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>My problem is trying to create collision detection, if another piece is in the way it should not be able to move past it, however with my code currently it can. Can anyone help me do this?</p>