Rook funkar nu

This commit is contained in:
loveb 2022-03-15 15:36:32 +01:00
parent ed07eecccb
commit 06f37e4097

View File

@ -20,8 +20,10 @@ public class Rook extends Piece {
//men jag är trög och har spenderat alldles förmycket tid att vara trög :^) //men jag är trög och har spenderat alldles förmycket tid att vara trög :^)
// Vänster // Vänster
for (int rookX = this.position.x; rookX >= 0; rookX--) { for (int rookX = this.position.x-1; rookX >= 0; rookX--) {
Point pos = new Point(this.position.x - rookX, this.position.y);
Point pos = new Point(rookX,this.position.y);
// Instead of checking index and null, try-catch // Instead of checking index and null, try-catch
try { try {
@ -45,8 +47,10 @@ public class Rook extends Piece {
} }
// Höger // Höger
for (int rookX = 1; rookX <= this.position.x + rookX; rookX++) { for (int rookX = this.position.x+1; rookX <= 7; rookX++) {
Point pos = new Point(this.position.x + rookX, this.position.y);
Point pos = new Point(rookX,this.position.y);
// Instead of checking index and null, try-catch // Instead of checking index and null, try-catch
try { try {
@ -69,67 +73,59 @@ public class Rook extends Piece {
} }
// for (int rookY = 0 - this.position.y; rookY < 8 - this.position.y; rookY++) { // Ner
// if (this.position.y == 0 && rookY == 0) { for (int rookY = this.position.y+1; rookY <= 7; rookY++) {
// continue;
// } Point pos = new Point(this.position.x,rookY);
// Point pos = new Point(this.position.x, this.position.y + rookY);
//
// // Instead of checking index and null, try-catch // Instead of checking index and null, try-catch
// try { try {
// Piece p = pieces[pos.x][pos.y]; Piece p = pieces[pos.x][pos.y];
// System.out.println(p); System.out.println(p);
// // If this piece is the same team as ours, skip // If this piece is the same team as ours, skip
// if (p.isWhite == this.isWhite) { if (p.isWhite == this.isWhite) {
// continue; break;
// } }
// movable.add(pos);
// movable.add(pos);
// } catch (NullPointerException npe) { break;
// // This is an empty spot
// movable.add(pos); } catch (NullPointerException npe) {
// } catch (Exception e) { // This is an empty spot
// // This means that the player is at the edge movable.add(pos);
// } } catch (Exception e) {
// } // This means that the player is at the edge
// }
// // En lista för att kolla alla vi har lagt till innan en pjäs av samma färg.
// HashSet<Point> toBeRemoved = new HashSet(); }
//
// for (int rookX = 0 - this.position.x; rookX < 8 - this.position.x; rookX++) { // Upp
// for (int rookY = this.position.y-1; rookY >= 0; rookY--) {
// if (this.position.y == 0 && rookX == 0) {
// continue; Point pos = new Point(this.position.x,rookY);
// }
// Point pos = new Point(this.position.x + rookX, this.position.y);
// // Instead of checking index and null, try-catch
// // Instead of checking index and null, try-catch try {
// try { Piece p = pieces[pos.x][pos.y];
// Piece p = pieces[pos.x][pos.y]; System.out.println(p);
// System.out.println(p); // If this piece is the same team as ours, skip
// if (p.isWhite == this.isWhite) {
// // Funkar bara åt vänster break;
// if (pieces[pos.x + 1][pos.y] != null && pieces[pos.x + 1][pos.y] != this) { }
// toBeRemoved.add(pos);
// } movable.add(pos);
// break;
// // If this piece is the same team as ours, skip
// if (p.isWhite == this.isWhite) { } catch (NullPointerException npe) {
// movable.removeAll(toBeRemoved); // This is an empty spot
// toBeRemoved.clear(); movable.add(pos);
// continue; } catch (Exception e) {
// } // This means that the player is at the edge
//// toBeRemoved.add(pos); }
// movable.add(pos);
// }
// } catch (NullPointerException npe) {
// // This is an empty spot
// movable.add(pos);
// } catch (Exception e) {
// // This means that the player is at the edge
// }
//
// }
System.out.println("Len of movable: " + movable.size()); System.out.println("Len of movable: " + movable.size());
return movable; return movable;