STEP 1 : Constructing “tree”
When we start the game, each player have 16 pieces. Assume now is computer turn. The computer can make 1 of 20 possible moves (2 each for the 8 pawn, plus 2 each for the knights). After that, the opponent can also make 20 possible moves. That make it we have 20*20 possible scenarios which means 400 scenarios only in two turns. Next, the computer can make another 20 possible moves to each of these 400 scenarios.
As long the game still continues, the tree will keeps growing. In theory, the perfect computer would be able to get to the very bottom of this tree, and look at all possible configurations of the board, approximately 10¹²⁰. Then, it would see which are the paths down this tree that will lead to the victory, and choose the best one for the bot.
STEP 2 : Evaluating the outcomes
Pretty sure that all of us know the problem, 10¹²⁰ is very huge number. For your information, the total estimated atoms in the universe are 10⁷⁵, in other words, the bot might still calculating its move while universe already reached its end.
The real and sufficient computers will build up this tree to the best of their hardware capabilites, like 5, or 10, or 20 or whatever moves into the future. Once they have this limited tree, they evaluate each position using an evaluation function.
The pretty simple example is an evaluation function could be the number of pieces the computer has minus number of pieces opponent has. For example, the computer has 12 pieces left on the board, while the opponent only has 8. Then the computer would evaluate such a board to 12-8 = 4.
Of course, that is not a very good evaluation function, but that is the idea. This can be made more and more complicated, taking into account of many values such as individual pieces, board position, control of the center, vulnerability of the king to check, vulnerability of the opponent’s queen, and tons of other parameters. Function can be whatever as long as it works, as it allows a computer to compare board positions, to see which are the desirable outcomes.
STEP 3 : Making a move
After doing the analysis, now it is time to make the decision, this is the example of simplified tree.Now, let’s begin the fun part.First, it starts from the most bottom level, let’s call it first level. The computer will chooses the one with maximum score. Consider the right-most square team at the first level. It has two possible outcomes 2 and 5. Since it will be the computer’s turn at that stage, it chooses the best outcome, the one with MAX score, which is 5, and so it assigns 5 to that node. Same things for other square in the same level.

#mathematics #programming #math #chess #algorithms

How Chess Algorithm Works?
1.55 GEEK