Merge branch 'master' of https://gitarero.ecam.fr/louise.berteloot/OOP_2A5_Project
This commit is contained in:
commit
b56780571b
|
|
@ -315,9 +315,10 @@ public class Board {
|
|||
if (king != null) {
|
||||
int kingX = king.getX();
|
||||
int kingY = king.getY();
|
||||
|
||||
for (int i = 0; i < pieces.size(); i++) {
|
||||
Piece p = pieces.get(i);
|
||||
if (p.isWhite() != whiteKing) {
|
||||
if (p.isWhite() != whiteKing && p.getType() != PieceType.King) {
|
||||
ArrayList<int[]> moves = getValidMoves(p);
|
||||
|
||||
for (int j = 0; j < moves.size(); j++) {
|
||||
|
|
@ -342,29 +343,41 @@ public class Board {
|
|||
Piece piece = pieces.get(i);
|
||||
|
||||
if (piece.isWhite() == whiteKing) {
|
||||
ArrayList<int[]> moves = getValidMoves(piece);
|
||||
ArrayList<int[]> rawMoves = getValidMoves(piece);
|
||||
|
||||
for (int j = 0; j < moves.size(); j++) {
|
||||
int[] move = moves.get(j);
|
||||
for (int j = 0; j < rawMoves.size(); j++) {
|
||||
int[] move = rawMoves.get(j);
|
||||
int newX = move[0];
|
||||
int newY = move[1];
|
||||
|
||||
// Simulate the board
|
||||
Board simBoard = new Board(this);
|
||||
Piece simPiece = simBoard.getPieceAt(piece.getX(), piece.getY());
|
||||
Piece captured = simBoard.getPieceAt(newX, newY);
|
||||
|
||||
if (captured != null) {
|
||||
simBoard.getPieces().remove(captured);
|
||||
// Find the same piece in the simulated board
|
||||
Piece simPiece = null;
|
||||
for (int k = 0; k < simBoard.getPieces().size(); k++) {
|
||||
Piece p = simBoard.getPieces().get(k);
|
||||
if (p.getX() == piece.getX() && p.getY() == piece.getY()
|
||||
&& p.getType() == piece.getType()
|
||||
&& p.isWhite() == piece.isWhite()) {
|
||||
simPiece = p;
|
||||
}
|
||||
}
|
||||
|
||||
simPiece.setX(newX);
|
||||
simPiece.setY(newY);
|
||||
if (simPiece != null) {
|
||||
Piece captured = simBoard.getPieceAt(newX, newY);
|
||||
if (captured != null) {
|
||||
simBoard.getPieces().remove(captured);
|
||||
}
|
||||
|
||||
boolean stillInCheck = simBoard.isKingInCheck(whiteKing);
|
||||
simPiece.setX(newX);
|
||||
simPiece.setY(newY);
|
||||
|
||||
if (!stillInCheck) {
|
||||
hasEscape = true;
|
||||
boolean stillInCheck = simBoard.isKingInCheck(whiteKing);
|
||||
|
||||
if (!stillInCheck) {
|
||||
hasEscape = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -167,22 +167,51 @@ public class MoveConditions {
|
|||
|
||||
int[][] offsets = {
|
||||
{-1, -1}, {-1, 0}, {-1, 1},
|
||||
{0, -1}, {0, 1},
|
||||
{1, -1}, {1, 0}, {1, 1}
|
||||
{0, -1}, {0, 1},
|
||||
{1, -1}, {1, 0}, {1, 1}
|
||||
};
|
||||
|
||||
for (int[] offset : offsets) {
|
||||
int newX = x + offset[0];
|
||||
int newY = y + offset[1];
|
||||
for (int i = 0; i < offsets.length; i++) {
|
||||
int newX = x + offsets[i][0];
|
||||
int newY = y + offsets[i][1];
|
||||
|
||||
if (newX >= 0 && newX < board.getWidth() && newY >= 0 && newY < board.getHeight()) {
|
||||
Piece target = board.getPieceAt(newX, newY);
|
||||
|
||||
if (target == null || target.isWhite() != isWhite) {
|
||||
moves.add(new int[]{newX, newY});
|
||||
Board simBoard = new Board(board);
|
||||
|
||||
// Find this same King in the simulated board
|
||||
Piece simKing = null;
|
||||
for (int j = 0; j < simBoard.getPieces().size(); j++) {
|
||||
Piece p = simBoard.getPieces().get(j);
|
||||
if (p.getX() == x && p.getY() == y &&
|
||||
p.getType() == PieceType.King &&
|
||||
p.isWhite() == isWhite) {
|
||||
simKing = p;
|
||||
}
|
||||
}
|
||||
|
||||
if (simKing != null) {
|
||||
Piece captured = simBoard.getPieceAt(newX, newY);
|
||||
if (captured != null) {
|
||||
simBoard.getPieces().remove(captured);
|
||||
}
|
||||
|
||||
simKing.setX(newX);
|
||||
simKing.setY(newY);
|
||||
|
||||
boolean stillInCheck = simBoard.isKingInCheck(isWhite);
|
||||
if (!stillInCheck) {
|
||||
moves.add(new int[]{newX, newY});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -36,7 +36,7 @@ public class SpecialMoves {
|
|||
|
||||
public boolean isEnpassant() {
|
||||
boolean isWhite = piece.isWhite();
|
||||
if (boolean isWhite == true|| PieceType getType() == PieceType.Pawn) { //no idea honestly
|
||||
if (isWhite == true || PieceType getType() == PieceType.Pawn) { //no idea honestly
|
||||
if ()
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue