bättre castling igen

This commit is contained in:
loveb 2022-05-12 08:39:16 +02:00
parent d5244cea94
commit 76be123a54

View File

@ -13,7 +13,7 @@ public final class King extends PieceKnownIfMoved {
private ArrayList<Point> getCastlingIfPossible(Piece[][] pieces) { private ArrayList<Point> getCastlingIfPossible(Piece[][] pieces) {
ArrayList<Point> possibleCastling = new ArrayList<>(); ArrayList<Point> possibleCastling = new ArrayList<>();
if (isMoved()) { if (this.isMoved()) {
return possibleCastling; return possibleCastling;
} }
@ -25,13 +25,11 @@ public final class King extends PieceKnownIfMoved {
if (loopX == 0 && nothingInBetween) { if (loopX == 0 && nothingInBetween) {
// Check att man bara kan göra rockad ifall tornet inte rört sig // Check att man bara kan göra rockad ifall tornet inte rört sig
Piece p = pieces[loopX][this.position.y]; Piece possibleRook = pieces[loopX][this.position.y];
if (p != null) { if (possibleRook != null && !possibleRook.isMoved()) {
if (!p.isMoved()) {
possibleCastling.add(new Point(2, this.position.y)); possibleCastling.add(new Point(2, this.position.y));
} }
} }
}
// Kolla ifall det är tomt emellan kung och torn // Kolla ifall det är tomt emellan kung och torn
if (pieces[loopX][this.position.y] != null) { if (pieces[loopX][this.position.y] != null) {
@ -46,13 +44,11 @@ public final class King extends PieceKnownIfMoved {
// Kolla ifall vi kollar tornet och inget är emellan // Kolla ifall vi kollar tornet och inget är emellan
if (loopX == 7 && nothingInBetween) { if (loopX == 7 && nothingInBetween) {
// Check att man bara kan göra rockad ifall tornet inte rört sig // Check att man bara kan göra rockad ifall tornet inte rört sig
Piece p = pieces[loopX][this.position.y]; Piece possibleRook = pieces[loopX][this.position.y];
if (p != null) { if (possibleRook != null && !possibleRook.isMoved()) {
if (!p.isMoved()) {
possibleCastling.add(new Point(6, this.position.y)); possibleCastling.add(new Point(6, this.position.y));
} }
} }
}
// Kolla ifall det är tomt emellan kung och torn // Kolla ifall det är tomt emellan kung och torn
if (pieces[loopX][this.position.y] != null) { if (pieces[loopX][this.position.y] != null) {
@ -82,7 +78,7 @@ public final class King extends PieceKnownIfMoved {
@Override @Override
public void move(Piece[][] pieces, Point toMove) { public void move(Piece[][] pieces, Point toMove) {
if (Math.abs(position.x - toMove.x) == 2) { if (Math.abs(position.x - toMove.x) == 2) {
final boolean goToLeftSide = (toMove.x < 5) ? true : false; final boolean goToLeftSide = toMove.x < 5;
castle(pieces, goToLeftSide); castle(pieces, goToLeftSide);
} else { } else {
super.move(pieces, toMove); super.move(pieces, toMove);