How does chess engines work ?


I know there’s different depths but I don’t know what any of it means.

In: 0

You mean the chess AIs?

They basically try moving every piece, look at what that might do, then iterate and check every possible move they can do from that new position, then every possible position from each of THOSE positions, etc….then do that again with the next piece.

Using this web of possible actions, it picks the most advantageous.

The more moves ahead it can look, the more processing power it needs, but the “better” it can play.

There are two types of advantage in chess, Material advantage and positional advantage. Material advantage is easy, that’s who has more pieces. Positional advantage is harder to quantify but it’s who has their pieces in better spots, controlling more of the board and having more pieces developed (able to freely move around the board and not stuck behind pawns). The computer looks for the move that increases both ther material and positional advantage the most. They will even look ahead a certain number of moves depending on the time constraints and power of the computer and create what is called a markov chain (which is a ELI5 on it’s own) that will measure the strength of a move into the future not just in the current board configuration.

Chess engines are very complicated and can be built in many different ways. But the traditional way to make a chess engine is to start with a formula to evaluate a chess position. You may have been taught counting the material points on the board, pawns are worth 1 point, pieces 3, rooks 5 and the queen is worth 9 points. The chess engines use this, but also adds or subtract points for various other aspects of the position. Things like control over the centre, passed pawns, piece activity, king safety, etc. So the score they give a position is more accurate then just the material count.

But this is not enough to spot tactics. To do this they start by visualising all the legal moves they can make. For each one they calculate what the score would be after the move. Then they take some of the best moves for their opponent and visualise them. They calculate the scores again and then take some of their best moves. This goes on for a certain depth, always taking a number of best possible moves from the previous position. Eventually the engine have to decide and so it picks the line that would be best for it and make that move.

It’s better explain through a game of Tic-Tac-Toe.

So imagine a game of 3×3 TTT. You vs the Computer. The computer starts.

It has 9 possible moves. After each of these moves, it’s your turn, and you have 8 possible moves. After you played, the computer has 7 possibles moves, etc etc…

What a game computer does is list every one of those moves, until it reaches the end of the game. The end is either a draw, a computer win, or a computer loss.

Now assign a score to each state, based on how favorable it is to the computer. If it has 2 X and a Blank in a row, it’s very good, if you have to O and a Blank in a row, it’s bad. If on the next move it fills your Blank, it’s good. A win is VERY GOOD, a loss is VERY BAD.

So each state has a score assigned, and the computer will, at each move, try to maximize next step’s score, while taking into account that you will in turn try to maximize yours. This way, the computer plots an optimal path to a win.

For Tic Tac Toe it’s easy. There aren’t that many different states, and it’s easy to assign a score based on the state of the board.

For Chess it’s the same thing, except instead of plotting in advance every move up to the final state (we can’t store that much information), it will do so for the next *n* move (n being 2, 5, 10,… Chess masters can see so far as 5 moves in advance. Think of how amazing this is considering every possibility).

The main difficulty when creating those programs is finding what constitutes a good state and what’s a bad state.

Hi. I’ve been involved in chess engine testing since 1995. In simplistic terms human crafted engines use a hand made evaluation.

First determine the set of legal moves. Then a set of legal responses to each and so on. This grows into a problem so we trim lines that our evaluation say are losing.

Each line in the search tree returns a score. Highest score wins.

Piece values. Mobility. King safety. Pawn structure. Open or closed positions are are added to investigate each line.

Ai engines like alpha zero are completely different.

My username here Epanek is the panek reference in this link

This is my live stream of chess engines including those using ai derived networks.