mirror of
https://github.com/lov3b/Schack.git
synced 2025-04-18 12:20:11 +02:00

Nu går det inte längre att göra rockad till ett ställe där man står i schack, eller till ett ställe där det hade varit schack på vägen. isSelected har även blivit bytt till det mer beskrivande namnet allowedToRecurse
40 lines
1.1 KiB
Java
40 lines
1.1 KiB
Java
package schack;
|
|
|
|
import java.awt.Point;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
|
|
public abstract class LongWalkers extends PieceKnownIfMoved {
|
|
|
|
public LongWalkers(boolean isWhite, Point startingPosition) throws IOException {
|
|
super(isWhite, startingPosition);
|
|
}
|
|
|
|
/**
|
|
* Generell metod för att generera möjliga drag för LongWalkers
|
|
*
|
|
* @param directions
|
|
* @param pieces
|
|
* @param allowedToRecurse
|
|
* @return
|
|
*/
|
|
ArrayList<Point> getMoves(int[][] directions, Piece[][] pieces, boolean allowedToRecurse) {
|
|
ArrayList<Point> movable = new ArrayList<>();
|
|
|
|
for (int[] xy : directions) {
|
|
int loopX = this.position.x, loopY = this.position.y;
|
|
while (loopX + xy[0] >= 0 && loopX + xy[0] <= 7 && loopY + xy[1] >= 0 && loopY + xy[1] <= 7) {
|
|
loopX += xy[0];
|
|
loopY += xy[1];
|
|
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces, allowedToRecurse);
|
|
if (shouldBreak) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return movable;
|
|
}
|
|
|
|
}
|