lichess.org
Donate
Based on my creativity

pixabay.com

How does a chess engine work in detail?

ChessAnalysisChess engineSoftware Development
At the heart of modern chess preparation lies powerful analysis software that seems to play with an otherworldly ability. But how do the likes of Stockfish, Komodo and other top engines actually work their magic?

Contents

  1. Introduction to Chess Engines
  2. Minimax Algorithm and Game Trees
  3. Alpha-Beta Pruning
  4. Move Ordering
  5. Iterative Deepening
  6. Evaluation Functions
  7. Position Evaluation via NNUE
  8. Transposition Tables
  9. Opening Books
  10. Endgame Tablebases
  11. Cloud Analysis
  12. Machine Learning and Self-Play
  13. Contempt Factor and Risk Settings
  14. Engine Strength Measurement
  15. Conclusion - Appreciating the Magic
  16. Join the community

1. Introduction to Chess Engines

Chess engines are key players in modern chess. But what are they exactly? Essentially, they are computer programs specifically designed to play chess autonomously and at a high level. They utilize advanced artificial intelligence algorithms to evaluate billions of possible positions and consistently choose the best-calculated move.

While they have been in development since the mid-20th century, it wasn't until the late '90s and early 2000s that they reached the strength of a human Grandmaster. In a very short time, they continued to grow exponentially, surpassing any human. Incredible!

2. The MiniMax Algorithm and Game Trees

To understand how engines analyze so many possibilities without going crazy, one must grasp the algorithm called "minimax." This algorithm explores all future possibilities that unfold after each move, creating a gigantic "tree" of potential variations.

It assigns a numerical value to each final position reached, measuring how favorable it is for each side. This way, it can compare billions of hypothetical futures, choosing at each step the branch that optimizes its own chances of victory.

3. Alpha-Beta Pruning

But even the fastest computers couldn't explore all possible futures without a clever shortcut: alpha-beta pruning. This identifies branches in the analysis tree that we already know will not lead to better results and simply cuts them off, saving precious time.

A small sacrifice of accuracy allows us to gain orders of magnitude in depth. Instead of 20 moves ahead, we can suddenly read 40 or more!

4. Move Ordering

Another significant optimization is to first analyze, at each node, the moves that are most likely to be the best. This also significantly speeds up the search and allows for more efficient pruning.

Heuristics and the expertise of human Masters are used to define rules that assign scores and order candidate moves, guiding the exploration toward the most promising ones.

5. Iterative Deepening

And to squeeze every bit of available computational power, engines use iterative searches, where they repeatedly extend the depth of analysis on the same positions, readjusting values with each pass.

They first examine immediate moves and then delve deeper and deeper into the variations. Wonderful optimization! Each time, we better understand the astonishing brute force of these digital allies.

Evaluation Functions

After looking ahead at so many moves, the engine needs to determine how good a reached final position is. For this, it uses an evaluation function that assigns scores to positional aspects such as material, piece mobility, king safety, control of the center, and much more.

Each parameter has a weight to contribute to the total score. Initially, these weights were defined manually, but currently, machine learning also comes into play to adjust values, enhancing evaluative capability.

Position Evaluation via NNUE

A recent advancement has been the use of neural networks (NNUE) for evaluations. Millions of positions were used to train a network capable of "intuiting" who has the advantage in any scenario, without the need for fixed rules.

It works by directly examining the geometry of a position and extracting hidden predictive patterns of good results, which it applies to evaluate new positions it has never seen before.

Transposition Tables

Another significant optimization is transposition tables. As many move variations can converge on the same boards later on, the program saves each unique position in a table along with the result of its previous analysis.

This way, it avoids reanalyzing identical or similar situations it had already calculated from scratch, saving valuable time. It recycles computing effort by identifying transpositions.

Opening Books

Engines also use manually created opening databases by human experts, both for their games and for analysis. They guide the early exploration through theoretically solid paths, avoiding wasting time analyzing thousands of bad alternatives in the opening moves.

This allows them to focus their power on the middle game and endgames, where no human could keep up with their pace in variant calculation. They combine the best of both worlds.

Endgame Tables

And speaking of endgames, another gem is the endgame tables, which contain the perfect result for every imaginable position involving 5 or fewer pieces on each side. Billions of precalculated end positions.

By consulting these tables in seconds, the program knows with certainty the outcome of very complex endgames that not even the best humans could fully master. They are invaluable theoretical treasures.

Cloud Analysis

Chess engines keep getting stronger thanks to distributing the computational workload across a networked cluster of multiple machines. By splitting the analysis of different move branches across many dedicated servers with specialized hardware, the main engine can aggregate their feedback for deeper and more comprehensive results.

Some cloud services boast thousands of computational cores working in parallel on the same position, bringing unprecedented decisiveness and accuracy to evaluations and strategic guidance. No wonder the top classics regularly utilize distributed cloud analysis services to prepare against opponents.

12. Machine Learning and Self-Play

In addition to integrating existing human chess knowledge, engines optimize their ability through machine learning techniques by playing against themselves over and over. The neural network keeps adjusting tactical and positional heuristics over millions of games to learn what leads to victory and positive outcomes.

By competing against constantly improving versions of themselves, with no human data biases, chess AIs now develop unconventional plans and creative attack ideas unlike anything seen before. Their style keeps evolving thanks to non-stop self-play experimentation and fine-tuning evaluations via reinforcement learning algorithms.

13. Contempt Factor and Risk Settings

Engines allow tweaking critical parameters that govern playing style, including contempt and risk factors. Contempt controls tendency to strive for draws or favor aggressive moves with greater winning chances but also chances to lose. Risk settings determine how sharply tactical complications are avoided or embraced.

Based on if you want steady positional squeezing or tactical fireworks, you adjust these settings to get variations suiting personal preferences. This way coaches can configure analysis aligned with a student's natural inclinations and customize preparation accordingly.

14. Engine Strength Measurement

Rating the absolute strength of chess software uses Elo-based benchmarking. Thousands of games against human GMs and other top engines are used to quantify ratings reliably. Thanks to extreme optimization and perpetual self-improvement via machine learning, rating figures from just a year or two ago are already obsolete, with leading engines exceeding 3600 Elo on standard consumer hardware.

15. Conclusion

Appreciating the Magic And there you have it - a whirlwind glimpse into the astonishing innovations powering modern chess titans! We are all incredibly fortunate to gain superhuman insight thanks to these digital allies.

16. Join the community

And with this, we reach the end of our journey through the intricate intricacies of modern chess engines! I hope you have enjoyed it and learned some new things about these magnificent digital allies.
I would love to hear what you thought of the article. Did you find it interesting? Which concepts were the most useful or intriguing to you? Let me know in the comments all your reactions, opinions, questions, criticisms, and suggestions that come to mind.

I'm also curious about what other topics you would like me to cover in future blog entries. With so much to explore in the exciting world of chess, ideas abound! From opening strategies, tactical studies, profiles of grandmasters, and much more.

So, feel free to use the comment box. Write down any points you want to highlight, ask, or suggest. Let's keep the dialogue active to continue learning together. I appreciate every message. Until the next lesson!