ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Discussion of computer chess matches and engine tournaments.

Moderators: hgm, Rebel, chrisw

User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

Image

Hi chess engine fans!

On this topic we discuss about how to modify Stockfish to create a DERIVATIVE engine focused on material sacrifices for positional advantage.

All ideas, suggestions and comments are welcome!

Image

I will release ProteusChessSF under GPLv3 attributing the original source to the Stockfish Team and never share my private engine executable before it will be really different in standard SF playing style.
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

The entirety of chess boils down to evaluating positions, and then searching for good moves. Let's start with evaluating positions. In order to tell how "good" a chess position is, Stockfish takes into account many things that human players do as well:

Raw Material
Having more pieces is better than having less pieces.
Pawn Midgame = 198, Pawn Endgame = 258
Knight Midgame = 817, Knight Endgame = 846
Bishop Midgame = 836, Bishop Endgame = 857
Rook Midgame = 1270, Rook Endgame = 1281
Queen Midgame = 2521, Queen Endgame = 2558
Humans typically use Pawn = 1, Knight/Bishop = 3, Rook = 5, and Queen = 9-10. These proportions are pretty close to that.
General Piece Placement
Controlling (attacking/defending) center squares is better than controlling unoccupied squares.
Defending important friendly pieces (that are in turn controlling important squares) is good.
Attacking important enemy pieces (that are in turn controlling important squares) is good.
"Bonus" Piece Placement
Knights
Enjoy outposts (squares where they are sufficiently protected by a pawn) near the center of the board.
Bishops
Enjoy control of major diagonals.
Enjoy being paired (having the other bishop still in the game) in open positions (where most pieces are not blocked) are good.
Kings
Enjoy safety on squares difficult to for the opponent to checkmate (or control every other square around).
Pawn formation
Doubled and tripled pawns are bad, as they have limited mobility, and therefore cannot defend each other.
Isolated pawns are bad, they cannot be defended by other pieces.
Protected passed pawns are good, they can queen soon.
Phew, that was a long (and not even exhaustive!) list. Each one of these bullet points has its own unique weight that has been fine-tuned over the years. An exhaustive list can be found at chessprogramming - Evaluation. Remember though, evaluation does not account for everywhere the pieces could move in the future, and a positive evaluation does not ensure checkmate is imminent. Rather, evaluation gives a general sense of where a position is headed in the future, it can be thought of as an approximate derivative.

Now that we know how to evaluate positions, we can examine the resulting positions from all the legal moves available and pick the best one (aka "search" for it). The only problem is that a move may be beneficial to us in the short term (i.e. taking an uncontested queen), but a counter-move by the opponent (i.e. delivering checkmate) could lead to us losing the game. So, we have to consider all possible moves, all the way until checkmate, or else that move may not actually lead to a "good" position. Another way to think about it is that a position is really only "good" if always leads to checkmate, otherwise it is technically still up in the air. So then Stockfish can just probe moves until checkmate, right?

Wrong. Crazily enough, there are just TOO MANY possible moves until checkmate is reached. This is what still makes chess interesting to us humans, no machine can solve EVERY game of chess from the starting position all the way until checkmate with there always being an optimal move (as has been done with checkers), but in theory it is possible in the future.

To put this in perspective, after both players move, 400 possible board setups exist. After the second pair of turns, there are 197,742 possible games, and after three moves, 121 million. According to Jonathan Schaeffer, a computer scientist at the University of Alberta who demonstrates A.I. using games, "The possible number of chess games is so huge that no one will invest the effort to calculate the exact number." Some have estimated it at around 10,100,000. Out of those, 10,120 games are "typical": about 40 moves long with an average of 30 choices per move.[1]

So instead of evaluating all the way until checkmate, Stockfish simply looks as far as it can (usually 30+ nodes deep), and uses heuristics based on the stage of the game to assign a value to how "good" the move really is based off of the resulting position. To do this, Stockfish cleverly constructs a tree full of ever-increasing depth, consisting of moves followed by more moves, along with their values. While modern hardware can analyze hundreds of thousands of positions in seconds, multiple steps are still taken to "prune" and recognize patterns inside the tree.

A non-exhaustive list of techniques is as follows:

