mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Mer beskrivande namn
This commit is contained in:
parent
ba366b1e16
commit
4f4a4e2293
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user