How engines work
How do you develop engines , which can find the best move every time and how other engines are more powerful than others, how do you make them
Ok so this is a simple run down.
1. Choose a programming language, preferably compiled like Rust, C#, unless you want to give yourself a challenge, like me using Javascript.
2. Rely on the Chess Programming Wiki. It is the best source for programming a chess engine as it has many worked examples.
3. Program board representation ( A bug free internal board representation that knows every rule of chess )
Recommended:
Beginner level - 16x16 Vector Attacks, Mailbox like 0x88
Intermediate - Plain bitboards, fancy bitboards
Advanced - Magic bitboards, Hyperbola Quintessence
4. Do something called a Perft test, which basically ensures your engine hits the correct move count at a certain ply.
5. Choose a search function. Popular ones include Negamax search, Monte Carlo Tree Search, Minimax, etc.
6. Program an evaluation function that evaluates a position based on factors like piece count, piece mobility, pawn structure, king safety, etc
7. Optimise your code and use tuning methods like Texel tuning and Stockfish tuning to get the evaluation parameters like piece values right
You could also try implementing neural nets, like the ones using by Lc0, Alphazero and Stockfish, for example NNUE (Efficiently Updatable Neural Network). These provide highly quality evaluations at the cost of node count.
Why some engines stronger than others:
There are multiple reasons. One reason is nodes per second, where a node is a unique position. Higher nps would allow for engines to search to deeper depths, which is limited by the language it is written in and the computational resources. Secondly it is how good the search tree can prune to search the best lines. Some have attempted to do so using methods like alpha-beta, reverse futility, etc. Thirdly, the evaluation function. Hand crafted evaluation functions without neural nets are usually weaker because the nets have been trained on millions of positions to get a better understanding of positions. However, nets result in lower nps as more time is spent on each node, but result in possibly higher playing strength from better evaluations, like Alphazero vs Stockfish in 2017