The evaluation method
This part makes only prework for the next part, the choosing of a move. To choose a move, the AI has to evaluate positions. The AI has to find the positions that are good for it. Thereforee the evaluation method exists. The method gives a position a value.
In the evaluation method, several aspects of the position may be valued: The structure of the pawns, the occupation of the center, a positional value and the value of the material to name some. We will only value the material and the position.
We save the positional value of each field in the array
posvalues, that we define in the global namespace of the class Board:
//variables for the evaluation
float [] posvalues = {
0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.01f, 0.02f, 0.03f, 0.03f, 0.02f, 0.01f, 0.00f, 0.00f, 0.00f, 0.01f, 0.04f, 0.04f, 0.04f, 0.04f, 0.04f, 0.04f, 0.01f, 0.00f, 0.00f, 0.03f, 0.04f, 0.06f, 0.06f, 0.06f, 0.06f, 0.04f, 0.02f, 0.00f, 0.00f, 0.03f, 0.04f, 0.06f, 0.08f, 0.08f, 0.06f, 0.04f, 0.03f, 0.00f, 0.00f, 0.03f, 0.04f, 0.06f, 0.08f, 0.08f, 0.06f, 0.04f, 0.03f, 0.00f, 0.00f, 0.02f, 0.04f, 0.06f, 0.06f, 0.06f, 0.06f, 0.04f, 0.02f, 0.00f, 0.00f, 0.01f, 0.04f, 0.04f, 0.04f, 0.04f, 0.04f, 0.04f, 0.01f, 0.00f, 0.00f, 0.00f, 0.01f, 0.02f, 0.03f, 0.03f, 0.02f, 0.01f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f, 0.00f };The method
evalutation ()is definied so::
//This method evaluates a position
public float evaluation ( ) {
float value = 0;
float figur = 0;
for (int i = 21; i < 99; i++) {
if ( board [i] != 0 ) {
//material value
switch (board [i] % 10) {
case 1:
figur = 1.0f;
break;
case 2:
case 3:
figur = 3.0f;
break;
case 4:
figur = 4.5f;
break;
case 5:
figur = 9.0f;
break;
case 6:
figur = 0.0f;
}
//positional value
figur += posvalues [i];
if ( board [i] % 100 / 10 == color)
value += figur;
else
value -= figur;
}
if ( i%10 == 8)
i += 2;
}
return value;
}show applet step 7
source code of step 7