mirror of
https://github.com/lov3b/Schack.git
synced 2025-01-18 21:00:11 +01:00
loopYX
This commit is contained in:
parent
4f77dc0b33
commit
507315cefe
@ -16,8 +16,8 @@ public class Bishop extends Piece {
|
||||
LinkedHashSet<Point> movable = new LinkedHashSet<>();
|
||||
|
||||
// Upp vänster
|
||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y - 1; bishopX >= 0 && bishopY >= 0; bishopX--, bishopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x - 1, loopY = this.position.y - 1; loopX >= 0 && loopY >= 0; loopX--, loopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
@ -25,24 +25,24 @@ 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 = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x + 1, loopY = this.position.y - 1; loopX <= 7 && loopY >= 0; loopX++, loopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// Ner höger
|
||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x + 1, loopY = this.position.y + 1; loopX <= 7 && loopY <= 7; loopX++, loopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// Ner vänster
|
||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x - 1, loopY = this.position.y + 1; loopX >= 0 && loopY <= 7; loopX--, loopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ public class Board extends JPanel implements MouseListener {
|
||||
private Point selectedPiece = new Point();
|
||||
private Color moveableColor = new Color(255, 191, 0);
|
||||
private boolean turn = true;
|
||||
private LinkedHashSet<Point> whiteAttacks = new LinkedHashSet<>();
|
||||
private LinkedHashSet<Point> blackAttacks = new LinkedHashSet<>();
|
||||
|
||||
public Board() throws IOException {
|
||||
|
||||
@ -129,6 +131,8 @@ public class Board extends JPanel implements MouseListener {
|
||||
if (p.isWhite() == turn) {
|
||||
LinkedHashSet validMoves = p.validMoves(pieces);
|
||||
validMovesToDraw.addAll(validMoves);
|
||||
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
validMovesToDraw.clear();
|
||||
|
@ -110,6 +110,15 @@ public final class King extends PieceKnownIfMoved {
|
||||
addCastlingIfCan(pieces, movable, position, position);
|
||||
return movable;
|
||||
}
|
||||
|
||||
private boolean chechCheck(Piece[][] pieces, Point point ){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -16,39 +16,39 @@ public class Queen extends Piece {
|
||||
LinkedHashSet<Point> movable = new LinkedHashSet<>();
|
||||
|
||||
// Vänster
|
||||
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
|
||||
for (int loopX = this.position.x - 1; loopX >= 0; loopX--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, this.position.y), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Höger
|
||||
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
|
||||
for (int loopX = this.position.x + 1; loopX <= 7; loopX++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, this.position.y), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Ner
|
||||
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
|
||||
for (int loopY = this.position.y + 1; loopY <= 7; loopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Upp
|
||||
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
|
||||
for (int loopY = this.position.y - 1; loopY >= 0; loopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, loopY), 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 = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x - 1, loopY = this.position.y - 1; loopX >= 0 && loopY >= 0; loopX--, loopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
@ -56,24 +56,24 @@ 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 = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x + 1, loopY = this.position.y - 1; loopX <= 7 && loopY >= 0; loopX++, loopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// Ner höger
|
||||
for (int bishopX = this.position.x + 1, bishopY = this.position.y + 1; bishopX <= 7 && bishopY <= 7; bishopX++, bishopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x + 1, loopY = this.position.y + 1; loopX <= 7 && loopY <= 7; loopX++, loopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// Ner vänster
|
||||
for (int bishopX = this.position.x - 1, bishopY = this.position.y + 1; bishopX >= 0 && bishopY <= 7; bishopX--, bishopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(bishopX, bishopY), movable, pieces);
|
||||
for (int loopX = this.position.x - 1, loopY = this.position.y + 1; loopX >= 0 && loopY <= 7; loopX--, loopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
@ -19,32 +19,32 @@ public class Rook extends PieceKnownIfMoved {
|
||||
//men jag är trög och har spenderat alldles förmycket tid på att vara trög :^)
|
||||
|
||||
// Vänster
|
||||
for (int rookX = this.position.x - 1; rookX >= 0; rookX--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
|
||||
for (int loopX = this.position.x - 1; loopX >= 0; loopX--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, this.position.y), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Höger
|
||||
for (int rookX = this.position.x + 1; rookX <= 7; rookX++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(rookX, this.position.y), movable, pieces);
|
||||
for (int loopX = this.position.x + 1; loopX <= 7; loopX++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(loopX, this.position.y), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Ner
|
||||
for (int rookY = this.position.y + 1; rookY <= 7; rookY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
|
||||
for (int loopY = this.position.y + 1; loopY <= 7; loopY++) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Upp
|
||||
for (int rookY = this.position.y - 1; rookY >= 0; rookY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, rookY), movable, pieces);
|
||||
for (int loopY = this.position.y - 1; loopY >= 0; loopY--) {
|
||||
boolean shouldBreak = addMovesIfCan(new Point(this.position.x, loopY), movable, pieces);
|
||||
if (shouldBreak) {
|
||||
break;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user