mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
Changed to Point signature
This commit is contained in:
parent
caa7ad4cef
commit
ae634b89c1
@ -19,7 +19,7 @@ public class Bishop extends Piece {
|
|||||||
|
|
||||||
// Upp vänster
|
// Upp vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ public class Bishop extends Piece {
|
|||||||
|
|
||||||
// Upp höger
|
// Upp höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ public class Bishop extends Piece {
|
|||||||
}
|
}
|
||||||
// Ner höger
|
// Ner höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ public class Bishop extends Piece {
|
|||||||
}
|
}
|
||||||
// Ner vänster
|
// Ner vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -53,8 +53,6 @@ public class Bishop extends Piece {
|
|||||||
return movable;
|
return movable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Bishop{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
return "Bishop{" + "position=" + position + ", isWhite=" + isWhite + '}';
|
||||||
|
@ -37,7 +37,7 @@ public class Horse extends Piece {
|
|||||||
|
|
||||||
for (Point pos : positions) {
|
for (Point pos : positions) {
|
||||||
// Ifall en är blockerad så ska vi inte sluta kolla
|
// Ifall en är blockerad så ska vi inte sluta kolla
|
||||||
checkMove(pos.x, pos.y, movable, pieces);
|
checkMove(pos, movable, pieces);
|
||||||
}
|
}
|
||||||
|
|
||||||
return movable;
|
return movable;
|
||||||
|
@ -61,8 +61,7 @@ public abstract class Piece extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkMove(int x, int y, LinkedHashSet movable, Piece[][] pieces) {
|
protected boolean checkMove(Point pos, LinkedHashSet movable, Piece[][] pieces) {
|
||||||
Point pos = new Point(x, y);
|
|
||||||
|
|
||||||
// Instead of checking index and null, try-catch
|
// Instead of checking index and null, try-catch
|
||||||
try {
|
try {
|
||||||
|
@ -17,7 +17,7 @@ public class Queen extends Piece {
|
|||||||
|
|
||||||
// Vänster
|
// Vänster
|
||||||
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
||||||
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ public class Queen extends Piece {
|
|||||||
|
|
||||||
// Höger
|
// Höger
|
||||||
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
||||||
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ public class Queen extends Piece {
|
|||||||
|
|
||||||
// Ner
|
// Ner
|
||||||
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
||||||
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -41,14 +41,14 @@ public class Queen extends Piece {
|
|||||||
|
|
||||||
// Upp
|
// Upp
|
||||||
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
||||||
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Upp vänster
|
// Upp vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ public class Queen extends Piece {
|
|||||||
|
|
||||||
// Upp höger
|
// Upp höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y - 1; bishopX <= 7 && bishopY >= 0; bishopX++, bishopY--) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ public class Queen extends Piece {
|
|||||||
}
|
}
|
||||||
// Ner höger
|
// Ner höger
|
||||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -73,13 +73,12 @@ public class Queen extends Piece {
|
|||||||
}
|
}
|
||||||
// Ner vänster
|
// Ner vänster
|
||||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
||||||
boolean shouldBreak = checkMove(bishopX, bishopY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(bishopX, bishopY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return movable;
|
return movable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class Rook extends Piece {
|
|||||||
|
|
||||||
// Vänster
|
// Vänster
|
||||||
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
||||||
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -29,7 +29,7 @@ public class Rook extends Piece {
|
|||||||
|
|
||||||
// Höger
|
// Höger
|
||||||
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
||||||
boolean shouldBreak = checkMove(rookX, this.position.y, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(rookX, this.position.y), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ public class Rook extends Piece {
|
|||||||
|
|
||||||
// Ner
|
// Ner
|
||||||
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
||||||
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -45,7 +45,7 @@ public class Rook extends Piece {
|
|||||||
|
|
||||||
// Upp
|
// Upp
|
||||||
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
||||||
boolean shouldBreak = checkMove(this.position.x, rookY, movable, pieces);
|
boolean shouldBreak = checkMove(new Point(this.position.x, rookY), movable, pieces);
|
||||||
if (shouldBreak) {
|
if (shouldBreak) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -55,6 +55,4 @@ public class Rook extends Piece {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user