chess:programming:evaluation
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
chess:programming:evaluation [2021/10/30 22:46] – created peter | chess:programming:evaluation [2022/01/06 20:07] (current) – peter | ||
---|---|---|---|
Line 12: | Line 12: | ||
---- | ---- | ||
- | [[Chess: | + | [[Chess: |
---- | ---- | ||
+ | ===== 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. | ||
+ | |||
+ | <code cpp> | ||
+ | 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. | ||
+ | |||
+ | <code cpp> | ||
+ | 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.1635634013.txt.gz · Last modified: 2021/10/30 22:46 by peter