Search code examples
chessminimaxalpha-beta-pruning

How are value assigned to moves in minimax or other strategy in Chess?


I am trying to understand how values are assigned to different moves in AI chess strategy. For example user has 3 options moves pawn, queen or knight, then for each move the opponent has 3 moves. Those moves have values: move rook + 3, move Queen +2, move Pawn -3 and so on.

So, what represent these numbers, the number of moves opponent has or the item opponent can beat(if beat a rook is +2 if beat a pawn is 0)?

Sorry if my question is confusing.


Solution

  • Imaging you could play every position to the end. In that case, every final position would either be a win for white, a win for black, or a draw. Using the Minimax algorithm, you could compute for every move in your starting position whether it is won, lost or drawn.

    For instance, if white is to move next, and one of its move is winning, the previous position must be lost for black (here we assume that both players are perfect and will only play the best moves). If white has no winning moves, but some moves that draw and some that will loose, it will not play the loosing moves, so the previous position must be drawn for black. And so on, until you finally arrive at the starting position.

    However, that is not feasible as the number of possible moves explodes too fast, even if you use more advanced algorithms. That is why chess engines stop after a few moves and call an evaluation function. This function assign each position a score. These scores are the numbers that you describe in your question.

    Every engine has a unique evaluation function, but all share the most fundamental chess knowledge:

    • Material (one pawn is +100, knight/bishop +300, rook +500, and queen +900)
    • Mobility (encourages the engine to moves its pieces toward the center)
    • King safety (a weak king can be easily mated unless it is the endgame)
    • Passed pawns
    • Pawn structure (double pawns or isolated pawns should be avoided)
    • etc

    Often, the scores that you see in the output are rounded to pawns. For instance, +1.09 is an advantage of roughly one pawn. That could be because one side has one pawn more in an equal position, or it could be that the material is equal but one side has some positional advantages.