diff --git a/Schack-master.7z b/Schack-master.7z deleted file mode 100644 index 3b93e3e..0000000 Binary files a/Schack-master.7z and /dev/null differ diff --git a/src/schack/Board.java b/src/schack/Board.java index 6769b8f..371b9a9 100644 --- a/src/schack/Board.java +++ b/src/schack/Board.java @@ -33,7 +33,7 @@ public class Board extends JPanel implements MouseListener { {new Rook(false, new Point(0, 0)), null, null, null, null, null, null, new Rook(true, new Point(0, 7))}, {new Horse(false, true, new Point(1, 0)), null, null, null, null, null, null, new Horse(true, true, new Point(1, 7))}, {new Bishop(false, new Point(2, 0)), null, null, null, null, null, null, new Bishop(true, new Point(2, 7))}, - {new Queen(false, new Point(3, 0)), null, null, null, null, null, null, new Queen(true, new Point(3, 7))}, + {new Queen(false, new Point(3, 0)), null, null, null, new Rook(false, new Point(3, 4)), null, null, new Queen(true, new Point(3, 7))}, {new King(false), null, null, null, null, null, null, new King(true)}, {null, null, null, null, null, null, null, new King(false, new Point(5, 7))}, {null, null, null, null, null, null, null, null}, diff --git a/src/schack/Rook.java b/src/schack/Rook.java index f0dfd53..14cb0ee 100644 --- a/src/schack/Rook.java +++ b/src/schack/Rook.java @@ -12,8 +12,40 @@ public class Rook extends Piece { } @Override - public LinkedHashSet validMoves(Piece[][] pieces) { - return new LinkedHashSet<>(); + public LinkedHashSet validMoves(Piece[][] pieces) { + LinkedHashSet movable = new LinkedHashSet<>(); +//Behöver skriva att om rookX = this.position.x så ska vi istället loopa igenom +//int rookY = 0-this.position.y; rookY < 8-this.position.Y; rookY++ +//men jag är trög och har spenderat alldles förmycket tid på att vara trög :^) + for (int rookX = 0-this.position.x; rookX < 8-this.position.x; rookX++) { + + if (this.position.y == 0 && rookX == 0) { + continue; + } + Point pos = new Point(this.position.x + rookX, this.position.y); + + // Instead of checking index and null, try-catch + try { + Piece p = pieces[pos.x][pos.y]; + System.out.println(p); + // If this piece is the same team as ours, skip + if (p.isWhite == this.isWhite) { + continue; + } + 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()); + return movable; + }