End of game detection now works fine but has made the game a lot slower.
I will imporve this with a : istherevalidmove function.
This commit is contained in:
@ -73,6 +73,7 @@ public class Board {
|
||||
private int numberOfWhitePieces = NB_OF_FILES*2;
|
||||
private int boardValue = 0; //evaluation of the board value
|
||||
|
||||
private int currentPlayer; //color of the current player.
|
||||
|
||||
/*=============*
|
||||
* CONSTRUCTOR *
|
||||
@ -141,6 +142,7 @@ public class Board {
|
||||
}
|
||||
this.enPassant = bitboard.enPassant;
|
||||
this.enPassantSquare = new Square(bitboard.enPassantSquare);
|
||||
this.currentPlayer = bitboard.currentPlayer;
|
||||
}
|
||||
|
||||
/*================*
|
||||
@ -152,10 +154,11 @@ public class Board {
|
||||
* This methods takes a {@link Move} and applies it (updating the bitboard)
|
||||
* @param move The move that is to be done
|
||||
* @throws NoPieceOnSquare If a piece is trying to be moved from a square that does not exist.
|
||||
* @throws NotAValidSquare
|
||||
* @see Move
|
||||
*/
|
||||
|
||||
public void doMove(Move move) throws NoPieceOnSquare {
|
||||
public void doMove(Move move) throws NoPieceOnSquare, NotAValidSquare {
|
||||
if (move.isCaptureMove()) {
|
||||
if (move.isEnPassant()) {
|
||||
removePiece(move.getEnPassantSquare(), move.getCapturedPiece());
|
||||
@ -176,6 +179,16 @@ public class Board {
|
||||
enPassantSquare=move.getEnPassantSquare();
|
||||
}
|
||||
|
||||
if(currentPlayer==Piece.WHITE) {
|
||||
currentPlayer=Piece.BLACK;
|
||||
if (SuicideChess.ASCII_GAME)
|
||||
System.out.println("Black: ");
|
||||
} else {
|
||||
currentPlayer=Piece.WHITE;
|
||||
if (SuicideChess.ASCII_GAME)
|
||||
System.out.println("White: ");
|
||||
}
|
||||
|
||||
evaluateNewBoardValue(move);
|
||||
}
|
||||
|
||||
@ -274,12 +287,19 @@ public class Board {
|
||||
/**
|
||||
* This function returns an integer representing the result of the static evaluation function
|
||||
* for the current board
|
||||
* @return
|
||||
* @return Integer
|
||||
*/
|
||||
public int getBoardValue() {
|
||||
return boardValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the current player color
|
||||
* @return Integer
|
||||
*/
|
||||
public int getCurrentPlayer() {
|
||||
return currentPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function can be used to display the board
|
||||
@ -402,7 +422,7 @@ public class Board {
|
||||
}
|
||||
}
|
||||
|
||||
private void evaluateNewBoardValue (Move move) {
|
||||
private void evaluateNewBoardValue (Move move) throws NotAValidSquare {
|
||||
if (move.isCaptureMove()) {
|
||||
if (move.getCapturedPiece().getColor()==Piece.BLACK) {
|
||||
numberOfBlackPieces--;
|
||||
@ -418,6 +438,7 @@ public class Board {
|
||||
boardValue = numberOfBlackPieces - numberOfWhitePieces;
|
||||
}
|
||||
}
|
||||
Rules.legalMovesForPlayer(this);
|
||||
if ((Rules.getLegalMovesCapture().size()==0)&&(Rules.getLegalMovesNonCapture().size()==0)) {
|
||||
// The following line is NOT an error !!!
|
||||
// After move from WHITE, if there is no moves for BLACK, BLACK won.
|
||||
|
Reference in New Issue
Block a user