From 4f4a4e2293fe67882e3a425a768a3b7c9f93e41b Mon Sep 17 00:00:00 2001 From: loveb Date: Thu, 24 Mar 2022 09:31:05 +0100 Subject: [PATCH] Mer beskrivande namn --- src/schack/Bishop.java | 8 ++++---- src/schack/Horse.java | 2 +- src/schack/Pawn.java | 8 ++++---- src/schack/Piece.java | 2 +- src/schack/Queen.java | 16 ++++++++-------- src/schack/Rook.java | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/schack/Bishop.java b/src/schack/Bishop.java index 8ceb04d..a023eae 100644 --- a/src/schack/Bishop.java +++ b/src/schack/Bishop.java @@ -17,7 +17,7 @@ public class Bishop extends Piece { // Upp vänster for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } @@ -26,7 +26,7 @@ public class Bishop extends Piece { // Upp höger for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } @@ -34,7 +34,7 @@ public class Bishop extends Piece { } // Ner höger for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } @@ -42,7 +42,7 @@ public class Bishop extends Piece { } // Ner vänster for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } diff --git a/src/schack/Horse.java b/src/schack/Horse.java index 7f4252f..77cef4a 100644 --- a/src/schack/Horse.java +++ b/src/schack/Horse.java @@ -37,7 +37,7 @@ public class Horse extends Piece { for (Point pos : positions) { // Ifall en är blockerad så ska vi inte sluta kolla - checkMove(pos, movable, pieces); + addMovesIfCan(pos, movable, pieces); } return movable; diff --git a/src/schack/Pawn.java b/src/schack/Pawn.java index 2c1735e..28dabd0 100644 --- a/src/schack/Pawn.java +++ b/src/schack/Pawn.java @@ -23,7 +23,7 @@ public class Pawn extends PieceKnownIfMoved { System.out.println("this.position.x: " + this.position.x); System.out.println("calced y: " + (this.position.y + (this.isWhite ? -pawnDY : pawnDY))); Point pos = new Point(this.position.x, this.position.y + (this.isWhite ? -pawnDY : pawnDY)); - boolean shouldBreak = checkMove(pos, movable, pieces); + boolean shouldBreak = addMovesIfCan(pos, movable, pieces); if (shouldBreak) { System.out.println("should brkje!"); break; @@ -34,14 +34,14 @@ public class Pawn extends PieceKnownIfMoved { for (int pawnX : new int[]{-1, 1}) { // Position vi kollar just nu, snett upp åt höger & vänster Point pos = new Point(this.position.x + pawnX, this.position.y + (this.isWhite ? -1 : 1)); - checkAttack(pos, movable, pieces); + addAttackMovesIfCan(pos, movable, pieces); } System.out.println("len of movable: " + movable.size()); return movable; } // Känns som det här skulle kunnat vara i validMoves, men nu är det såhär - private void checkAttack(Point pos, LinkedHashSet movable, Piece[][] pieces) { + private void addAttackMovesIfCan(Point pos, LinkedHashSet movable, Piece[][] pieces) { // Ifall det är en pjäs som står här och den inte är samma färg som oss, lägg till try { @@ -54,7 +54,7 @@ public class Pawn extends PieceKnownIfMoved { } @Override - protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) { + protected boolean addMovesIfCan(Point pos, LinkedHashSet movable, Piece[][] pieces) { if (pos.x < 0 || pos.x > 7 || pos.y < 0 || pos.y > 7) { return false; } diff --git a/src/schack/Piece.java b/src/schack/Piece.java index 797e5f5..5ba7aa1 100644 --- a/src/schack/Piece.java +++ b/src/schack/Piece.java @@ -59,7 +59,7 @@ public abstract class Piece { } } - protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) { + protected boolean addMovesIfCan(Point pos, LinkedHashSet movable, Piece[][] pieces) { // Instead of checking index and null, try-catch try { // Ifall vi kollar utanför brädet kommer detta att faila diff --git a/src/schack/Queen.java b/src/schack/Queen.java index 490ad3b..b66b032 100644 --- a/src/schack/Queen.java +++ b/src/schack/Queen.java @@ -17,7 +17,7 @@ public class Queen extends Piece { // Vänster for (int rookX = this.position.x - 1; rookX >= 0; rookX--) { - boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces); if (shouldBreak) { break; } @@ -25,7 +25,7 @@ public class Queen extends Piece { // Höger for (int rookX = this.position.x + 1; rookX <= 7; rookX++) { - boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces); if (shouldBreak) { break; } @@ -33,7 +33,7 @@ public class Queen extends Piece { // Ner for (int rookY = this.position.y + 1; rookY <= 7; rookY++) { - boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces); if (shouldBreak) { break; } @@ -41,14 +41,14 @@ public class Queen extends Piece { // Upp for (int rookY = this.position.y - 1; rookY >= 0; rookY--) { - boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces); if (shouldBreak) { break; } } // Upp vänster for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } @@ -57,7 +57,7 @@ public class Queen extends Piece { // Upp höger for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } @@ -65,7 +65,7 @@ public class Queen extends Piece { } // Ner höger for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } @@ -73,7 +73,7 @@ public class Queen extends Piece { } // Ner vänster for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) { - boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces); if (shouldBreak) { break; } diff --git a/src/schack/Rook.java b/src/schack/Rook.java index 0ec8e59..26df67a 100644 --- a/src/schack/Rook.java +++ b/src/schack/Rook.java @@ -20,7 +20,7 @@ public class Rook extends Piece { // Vänster for (int rookX = this.position.x - 1; rookX >= 0; rookX--) { - boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces); if (shouldBreak) { break; } @@ -28,7 +28,7 @@ public class Rook extends Piece { // Höger for (int rookX = this.position.x + 1; rookX <= 7; rookX++) { - boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces); if (shouldBreak) { break; } @@ -36,7 +36,7 @@ public class Rook extends Piece { // Ner for (int rookY = this.position.y + 1; rookY <= 7; rookY++) { - boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces); if (shouldBreak) { break; } @@ -44,7 +44,7 @@ public class Rook extends Piece { // Upp for (int rookY = this.position.y - 1; rookY >= 0; rookY--) { - boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces); + boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces); if (shouldBreak) { break; }