Rockad funkar

This commit is contained in:
loveb 2022-05-10 16:01:09 +02:00
parent 08d004b40b
commit 4cf3eeafbb
3 changed files with 20 additions and 12 deletions

View File

@ -1,4 +1,3 @@
package schack; package schack;
import java.awt.Point; import java.awt.Point;
@ -13,7 +12,7 @@ public final class King extends PieceKnownIfMoved {
} }
private void addCastlingIfCan(Piece[][] pieces, ArrayList<Point> movable, Point toMove, Point selected) { private void addCastlingIfCan(Piece[][] pieces, ArrayList<Point> movable, Point toMove, Point selected) {
if (moved) { if (isMoved()) {
return; return;
} }
@ -27,23 +26,16 @@ public final class King extends PieceKnownIfMoved {
// 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 p = pieces[loopX][this.position.y];
if (p != null) { if (p != null) {
try { if (!p.isMoved()) {
PieceKnownIfMoved PKIM = (PieceKnownIfMoved) p; movable.add(new Point(2, this.position.y));
if (!PKIM.moved) {
movable.add(new Point(2, this.position.y));
}
} catch (Exception e) {
} }
} }
} }
// 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) {
nothingInBetween = false; nothingInBetween = false;
} }
} }
// Höger // Höger
@ -52,7 +44,13 @@ 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) {
movable.add(new Point(6, this.position.y)); // Check att man bara kan göra rockad ifall tornet inte rört sig
Piece p = pieces[loopX][this.position.y];
if (p != null) {
if (!p.isMoved()) {
movable.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

View File

@ -223,4 +223,13 @@ public abstract class Piece {
return isWhite; return isWhite;
} }
/**
* Kompabilitet med PieceKnownIfMoved
*
* @return false
*/
public boolean isMoved() {
return false;
}
} }

View File

@ -17,6 +17,7 @@ public abstract class PieceKnownIfMoved extends Piece {
moved = true; moved = true;
} }
@Override
public boolean isMoved() { public boolean isMoved() {
return moved; return moved;
} }