English draughts - an environment for evaluating heuristics |
The implementation of the heuristic evaluation function must be written in Java, and compliant with the following example:
package checkers; // This package is required - don't remove it
public class EvaluatePosition // This class is required - don't remove it
{
static private final int WIN=Integer.MAX_VALUE/2;
static private final int LOSE=Integer.MIN_VALUE/2;
static private boolean _color; // This field is required - don't remove it
static public void changeColor(boolean color) // This method is required - don't modify it
{
_color=color;
}
static public boolean getColor() // This method is required - don't modify it
{
return _color;
}
static public int evaluatePosition(AIBoard board)
 // This method is required and it is the main heuristic method - type your code here
{
int myRating=0;
int opponentsRating=0;
int size=board.getSize();
for (int i=0;i<size;i++)
{
for (int j=(i+1)%2;j<size;j+=2)
{
if (!board._board[i][j].empty) // field is not empty
{
if (board._board[i][j].white==getColor()) // this is my piece
{
if (board._board[i][j].king) myRating+=5; // this is my king
else myRating+=1; // this is my man
}
else
{
if (board._board[i][j].king) opponentsRating+=5; // this is opponent's king
else opponentsRating+=1;
}
}
}
}
//Judge.updateLog("Type your message here, you will see it in the log window\n");
if (myRating==0) return LOSE;
else if (opponentsRating==0) return WIN;
else return myRating-opponentsRating;
}
}
package checkers;
The implementation of the heuristic evaluation function must provide the package checkers containing the elements described below.
They are necessary for the proper operation of the heuristic in the program.
public class EvaluatePosition
The package checkers must contain a complete implementation of the class EvaluatePosition.
This class implements all the methods and fields necessary for the proper operation of the heuristic function. Its contents can be modified and extended, provided the requirements for the following methods and fields are observed.
static private boolean _color;
NOTE! This field must not be modified in any way!
The field stores the information which pieces belong to the current player. Possible values are:
void changeColor(boolean color)
NOTE! This method must not be used or modified in any way!
The method allows prescribing which pieces the current player should consider to be his. If the argument to the method takes the value:
boolean getColor()
NOTE! This method should not be modified in any way!
The method determines which pieces belong to the current player. The values returned:
int evaluatePosition(AIBoard board)
NOTE! This is the main method of heuristic! It should not be removed but its content may be modified.
The method allows to examine the state of the gameboard.
The method takes as argument the board to examine of the type AIBoard (described below).
The method returns an int value of the evaluation function for the board.
Stores a representation of the board: its size, the information which player is to move next, and the placement of the game pieces.
Piece [][] _board
Two-dimensional array that describes the game board cells (of class Piece).
The first index denotes the row and the second index denotes the column of the board, numbered from [0][0] (upper left corner), to [getSize()-1][getSize()-1] (bottom right corner).
Only those elements of the array are defined which correspond to the black (active) cells of the game board. A reference to an array element corresponding to the white (inactive) cell will return an undefined result.
boolean getMovesWhite()
The method specifies which player is next to move.
int getSize()
The method returns an int value specifying the length of either side of the game board.
Stores the representation of a game board cell: the information if it contains a game piece, which color, and whether it is a king.
boolean empty;
The field specifies whether the cell contains a piece. Its value is:
boolean king;
This field specifies whether the piece in the cell is a king. If is set to:
boolean white;
This field specifies which player owns the piece in the cell. If is set to: