fix errors
This commit is contained in:
parent
87f6595e52
commit
fef5244994
|
|
@ -73,12 +73,9 @@ public class Board {
|
|||
|
||||
public boolean isCheckmate() {
|
||||
Check check = new Check(board);
|
||||
return check.checkmate(whiteTurn);
|
||||
}
|
||||
|
||||
public void setParameters() {
|
||||
//
|
||||
return check.isCheckmate(whiteTurn);
|
||||
}
|
||||
|
||||
|
||||
// INITIALISE THE BOARD
|
||||
public void initialise() {
|
||||
|
|
@ -186,7 +183,6 @@ public class Board {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
// PROCESS THE USER CLICK
|
||||
public void userTouch(int x, int y) {
|
||||
// there have been no preselected location (no piece is selected)
|
||||
|
|
@ -202,7 +198,7 @@ public class Board {
|
|||
else {
|
||||
Move move = new Move(this.x,this.y,x,y);
|
||||
// if the new location is the same as before, de-selects the piece and no move happens
|
||||
if (this.x == x && this.y == y || board[this.y][this.x] == null) {
|
||||
if (move.noMove() || board[this.y][this.x] == null) {
|
||||
this.x = -1;
|
||||
this.y = -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public class Check {
|
|||
}
|
||||
|
||||
// return if the piece of coordinates x,y in parameter is in check or not
|
||||
public boolean check(Piece[][] board2, int x, int y, boolean white) {
|
||||
public boolean isCheck(Piece[][] board2, int x, int y, boolean white) {
|
||||
int i;
|
||||
int j;
|
||||
|
||||
|
|
@ -145,43 +145,18 @@ public class Check {
|
|||
temporaryBoard[move.getFromY()][move.getFromX()] = null;
|
||||
|
||||
// verify if in this temporary board, the king is in check
|
||||
return check(temporaryBoard, kingX, kingY, white);
|
||||
return isCheck(temporaryBoard, kingX, kingY, white);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
String str = "";
|
||||
// iterate through lines
|
||||
for (int i = 0; i < lineNum; i++) {
|
||||
// iterate through columns
|
||||
for (int j = 0; j < colNum; j++) {
|
||||
// write the corresponding letters depending on the piece on the board
|
||||
if (board[i][j] == null) {
|
||||
str += " ";
|
||||
}
|
||||
else if (board[i][j].isWhite()) {
|
||||
str += "W" + board[i][j].getType().getSummary();
|
||||
}
|
||||
else if (board[i][j].isWhite() == false) {
|
||||
str += "B" + board[i][j].getType().getSummary();
|
||||
}
|
||||
if (j != colNum-1) {
|
||||
str += ",";
|
||||
}
|
||||
}
|
||||
str += "\n";
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
// return if there is a checkmate
|
||||
public boolean checkmate(boolean turnWhite) {
|
||||
public boolean isCheckmate(boolean turnWhite) {
|
||||
MoveCalculator legalMoves = new MoveCalculator(board);
|
||||
ArrayList<int[]> moves;
|
||||
|
||||
int[] kingCoordinates = findKing(turnWhite);
|
||||
|
||||
if (check(board, kingCoordinates[0], kingCoordinates[1], turnWhite)) {
|
||||
if (isCheck(board, kingCoordinates[0], kingCoordinates[1], turnWhite)) {
|
||||
Board board2 = new Board(board);
|
||||
String state = board2.toString();
|
||||
|
||||
|
|
|
|||
|
|
@ -167,14 +167,14 @@ public class MoveCalculator {
|
|||
// the last 2 moves correspond to castling (right and left), so it verifies if the king and the (right or left) rook have never moved
|
||||
if (n == 8 && king == false && rookRight == false) {
|
||||
// verify if all the locations are empty and not threatened
|
||||
if (board[j][i-1] == null && board[j][i] == null && check.check(board,i,j,isWhite) == false && check.check(board,i-1,j,isWhite) == false) {
|
||||
if (board[j][i-1] == null && board[j][i] == null && check.isCheck(board,i,j,isWhite) == false && check.isCheck(board,i-1,j,isWhite) == false) {
|
||||
moves.add(new int[] {i, j});
|
||||
castlingRight = true;
|
||||
}
|
||||
}
|
||||
// same for the other one
|
||||
else if (n == 9 && king == false && rookLeft == false) {
|
||||
if (board[j][i+1] == null && board[j][i] == null && board[j][i-1] == null && check.check(board,i,j,isWhite) == false && check.check(board,i+1,j,isWhite) == false) {
|
||||
if (board[j][i+1] == null && board[j][i] == null && board[j][i-1] == null && check.isCheck(board,i,j,isWhite) == false && check.isCheck(board,i+1,j,isWhite) == false) {
|
||||
moves.add(new int[] {i, j});
|
||||
castlingLeft = true;
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ public class MoveCalculator {
|
|||
}
|
||||
}
|
||||
else {
|
||||
if (check.check(board, i, j, isWhite)) {
|
||||
if (check.isCheck(board, i, j, isWhite)) {
|
||||
moves.remove(k);
|
||||
k -= 1;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue