tests + ado equals override

This commit is contained in:
Janet-Doe
2025-04-16 10:55:27 +02:00
parent 3f06a9eb17
commit 076288a400
9 changed files with 89 additions and 4 deletions

View File

@@ -301,4 +301,11 @@ public class ChessBoard {
this.lastMove = lastMove;
}
@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)));
}
}

View File

@@ -28,4 +28,7 @@ public abstract class Piece {
public abstract <T> T accept(PieceVisitor<T> visitor);
@Override
public abstract boolean equals(Object other);
}

View File

@@ -20,4 +20,9 @@ public class Bishop extends Piece {
return 0;
}
@Override
public boolean equals(Piece obj) {
return (obj instanceof Bishop && ((Bishop) obj).getColor() == this.getColor());
}
}

View File

@@ -19,4 +19,9 @@ public class King extends Piece {
public int hashCode() {
return 1;
}
@Override
public boolean equals(Piece obj) {
return (obj instanceof King && ((King) obj).getColor() == this.getColor());
}
}

View File

@@ -19,4 +19,9 @@ public class Knight extends Piece {
public int hashCode() {
return 2;
}
@Override
public boolean equals(Piece obj) {
return (obj instanceof Knight && ((Knight) obj).getColor() == this.getColor());
}
}

View File

@@ -23,4 +23,9 @@ public class Pawn extends Piece {
public int hashCode() {
return 3;
}
@Override
public boolean equals(Piece obj) {
return (obj instanceof Pawn && ((Pawn) obj).getColor() == this.getColor());
}
}

View File

@@ -19,4 +19,9 @@ public class Queen extends Piece {
public int hashCode() {
return 4;
}
@Override
public boolean equals(Piece obj) {
return (obj instanceof Queen && ((Queen) obj).getColor() == this.getColor());
}
}

View File

@@ -19,4 +19,9 @@ public class Rook extends Piece {
public int hashCode() {
return 5;
}
@Override
public boolean equals(Piece obj) {
return (obj instanceof Rook && ((Rook) obj).getColor() == this.getColor());
}
}