change draw

This commit is contained in:
2025-04-16 11:25:31 +02:00
parent f54ddc1f59
commit ae55e0d94c
2 changed files with 17 additions and 41 deletions

View File

@@ -280,14 +280,15 @@ public class ChessBoard {
return null;
}
public int hashPlayerPieces(Color color) {
@Override
public int hashCode() {
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)
if (piece == null)
continue;
result = Objects.hash(result, new Coordinate(i, j), piece);
result = Objects.hash(result, piece.getColor(), new Coordinate(i, j), piece);
}
}
return result;
@@ -302,10 +303,10 @@ public class ChessBoard {
}
@Override
public boolean equals(Object otherBoard){
if (!(otherBoard instanceof ChessBoard)) return false;
return ((hashPlayerPieces(Color.White) == ((ChessBoard)otherBoard).hashPlayerPieces(Color.White))
&& (hashPlayerPieces(Color.Black) == ((ChessBoard)otherBoard).hashPlayerPieces(Color.Black)));
public boolean equals(Object obj){
if (obj instanceof ChessBoard board)
return board.hashCode() == this.hashCode();
return false;
}
}