Comments + rechange

This commit is contained in:
lov3b 2022-03-22 19:44:45 +01:00
parent 4b92c6d388
commit 65c1e22bbe

View File

@ -19,12 +19,15 @@ public class Pawn extends Piece {
@Override @Override
public LinkedHashSet<Point> validMoves(Piece[][] pieces) { public LinkedHashSet<Point> validMoves(Piece[][] pieces) {
// TODO: Lösa bugg där bunder kanterna inte kan röra sig
LinkedHashSet<Point> movable = new LinkedHashSet<>(); LinkedHashSet<Point> movable = new LinkedHashSet<>();
// Om bonden har gått en gång, får 1 steg, annars 2 // Om bonden har gått en gång, får 1 steg, annars 2
final int upTo = hasMoved ? 1 : 2; final int upTo = hasMoved ? 1 : 2;
// Kolla om man kan rakt frak // Kolla om man kan rakt frak
for (int pawnX = 1; pawnX <= upTo; pawnX++) { for (int pawnX = 1; pawnX <= upTo; pawnX++) {
System.out.println("this.position.x: " + this.position.x);
System.out.println("calced y: " + (this.position.y + (this.isWhite ? -pawnX : pawnX)));
Point pos = new Point(this.position.x, this.position.y + (this.isWhite ? -pawnX : pawnX)); Point pos = new Point(this.position.x, this.position.y + (this.isWhite ? -pawnX : pawnX));
boolean shouldBreak = checkMove(pos, movable, pieces); boolean shouldBreak = checkMove(pos, movable, pieces);
if (shouldBreak) { if (shouldBreak) {
@ -38,7 +41,7 @@ public class Pawn extends Piece {
Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1)); Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1));
checkAttack(pos, movable, pieces); checkAttack(pos, movable, pieces);
} }
System.out.println("len of movable: " + movable.size());
return movable; return movable;
} }
@ -47,8 +50,11 @@ public class Pawn extends Piece {
Piece p = pieces[pos.x][pos.y]; Piece p = pieces[pos.x][pos.y];
// Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till // Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till
if (p != null && p.isWhite != this.isWhite) { try {
movable.add(pos); if (p.isWhite != this.isWhite) {
movable.add(pos);
}
} catch (Exception e) {
} }
} }