User Tools

Site Tools


chess:programming:evaluation

Chess - Programming - Evaluation

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

  • This function is often known as Evaluation Function.
  • It is sometimes also called Heuristic Function.

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.

  • But one of these moves may result in a slower victory or a faster loss:
    • Move A could win in 2 moves.
    • Move B could win in 4 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.

  • To overcome this problem the depth value is subtracted from the evaluated score.
  • This means that in case of a victory it will choose a the victory which takes less number of moves.
  • In the case of a loss it will try to prolong the game and play as many moves as possible.

So the new evaluated value will be:

  • Move A will have a value of +10 – 2 = 8
  • Move B will have a value of +10 – 4 = 6

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

  • The same thing must be applied to the minimizer.
  • Instead of subtracting the depth value, it is added as the minimizer always tries to get as negative a value as possible.
  • We can subtract the depth either inside the evaluation function or outside it.
if maximizer has won:
  return WIN_SCORE – depth
else 
if minimizer has won:
  return LOOSE_SCORE + depth  

Consider both hits and misses:

  • evalHashHits
  • evalHashMiss
  • pawnHashHits
  • pawnHashMiss

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.

chess/programming/evaluation.txt · Last modified: 2022/01/06 20:07 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki