Table of Contents

Chess - Programming - Evaluation

A requirement is to calculate the value of the board depending on the placement of pieces on the board.

The evaluation function is unique for every type of game.

The evaluation function is combined with the minimax function or alpha-beta pruning function and so on.


Tests


Finding the Best Move

Evaluate all the available moves using minimax() or alpha-beta pruning() or similar.

Then returns the best move the maximizer can make.

function findBestMove(board):
  bestMove = NULL
  for each move in board :
    if current move is better than bestMove
      bestMove = current move
 
  return bestMove

Checking for GameOver state

To check whether the game is over and to make sure there are no moves left.

function isMovesLeft(board):
  for each cell in board:
    if current cell is empty:
      return true
 
  return false

Considering Depth

Occasionally an evaluation function will return the identical value for two possible moves.

Even though both moves evaluate to the same score, it is usually better to select the quicker move, i.e. in this case Move A.

So the new evaluated value will be:

Since move A has a higher score compared to move B means select move A over move B.

if maximizer has won:
  return WIN_SCORE – depth
else 
if minimizer has won:
  return LOOSE_SCORE + depth  

Consider both hits and misses:


Eval is adjusted towards 0 if a draw is likely.

Pawns are valued slightly less but becomes a bit more valuable in endings.

Rook & Queen on 7th rank only awarded if enemy king on 8th or enemy pawns still on 7th.