Home Projects Bot-vinnik Introduction Computer Chess Stockfish Twitch III CTC Filter Teaching Pendulum Outdoors Leatherworking About Me

How Computers Play Chess

Very briefly let's discuss how chess engines work. All engines are comprised of two major parts: an evaluation function and a search technique.

An evaluation function attempts to answer this question: given a position on the board, which side has the advantage and by how much? To do so, the engine might look at which side has more pieces, how safe each king is, who controls the centre of the board, and a host of other factors. Every chess engine has its own special mixture of considerations. The evaluation function returns a numerical value, with zero denoting an even game, positive numbers denoting an advantage for white and negative numbers denoting an advantage for black. The scale is somewhat arbitrary, with 1 point very roughly representing the value of a pawn. +0.35 is a modest advantage for white, -2 is an advantage for black usually sufficient to produce a win, +16 all but guarantees victory for white.

In this position (black to move), white has a bishop for black's knight, and black has an extra pawn. Bishops and knights tend to be equally powerful in chess, so considering the extra pawn and some other factors Stockfish gives the large but not necessarily decisive advantage of -1.65 to black.

Evaluation alone isn't enough to play good chess. The strength of computers comes from their ability to consider a huge number of ways in which the game might continue. In a typical position, the side to move might have 20 legal moves, each of which producing its own distinct position. The engine can apply its evaluation function to each of those 20 candidate positions and determine which is best - this would be a search of depth 1. Now each of the 20 positions might offer your opponent 20 legal moves in response, so we can repeat the process to get a search depth of 2, producing 20*20=400 candidate positions to evaluate. We can continue in this manner, seeing deeper and deeper into the future as long as we're happy evaluating an exponentially growing number of candidate positions. In practice only a few continuations are considered to any significant depth, and the judgement required to decide which to consider is a big determinant of how well the engine can play, but for our sake it's fine to assume each candidate is considered equally. Once the engine is satisfied with the depth of its search it stops, having produced a tree of possible ways the game might continue.

Now that we have our tree of possibilities, we apply the evaluation function to each of the 'leaf' positions at the end of the branches. We then and use that to update the evaluation of it's parent. We assume that we are going to play the move that results in the best possible evaluation for us, but we also assume that our opponent is going to do the same for themselves. We might have to update the evaluation of a position that initially looked great if it turns out there is even just one move our opponent can play that refutes it.

Black to move. Things look rosy for white with all the extra pieces, but black has exactly one move that wins on the spot. Ouch! The evaluation of the parent position gets changed from very good for white to a complete win for black.

The engine repeats this backtracking process all the way up its tree of positions, to ultimately determine 1) the evaluation of the current position, and 2) the best move currently available. And there you have it, the secret of the 'silicon monster': a smart way of searching to consider a tremendous number of possibilities, and an evaluation function to determine which path is best.