Skip to content

Heuristics

The heuristics for both the WHITE and BLACK players are implemented in separate modules (whiteheuristics.py and blackheuristics.py). These heuristics assess the current state of the board and contribute to the overall fitness of the position for each player: the higher the fitness, the more favorable the move is for the player.

In order to determine the fitness of a position, the heuristics are weighted and summed together. The weights are the result of the execution of genetic.py. The weights are not optimal, but they are good enough to provide a decent performance of the AI. A more in detail description of how the genetic algorithm works can be found in Genetic Algorithm for Weight Fine-Tuning.

WHITE Heuristics

The WHITE player's heuristics include factors such as:

  1. Number of white pieces
    • The more the white pieces are, the more the heuristic value increases
  2. Number of black pieces
    • The more the black pieces are, the more the heuristic value decreases
  3. Distance of the king from the centre
    • The more the king is distant from the centre, the more the heuristic value increases
    • The euclidean distance is used for this heuristic
  4. King sorrounded by black pieces
    • If the king is sorrounded by black pieces, the heuristic value decreases
  5. Weights of each position of the board
    • Each position of the board has a weight, which is used to calculate the heuristic value
    • The winning positions are very heavy
    • The positions in which the white pawns cannot go to have negative weight

BLACK Heuristics

The BLACK player's heuristics include factors such as:

  1. Number of black pieces
    • The more the black pieces are, the more the heuristic value increases
  2. Number of white pieces
    • The less the white pieces are, the more the heuristic value decreases
  3. Number of black pawns close to the king
    • The closer are the black pawns to the king, the more the fitness value is increased
  4. Free paths to the king
    • It counts how many direct path from any black pawn to the king exists. The fitness increases linearly to the number of paths
  5. Encirclement coefficient to the king
    • A coefficient that measures how much the king is encricled. Clearly the fitness is higher when the king is a lot encircled