jaeheonshim / ChessBoard

A Java library for working with a chess game and performing chess move validation
MIT License
34 stars 1 forks source link

Errors in Queen's movements #11

Open francogrex opened 2 years ago

francogrex commented 2 years ago

This is a good effort but it is 1) incomplete and 2) there are errors for example castling and the fen position and the queen move especially. I am for the sake of example going to highlight the latter in the class piece.Queen: This below is supposed to be the condition for diagonal move: ... ".. else if (Math.abs(start.getX() - end.getX()) == Math.abs(start.getY() - end.getY())) {" and the loop testing whether the path is clear however this is baffling (i.e. wrong) int xIndex = lowerX + 1; int yIndex = lowerY + 1; and then board.getSpot(xIndex, yIndex).getPiece() != null You aren't actually testing the diagonal and hence even if the diag path is clear for the queen, let's say for d8 to h4 (e7) being out of the way, the function returns false hence not allowing the queen a completely legal move!

francogrex commented 2 years ago

There are many other fundamental mistakes in the logic of the also for example in piece.King:

140 for (Spot spot : spots) { 141 if (spot.getPiece() != null && !(spot.getPiece() instanceof King) && spot.getPiece().isWhite() != isWhite() && spot.getPiece().canMove(board, spot, end)) { 142 end.setPiece(endTemp); 143 tempSpot.setPiece(this); 144 => return false; //if any piece on the board can kill the king after it has made its move, you will be unable to make the move. 145 } 146 } 147 }

This can work for all other pieces but not for a Pawn which moves and kills in not the same way...

Anyway, all those errors should be corrected and then you'll have a nice chess "GUI"