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;
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) {
if (moved) {
if (isMoved()) {
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
Piece p = pieces[loopX][this.position.y];
if (p != null) {
try {
PieceKnownIfMoved PKIM = (PieceKnownIfMoved) p;
if (!PKIM.moved) {
if (!p.isMoved()) {
movable.add(new Point(2, this.position.y));
}
} catch (Exception e) {
}
}
}
// Kolla ifall det är tomt emellan kung och torn
if (pieces[loopX][this.position.y] != null) {
nothingInBetween = false;
}
}
// Höger
@ -52,8 +44,14 @@ public final class King extends PieceKnownIfMoved {
// Kolla ifall vi kollar tornet och inget är emellan
if (loopX == 7 && nothingInBetween) {
// 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
if (pieces[loopX][this.position.y] != null) {

View File

@ -223,4 +223,13 @@ public abstract class Piece {
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;
}
@Override
public boolean isMoved() {
return moved;
}