Conclusion

I thank you for choosing to read my light-hearted chess tutorial. If you see any errors in the information that I've provided please feel free to inform me of them. Email me at queperknuckle@yahoo.com. Keep in mind that this tutorial was not meant to write the chess game for you, but to give you some ideas just in case you might have gotten stuck somewhere like I did many times! I conclude by giving you the most complicated of the "findPiece" functions that will help you with the idea of searching the board for checks and pieces, just in case you get stuck. Good luck with your chess program and all of your other endeavors!

The findKnight() Function

    //returns start square given an end square
   public Move findKnight(Board myBoard, int playerToMove, Move m, boolean ambiguous, int startRow){
       //directional counters
       int upRow, downRow, leftCol, rightCol;
       int KnightCounter = 1;
       int upKnight = 1;
       boolean valid = true;
       boolean upValid = true;
       boolean plusvalid = true;
       boolean minusvalid = true;
       iEndRow = upRow = downRow = iKingRow = m.getEndRow();
       iEndCol = leftCol = rigthCol = iKingCol = m.getEndCol();
       while(KnightCounter<=2){
          if(ambiguous){
             if(iEndRow+upKnight == startRow)
                upValid = true;
             else
                upValid = false;
             if(iEndRow+2 == startRow)
                plusvalid = true;
             else
                plusvalid = false;
             if(iEndRow-2 == startRow)
                minusvalid = true;
             else
                minusvalid = false;
            }
             if(iEndCol+upKnight < 8 && iEndCol+upKnight>=0){
                 if((iEndRow+2) < 8){
                   if(myBoard.board[iEndRow+2][iEndCol + upKnight].getKind() == Board.KNIGHT && plusvalid){
                      if(myBoard.board[iEndRow+2][iEndCol + upKnight].getColor() == playerToMove){
                         m.setStartSquare(iEndRow+2, iEndCol+upKnight);
                        return m;
                   }
                }
             }
            if((iEndRow-2) >=0 ){
                if(myBoard.board[iEndRow - 2][iEndCol + upKnight].getKind() == Board.KNIGHT && minusvalid){
                   if(myBoard.board[iEndRow - 2][iEndCol + upKnight].getColor() == playerToMove){
                      m.setStartSquare(iEndRow-2, iEndCol+upKnight);
                        return m;
                      }
                   }
                }
             }
             if(iEndRow+upKnight<8 && iEndRow+upKnight>=0){
                if((iEndCol+2) < 8){
                   if(myBoard.board[iEndRow + upKnight][iEndCol + 2].getKind() == Board.KNIGHT && upValid){
                      if(myBoard.board[iEndRow + upKnight][iEndCol + 2].getColor() == playerToMove){
                        return m;
                      }
                   }
                }
                   if((iEndCol-2) >=0){
                      if(myBoard.board[iEndRow + upKnight][iEndCol - 2].getKind() == Board.KNIGHT && upValid){
                      if(myBoard.board[iEndRow + upKnight][iEndCol - 2].getColor() == playerToMove){
                         return m;
                      }
                   }
                }
             }
            //increment tme counter for tme second check
             ++KnightCounter;
             upKnight *= -1;
          }
       return null; //no piece found
    }//findKNIGHT