Alpha-beta pruning is used to eliminate "bad moves," or moves that after counter-moves result in extremely bad positions.
A transposition-table is created to store frequently visited positions, so no identical nodes are analyzed more than once.
This becomes even more complicated past depths of 3, check out chessprogramming - Alpha-Beta for more info.
Razoring is used as a sort of forward pruning where rather than skipping an entire subtree, the engine searches it to a reduced depth, typically one less than the normal depth. The advantage is that you get most of the saving but with much lower risk than pruning entire subtrees like with alpha-beta pruning.
This comes from the heuristic that from any given position the opponent will be able to find at least one move that improves his position, the Null Move Observation.
Again, this is oversimplified. Check out chessprogramming - Razoring for more info.
Opening heuristics
Developing minor pieces (knights/bishops) is good.
Moving the queen out early is generally bad.
Castling ASAP is generally good.
Controlling the middle of the board ASAP is generally good.
Closed positions are generally a little bit bad, because they are harder to prune (although this is getting increasingly better, and my life savings says you still can't beat Stockfish in a closed position game with 20+10 timing).
Also, instead of actually doing computations, a computer can choose the first few favorable moves from a chess opening book. Stockfish actually doesn't do this.

Mid-game heuristics
Setting the opponent up to possibly make a bad move (or "setting up traps") is good.
Forking, pinning, and using other tactics on crucial squares is generally good.
Navigating pieces quickly to optimal positions is generally good.
Taking the initiative and attacking with white is generally good.
Defending with black until there is something you can punish is generally good.
The mid-game is where engines are most likely to overtake human opponents, as they are much sharper at analyzing trades and positional play than humans.

Lastly, the end-game is rather anti-climatic and already solved. The engine simply compares its position to a table of possible positions (called 6-man Syzygy Tablebases), or uses yet another set of its own custom heuristics that cover all endgames, most of which are usually obvious heuristics regarding passed-pawns and 50-move draws.

Altogether, the search method has been criticized for being too "brute-forcish," but current technology warrants "brute-force" methods, there is no elegant solution to pruning branches nor method to take some derivative of a position to tell which way it is headed. In the end, the brute-force method ultimately works quite well on modern hardware, it can usually go to about 30+ nodes (or plies/half-moves) deep in a matter of seconds. More importantly, Stockfish has been improved upon in recent years to the point where it can beat (or at worst draw) any human! Just take a look at the set of games of Nakamura (currently the world's highest rated US player, and 5th in the world) + Rybka (an older engine) vs Stockfish last year (2014).[2]

What truly makes Stockfish incredible compared to other engines (save the higher-rated commercial engine Komodo) is the community behind it, and very importantly its founders. Tord Romstad, Marco Costalba, and Joona Kiiski chose to open-source a top-class engine in 2008 to the public so that anyone could contribute, and until 2014 Costalba led the project exceptionally well. Additionally, in 2013 the Stockfish community created Fishtest, which uses hundreds of thousands of dollars on hardware to test future versions of Stockfish against... older versions of Stockfish to check for performance gains in the newer version. A dedicated community searching for every statistical and theoretical way to improve the engine has kept (and will continue to keep) it on top as long as interest is maintained.

SOURCE: https://www.quora.com/What-is-the-algor ... ess-engine
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

First 5 modifications in SF PSTQ - Blitz test against the strong SlowChess 2.83 - Arena luckily doesn't crash :mrgreen:

Image

Image

Image
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
Jjaw
Posts: 46
Joined: Thu Jul 29, 2021 4:48 pm
Full name: Joe Louvier

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by Jjaw »

Another stockfish clone ... :roll:
tcusr
Posts: 323
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by tcusr »

stockfish uses NNUE for evaluation, you changes (that affect the hand-crafted evaluation) are useless.
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

tcusr wrote: Mon Jan 31, 2022 10:40 pm stockfish uses NNUE for evaluation, you changes (that affect the hand-crafted evaluation) are useless.
Image

At this point, even if the NNUE and MCTS support is available, I'm not interested to the strength but to the style of the engine (I want add positional sacrifices, king safety and castle assault patterns) so hand-crafted evaluation is useful :) Then I will add hybrid mode.

https://computerchessengines.quora.com/ ... -of-an-Era
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

Jjaw wrote: Mon Jan 31, 2022 6:44 pm Another stockfish clone ... :roll:
Nobody reinvents the wheel (ask Ed Shroeder using Fruit as base for Rebel 14)
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

Image

Interesting article about Alpha-Zero projects for 2022 https://cacm.acm.org/magazines/2022/2/2 ... o/fulltext
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

First heavy modifications in Pawn Bonus values seem interesting, replaced SugaR 2.50 ICCF (closed project) with ProteusChessSF on my LT tournament :)

Image
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN
User avatar
AlexChess
Posts: 1534
Joined: Sat Feb 06, 2021 8:06 am
Full name: Alex Morales

Re: ProteusChessSF - Developing my Stockfish 14.1 Polyglot MTCS derivative

Post by AlexChess »

Wow! Disabling NNUE (to use hand-crafted evaluations) Proteus is 3 times faster than the other SF derivative Kayra 1.1

Until now, my bonus pawns modifications to enforce pawn structure seems to compensate well the lack of a neural network. I will publish all the games today afternoon (draws the first 2 games against Fat Titz 2 130121 and Kayra 1.1 :D )

Image

Image
Chess engines and dedicated chess computers fan since 1981 :D Mac mini M1 8GB-256GB, Windows 11 & Ubuntu ARM64.
ProteusSF Dev Forum TROLLS KINDERGARTEN