This section describes some aspect of static position evaluation used in KKFChess when playing a REGULAR chess game. Other chess variants will use different evaluation terms. The final evaluation score is stored into a hash table to remove the need to re-calculate if the same position occurs again.
The static position evaluation functions used in KKFChess are based on the game phase of the position. For regular chess, there are 5 phases:
Opening
Middlegame
Endgame
Near pawns only endgame
Real pawns only endgame
Mating endgame
Only the first 5 are used at present.
The material evaluation is simply the summing of the piece values that are still on the board. This is calculated incrementally by the move and unmove routines.
The piece position evaluation is also incrementally adjusted by the move and unmove routines. It comprises of adding the positional value of where each piece is on the chessboard - piece square tables.
With the basic evaluation items, the chess engine will take every opportunity to increase it's material gain and totally forsake its positional weaknesses. Sometimes this is okay but won't work against experienced players. Hence the need to add more chess knowledge into the evaluation function (and make it slower).
Most of these factors are well known chess theories.
Material balance addresses positions that arise when equal valued exchanges are made by unequal pieces, for example, rook plus pawn exchanged for two minor pieces. A bonus or penalty is added to the material evaluation based the this information.
Minor pieces have bonuses for centre control and outposts occupation. Development is also included during the opening and middlegame.
Major pieces have bonuses for occupying an open/semi-open file or being linked. It is also advantageous to have a major pieces on the enemies 2nd rank, especially when the enemy king is on the 1st.
KKFChess has a special pawn structure evaluator that understands the following basic pawn structure formations:
Pawn chains
Pawn walls
Passed pawns
Isolated pawns
Backward pawns
Weak pawns
Pawn islands
Pawn majorities (also semi-passed pawns)
Different phases of the game give different weights to each formation. For example, passed pawns are weighed more heavily in endgame and pawns-only endgames than other phases. There are other bonus and penalties such as protected passed pawns, isolated pawns with fewer pieces, etc.
Pawn structure values are hashed so that it can be referenced without recalculation.
As passed pawns can be deadly, special handling was needed, especially when few pieces are around to stop them. In a pawns-only or near pawns-only endgame, passed pawns are given bonus for being protected or able to move forward safely. The "square-rule" is also implemented to identify unstoppable passed pawns. Lastly, pawn promotion race is also coded for cases where each side has at least one unstoppable passed pawn.
King safety is included in the position evaluation when there are many enemy pieces around, typically during the opening and middlegame. The pawn shield of a castled king is the most dominating aspect of king safety, followed by open/semi-open files near the king (if major pieces are available). The proximity of enemy pieces and back rank mating threats are also included.
The king safety value is also stored into a hash table.