|
|
@ -82,6 +82,32 @@ public class ChessBoard { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean validateMove(int sourceX, int sourceY, int destX, int destY) { |
|
|
|
if (!isCellInBoard(sourceX, sourceY) || !isCellInBoard(destX, destY)) |
|
|
|
return false; |
|
|
|
ChessFigure figure = board[sourceY][sourceX]; |
|
|
|
if(board[destY][destX] == null || (board[destY][destX].getTeam() != figure.getTeam())) |
|
|
|
return false; |
|
|
|
int deltaX = destX - sourceX; |
|
|
|
int deltaY = sourceY - destY; |
|
|
|
//Pawn special case |
|
|
|
if(figure.getType() == ChessFigure.Type.PAWN){ |
|
|
|
//FUCKED Pawn can destroy Enemy backwards |
|
|
|
if((deltaX == -1 || deltaX == 1) && (deltaY == 1 || deltaY == -1) && (board[destY][destX] != null && board[destY][destX].getTeam() != figure.getTeam())) |
|
|
|
return true; |
|
|
|
if(figure.isRelativeMoveValid(deltaX, deltaY)) |
|
|
|
return true; |
|
|
|
} |
|
|
|
if(figure.isRelativeMoveValid(deltaX, deltaY)){ |
|
|
|
if(figure.getType() == ChessFigure.Type.KNIGHT) |
|
|
|
return true; |
|
|
|
if(validateCleanPath(sourceX, sourceY, destX, destY)) |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
protected boolean validateCleanPath(int sourceX, int sourceY, final int destX, final int destY) { |
|
|
|
int deltaX = destX - sourceX; |
|
|
|
int deltaY = destY - sourceY; |
|
|
|