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