Version 0.4

Now plays with a grandpa minmax.
It is much better, though not excellent ;)
This commit is contained in:
2006-01-26 18:05:16 +00:00
parent 6cf9f27892
commit 5266b582bb
5 changed files with 337 additions and 160 deletions

View File

@ -10,6 +10,9 @@ import suicideChess.Square.NotAValidSquare;
* <li>a2 is square 8</li>
* <li>... and so on</li>
*
* Note that the evaluation of the board balance is in this class since I considered that it is
* very closely related to the board position.
*
* @author Jean-Baptiste H&eacute;tier
* @version $LastChangedRevision$, $LastChangedDate$
*
@ -37,7 +40,17 @@ public class Board {
NoPieceOnSquare(String s) { super(s); };
}
/**
* Value returned by the evaluation function when White wins
*/
public static final int WHITE_WINS = 99999;
/**
* Value returned by the evaluation function when Black wins
*/
public static final int BLACK_WINS = -99999;
/*======*
* DATA *
*======*/
@ -60,6 +73,9 @@ public class Board {
private boolean enPassant=false; //is there an 'en passant pawn' on the board
private Square enPassantSquare;
private int numberOfBlackPieces = NB_OF_FILES*2;
private int numberOfWhitePieces = NB_OF_FILES*2;
private int boardValue = 0; //evaluation of the board value
/*=============*
@ -111,12 +127,29 @@ public class Board {
}
/**
* A constructor that simply copies a bitboard
* @param bitboard The bitboard to be copied
*/
public Board(Board bitboard) {
this.numberOfBlackPieces = bitboard.numberOfBlackPieces;
this.numberOfWhitePieces = bitboard.numberOfWhitePieces;
this.boardValue = bitboard.boardValue;
this.bitBoards = new long[NB_OF_BITBOARDS];
for (int i=0; i<NB_OF_BITBOARDS; i++) {
this.bitBoards[i] = bitboard.bitBoards[i];
}
this.enPassant = bitboard.enPassant;
this.enPassantSquare = bitboard.enPassantSquare;
}
/*================*
* PUBLIC METHODS *
*================*/
/**
/**
* 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.
@ -130,6 +163,8 @@ public class Board {
} else {
removePiece(move.toSquare(), move.getCapturedPiece());
}
//capture moves change the value of the board
evaluateNewBoardValue(move);
}
removePiece(move.fromSquare(), move.getMovingPiece());
if (move.isPromotionMove()) {
@ -238,6 +273,17 @@ public class Board {
return enPassantSquare;
}
/**
* This function returns an integer representing the result of the static evaluation function
* for the current board
* @return
*/
public int getBoardValue() {
return boardValue;
}
/**
* This function can be used to display the board
* Black pieces are displayed in uppercase letters.
@ -358,5 +404,23 @@ public class Board {
return true;
}
}
private void evaluateNewBoardValue (Move move) {
if (move.isCaptureMove()) {
if (move.getCapturedPiece().getColor()==Piece.BLACK) {
numberOfBlackPieces--;
} else {
numberOfWhitePieces--;
}
if (numberOfBlackPieces == 0) {
boardValue = BLACK_WINS;
} else if (numberOfWhitePieces == 0){
boardValue = WHITE_WINS;
} else {
//this is a very very basic evaluation function that will be changed.
boardValue = numberOfBlackPieces - numberOfWhitePieces;
}
}
}
}