check draw

This commit is contained in:
2025-04-13 12:57:13 +02:00
parent 224a09c711
commit b336784a5d
15 changed files with 108 additions and 26 deletions

View File

@@ -2,6 +2,7 @@ package chess.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import chess.model.visitor.KingIdentifier;
import chess.model.visitor.PawnIdentifier;
@@ -137,20 +138,6 @@ public class ChessBoard {
}
public boolean hasAllowedMoves(Color player) {
// for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
// for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
// Coordinate attackCoords = new Coordinate(i, j);
// Piece attackPiece = pieceAt(attackCoords);
// if (attackPiece == null)
// continue;
// if (attackPiece.getColor() != player)
// continue;
// if (!getAllowedMoves(attackCoords).isEmpty())
// return true;
// }
// }
return !getAllowedMoves(player).isEmpty();
}
@@ -289,6 +276,19 @@ public class ChessBoard {
return null;
}
public int hashPlayerPieces(Color color) {
int result = 0;
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
Piece piece = pieceAt(new Coordinate(i, j));
if (piece == null || piece.getColor() != color)
continue;
result = Objects.hash(result, new Coordinate(i, j), piece);
}
}
return result;
}
public Move getLastMove() {
return this.lastMove;
}