title: How can I simplify this code? (Chess game obstruction testing)
body: <p>I'm making a chess game in Java, and testing to make sure there are no pieces blocking the path of the piece being moved. The piece moves from (srcX,srcY) to (dstX,dstY).</p>
  
  <p>I've written this code which checks if there are any obstructions for a rook:</p>
  
  <pre><code>    if(dstY == srcY) {
  
              // No change on Y axis, so moving east or west
  
              if(dstX &gt; srcX) {
                  // Moving east
                  // Test every cell the piece will pass over
                  for(int x = srcX+1; x &lt; dstX; x++) {
                      // Is the cell set?
                      if(isPiece(x, srcY)) {
                          return true;
                      }
                  }
              } else {
                  // Must be moving west
                  // Test every cell the piece will pass over
                  for(int x = srcX-1; x &gt; dstX; x--) {
                      // Is the cell set?
                      if(isPiece(x, srcY)) {
                          return true;
                      }
                  }
              }
  
          } else if(dstX == srcX) {
  
              // No change on X axis, so moving north or south
  
              if(dstY &gt; srcY) {
                  // Moving north
                  // Test every cell the piece will pass over
                  for(int y = srcY+1; y &lt; dstY; y++) {
                      // Is the cell set?
                      if(isPiece(srcX, y)) {
                          return true;
                      }
                  }
              } else {
                  // Must be moving south
                  // Test every cell the piece will pass over
                  for(int y = srcY-1; y &gt; dstY; y--) {
                      // Is the cell set?
                      if(isPiece(srcX, y)) {
                          return true;
                      }
                  }
              }
          }
  </code></pre>
  
  <p>but it's a bit big and I'm sure it can be simplied.. any ideas?</p>
  
  <p>ps, this is ONLY obstruction testing. I've already validated everything else.</p>