Tomasz Sobczyk [Fri, 7 May 2021 10:24:12 +0000 (12:24 +0200)]
Exporting the currently loaded network file
This PR adds an ability to export any currently loaded network.
The export_net command now takes an optional filename parameter.
If the loaded net is not the embedded net the filename parameter is required.
Two changes were required to support this:
* the "architecture" string, which is really just a some kind of description in the net, is now saved into netDescription on load and correctly saved on export.
* the AffineTransform scrambles weights for some architectures and sparsifies them, such that retrieving the index is hard. This is solved by having a temporary scrambled<->unscrambled index lookup table when loading the network, and the actual index is saved for each individual weight that makes it to canSaturate16. This increases the size of the canSaturate16 entries by 6 bytes.
Vizvezdenec [Wed, 5 May 2021 16:03:20 +0000 (19:03 +0300)]
Cleanup of likelyFailLow logic
This patch broadens and simplifies definition of PvNode that is likely to fail low.
New definition can be described as following "If node was already researched
at depth >= current depth and failed low there" which is more logical than the
previous version and takes less space + allows to not recompute it every time during move loop.
Introduce variable tempo for nnue depending on logarithm of estimated
strength, where strength is the product of time and number of threads.
The original idea here was that NNUE is best with a slightly different
tempo value to classical, since its style of play is slightly different.
It turns out that the best tempo for NNUE varies with strength of play,
so a formula is used which gives about 19 for STC and 24 for LTC under
current fishtest settings.
This patch simplifies QUIET_CHECKS pawn move generator by merging discovery check
move generator with direct check move generator. It also simplifies emptySquares
instantiation. In addition, I added a comment in generate_moves() to clarify Check
branches.
Tomasz Sobczyk [Sat, 24 Apr 2021 13:08:11 +0000 (15:08 +0200)]
Cleanup and simplify NNUE code.
A lot of optimizations happend since the NNUE was introduced
and since then some parts of the code were left unused. This
got to the point where asserts were have to be made just to
let people know that modifying something will not have any
effects or may even break everything due to the assumptions
being made. Removing these parts removes those inexisting
"false dependencies". Additionally:
* append_changed_indices now takes the king pos and stateinfo
explicitly, no more misleading pos parameter
* IndexList is removed in favor of a generic ValueList.
Feature transformer just instantiates the type it needs.
* The update cost and refresh requirement is deferred to the
feature set once again, but now doesn't go through the whole
FeatureSet machinery and just calls HalfKP directly.
* accumulator no longer has a singular dimension.
* The PS constants and the PieceSquareIndex array are made local
to the HalfKP feature set because they are specific to it and
DO differ for other feature sets.
* A few names are changed to more descriptive
NNUE evaluation is incapable of recognizing trivially drawn bishop endgames
(the wrong-colored rook pawn), which are in fact ubiquitous and stock standard
in chess analysis. Switching off NNUE evaluation in KBPs vs KPs endgames is
a measure that stops Stockfish from trading down to a drawn version of these
endings when we presumably have advantage. The patch is able to edge over master
in endgame positions.
Patch tested for Elo gain with the "endgame.epd" book, and verified for
non-regression with our usual book (see the pull request for details).
Verified for correctness of `EVASIONS` by running perft:
```
./stockfish b3nch 16 1 6 default perft (replace 3 by e in b3nch)
Nodes searched : 71608931810
```
Also tested for correctness on Chess960 with a similar code shown here:
https://github.com/official-stockfish/Stockfish/pull/3418#issuecomment-816630295
This patch removes the recently introduced distanceFromPv logic, and replaces
it with following logic: if reduction of moves with low movecount is really
negative, we search them deeper than the first move.
This patch increases the weight of pawns in the scale factor applied
to the output of the NNUE evaluation. This has the effect that Stockfish
will try a little bit harder to keep more pawns in position where the
engine has the advantage, and exchange more pawns in bad positions.
bmc4 [Tue, 30 Mar 2021 03:42:45 +0000 (00:42 -0300)]
Simplify King Evasion
Simplify away the removal of some illegal `KING`-evasion moves during move
generation. Verified for correctness by running perft on the following positions:
Tomasz Sobczyk [Sat, 27 Feb 2021 10:52:18 +0000 (11:52 +0100)]
Allow using Intel SDE for PGO builds.
The software development emulator (SDE) allows to run binaries compiled
for architectures not supported by the actual CPU. This is useful to
do PGO builds for newer architectures. The SDE can currently be obtained from
https://software.intel.com/content/www/us/en/develop/articles/intel-software-development-emulator.html
This patch introduces a new optional makefile argument SDE_PATH.
If not empty it should contain the path to the sde executable
Guy Vreuls [Sat, 13 Mar 2021 16:40:07 +0000 (17:40 +0100)]
Use reference instead of pointer for pop_lsb() signature
This patch changes the pop_lsb() signature from Square pop_lsb(Bitboard*) to
Square pop_lsb(Bitboard&). This is more idomatic for C++ style signatures.
Vizvezdenec [Mon, 15 Mar 2021 18:05:01 +0000 (19:05 +0100)]
Add a specific FRC correction from classical to NNUE
our net currently is not trained on FRC games, and so doesn't know about the important pattern of a bishop that is cornered in FRC.
This patch introduces a term we have in the classical evaluation for this case, and adds it to the NNUE eval.
Since fishtest doesn't support FRC right now, the patch was tested locally at STC conditions,
starting from the book of FRC starting positions.
Score of master vs patch: 993 - 2226 - 6781 [0.438] 10000
Which corresponds to approximately 40 Elo
The patch passes non-regression testing for traditional chess (where it adds one branch).
bmc4 [Mon, 15 Mar 2021 19:06:42 +0000 (16:06 -0300)]
Change definition of between_bb()
We remark that in current master, most of our use cases for between_bb() can be
optimized if the second parameter of the function is added to the segment. So we
change the definition of between_bb(s1, s2) such that it excludes s1 but includes s2.
We also use a precomputed array for between_bb() for another small speed gain
(see https://tests.stockfishchess.org/tests/view/604d09f72433018de7a389fb).
Vizvezdenec [Thu, 11 Mar 2021 11:51:20 +0000 (14:51 +0300)]
Remove advanced_pawn_push()
Continuation of work by @topologist: we now do futility pruning and movecount
pruning in qsearch() for pawn pushes up to the 7th rank. So the condition to
avoid the pruning is if the move is a promotion or not. This allows to get rid
of the advanced_pawn_push() function in position.h alltogether.
bmc4 [Tue, 16 Mar 2021 19:51:31 +0000 (20:51 +0100)]
Introduce least_significant_square_bb()
Introducing least_significant_square_bb(). It is a function that returns a value equal
to square_bb(lsb(bb)), but it uses fewer instruction. It should speed up more on older
processors like armv7-a Clang.
bmc4 [Fri, 5 Mar 2021 11:57:43 +0000 (08:57 -0300)]
Use Bitboard over Square in movegen
It uses pos.checkers() on target when movegen is the type of EVASION.
It simplify the code. And it's also expected a slightly speed up,
because Bitboard is more direct when doing bitwise.
Antoine Champion [Sat, 30 Jan 2021 08:50:04 +0000 (09:50 +0100)]
Clean functions returning by const values
The codebase contains multiple functions returning by const-value.
This patch is a small cleanup making those function returns
by value instead, removing the const specifier.
We introduce a metric for each internal node in search, called DistanceFromPV.
This distance indicated how far the current node is from the principal variation.
We then use this distance to search the nodes which are close to the PV a little
deeper (up to 4 plies deeper than the PV): this improves the quality of the search
at these nodes and bring better updates for the PV during search.
Vizvezdenec [Sat, 20 Feb 2021 21:48:08 +0000 (22:48 +0100)]
Introduce ProbCut for check evasions
The idea of this patch can be described as follows: if we are in check
and the transposition table move is a capture that returns a value
far above beta, we can assume that the opponent just blundered a piece
by giving check, and we return the transposition table value. This is
similar to the usual probCut logic for quiet moves, but with a different
threshold.
The committed version has an additional fix to never return unproven wins
in the tablebase range or the mate range. This fix passed tests for non-
regression at STC and LTC:
Vizvezdenec [Fri, 19 Feb 2021 07:32:12 +0000 (10:32 +0300)]
Tune search parameters (with Unai Corzo)
The values used in this patch are taken from a SPSA parameter tuning session
originated by Unai Corzo (@unaiic), but the final difference of his tune was
multiplied x2 by hand. Most of the credits should go to him :-)
It is our pleasure to release Stockfish 13 to chess fans worldwide.
As usual, downloads are freely available at
https://stockfishchess.org
The Stockfish project builds on a thriving community of enthusiasts
who contribute their expertise, time, and resources to build a free
and open-source chess engine that is robust, widely available, and
very strong. We would like to thank them all!
The good news first: from now on, our users can expect more frequent
high-quality releases of Stockfish! Sadly, this decision has been
triggered by the start of sales of the Fat Fritz 2 engine by ChessBase,
which is a copy of a very recent development version of Stockfish
with minor modifications. We refer to our statement on Fat Fritz 2[1]
and a community blog[2] for further information.
This version of Stockfish is significantly stronger than any of its
predecessors. Stockfish 13 outperforms Stockfish 12 by at least
35 Elo[3]. When playing against a one-year-old Stockfish, it wins 60
times more game pairs than it loses[4]. This release features an NNUE
network retrained on billions of positions, much faster network
evaluation code, and significantly improved search heuristics, as
well as additional evaluation tweaks. In the course of its development,
this version has won the superfinals of the TCEC Season 19 and
TCEC Season 20.
Going forward, the Leela Chess Zero and Stockfish teams will join
forces to demonstrate our commitment to open source chess engines and
training tools, and open data. We are convinced that our free and
open-source chess engines serve the chess community very well.
Stay safe and enjoy chess!
The Stockfish team
[1] https://blog.stockfishchess.org/post/643239805544792064/statement-on-fat-fritz-2
[2] https://lichess.org/blog/YCvy7xMAACIA8007/fat-fritz-2-is-a-rip-off
[3] https://tests.stockfishchess.org/tests/view/602bcccf7f517a561bc49b11
[4] https://tests.stockfishchess.org/tests/view/600fbb9c735dd7f0f0352d59
• reorder some sections of the README file
• add reference to the AUTHORS file
• rename Syzygybases to Syzygy tablebases
• add pointer to the Discord channel
• more precise info about the GPLv3 licence
Vizvezdenec [Thu, 11 Feb 2021 07:45:16 +0000 (10:45 +0300)]
PV-Nodes likely to fail low
Do not decrease reduction at pv-nodes which are likely to fail low.
The idea of this patch can be described as following: during the search, if a node
on the principal variation was re-searched in non-pv search and this re-search got
a value which was much lower than alpha, then we can assume that this pv-node is
likely to fail low again, and we can reduce more aggressively at this node.
mattginsberg [Thu, 11 Feb 2021 21:29:28 +0000 (22:29 +0100)]
Better code for hash table generation
This patch removes some magic numbers in TT bit management and introduce proper
constants in the code, to improve documentation and ease further modifications.
This patch give a small bonus to incite the attacking side to keep more
pawns on the board.
A consequence of this bonus is that Stockfish will tend to play positions
slightly more closed on average than master, especially when it believes
that it has an advantage.
To lower the risk of blockades where Stockfish start shuffling without
progress, we also implement a progressive decrease of the evaluation
value with the 50 moves counter (along with the necessary aging of the
transposition table to reduce the impact of the Graph History Interaction
problem): since the evaluation decreases during shuffling phases, the
engine will tend to examine the consequences of pawn breaks faster during
the search.
Lolligerhans [Tue, 12 Jan 2021 13:30:25 +0000 (14:30 +0100)]
Add penalty for doubled pawns in agile structure
Give an additional penalty of S(20, 10) for any doubled pawn if none of
the opponent's pawns is facing any of our
- pawns or
- pawn attacks;
that means, each of their pawns can push at least one square without
being captured.
This ignores their non-pawns pieces and attacks.
One possible justification: Their pawns' ability to push freely provides
options to react to our threats by changing their pawn structure. Our
doubled pawns however will likely lead to an exploitable weakness, even
if the pawn structure is not yet fixed.
Note that the notion of "their pawns not being fixed" is symmetric for
both players: If all of their pawns can push freely so can ours. All
pawns being freely pushable might just be an early-game-indicator.
However, it can trigger during endgame pawns races, where doubled pawns
are especially hindering, too.
Tomasz Sobczyk [Sun, 10 Jan 2021 06:30:40 +0000 (03:30 -0300)]
Optimize generate_moves
This change simplifies control flow in the generate_moves function which ensures the compiler doesn't duplicate work due to possibly not resolving pureness of the function calls. Also the biggest change is the removal of the unnecessary condition checking for empty b in a convoluted way. The rationale for removal of this condition is that computing attacks_bb with occupancy is not much more costly than computing pseudo attacks and overall the condition (also being likely unpredictable) is a pessimisation.
This is inspired by previous changes by @BM123499.
FauziAkram [Sat, 9 Jan 2021 23:31:09 +0000 (01:31 +0200)]
Bad Outpost Pawn Scale
Changed name from Bad Outpost to Uncontested Outpost
Scale Uncontested Outpost with number of pawns + Decrease Bishop PSQT values and general tuning
Credits for the decrease of the Bishop PSQT values: Fauzi
Credits for scaling Uncontested Outpost with number of pawns: Lolligerhans
Credits for the tunings: Fauzi
Vizvezdenec [Sat, 9 Jan 2021 14:42:58 +0000 (17:42 +0300)]
Refine stat based reductions
This patch separates stat based reductions for quiet moves in case of being in check and in case of not being in check.
We will be using sum of first continuation history and main history (similar to movepicker) instead of statScore for the first case.
BM123499 [Fri, 8 Jan 2021 17:03:26 +0000 (14:03 -0300)]
Rethink En Passant Evasion Capture
It now checks if it were a discovery attack instead of the attacking piece is the double-moved pawn.
As a side effect, certain illegal fens have different, and slightly more logical move generation.
There is no intend to maintain particular behavior for such non-reachable fens.
- "discovered check" (instead of "discovery check")
- "en passant" (instead of "en-passant")
- "pseudo-legal" before a noun (instead of "pseudo legal")
- "3-fold" (instead of "3fold")
Vizvezdenec [Sun, 10 Jan 2021 17:24:37 +0000 (20:24 +0300)]
Small code cleanup in LMR
In a recent patch we added comparing capture history to a number for LMR of captures.
Calling it via thisThread-> is not needed since capture history was already declared by this time -
so removing makes code slightly shorter and easier to follow.
MaximMolchanov [Mon, 11 Jan 2021 05:49:41 +0000 (07:49 +0200)]
Affine transform robust implementation
Size of the weights in the last layer is less than 512 bits. It leads to wrong data access for AVX512. There is no error because in current implementation it is guaranteed that there is an array of zeros after weights so zero multiplied by something is returned and sum is correct. It is a mistake that can lead to unexpected bugs in the future. Used AVX2 instructions for smaller input size.
MaximMolchanov [Wed, 6 Jan 2021 03:29:32 +0000 (05:29 +0200)]
Affine transform refactoring.
Reordered weights in such a way that accumulated sum fits to output.
Weights are grouped in blocks of four elements because four
int8 (weight type) corresponds to one int32 (output type).
No horizontal additions.
Grouped AVX512, AVX2 and SSSE3 implementations.
Repeated code was removed.
Vizvezdenec [Thu, 24 Dec 2020 22:11:09 +0000 (01:11 +0300)]
Do more LMR for captures
This patch enables LMR for all captures at allNodes that were not in PV.
Currently we do LMR for all captures at cutNodes so this is an expansion of this logic:
now we do LMR for all captures almost at all non-pv nodes,
excluding only allNodes that were in PV.
Moez Jellouli [Sun, 20 Dec 2020 21:28:23 +0000 (22:28 +0100)]
Correct Outflanking calculations in classical eval
Take signed value of rank difference between kings squares instead absolute value in outflanking calculation. This change correct evaluation of endgames with one king invading opponent last ranks.
FauziAkram [Sun, 20 Dec 2020 15:50:34 +0000 (17:50 +0200)]
Tweak the formulas for unsafeSquares
We give more bonus for a special case: If there are some enemy squares occupied
or attacked by the enemy on the passed pawn span,
but if they are all attacked by our pawn, use new intermediate factor 30.
The main credit goes to Rocky for the idea, with additional tuning and tests.
pb00067 [Mon, 14 Dec 2020 15:30:56 +0000 (16:30 +0100)]
Simplify condition for assigning static-eval based bonus
for quiet move ordering and simplify bonus formula.
Due to clamping the bonus to relative low values the impact on high
depths is minimal, thus the restriction to low depths seems not
necessary.
Also the condition of movecount in previous node seems to be not
determinant.
Vizvezdenec [Mon, 14 Dec 2020 00:49:04 +0000 (03:49 +0300)]
Increase reduction in case of stable best move
The idea of this patch is pretty simple - we already do more reductions
for non-PV and root nodes in case of stable best move for depth > 10.
This patch makes us do so if root depth if > 10 instead, which
is logical since best move changes (thus instability of it) is
counted at root, so it makes a lot of sense to use depth of the root.
pb00067 [Sun, 13 Dec 2020 20:23:30 +0000 (21:23 +0100)]
Merge static history into main history,
thus simplifying and reducing the memory footprint.
I believe using static diff for better move ordering is more suited for
low depths, so restrict writing to low depths.
Todo: probably the condition for writing can be simplified
mstembera [Sat, 12 Dec 2020 22:18:38 +0000 (14:18 -0800)]
AVX512, AVX2 and SSSE3 speedups
Improves throughput by summing 2 intermediate dot products using 16 bit addition before upconverting to 32 bit.
Potential saturation is detected and the code-path is avoided in this case.
The saturation can't happen with the current nets,
but nets can be constructed that trigger this check.
FauziAkram [Mon, 7 Dec 2020 17:28:47 +0000 (19:28 +0200)]
New Imbalance Tables Tweak
Imbalance tables tweaked to contain MiddleGame and Endgame values, instead of a single value.
The idea started from Fisherman, which requested my help to tune the values back in June/July,
so I tuned the values back then, and we were able to accomplish good results,
but not enough to pass both STC and LTC tests.
So after the recent changes, I decided to give it another shot, and I am glad that it was a successful attempt.
A special thanks goes also to mstembera, which notified me a simple way to let the patch perform a little better.
Use arithmetic right shift for sign extension in MMX and SSE2 paths
This appears to be slightly faster than using a comparison against zero
to compute the high bits, on both old (like Pentium III) and new (like
Zen 2) hardware.
Vizvezdenec [Sat, 5 Dec 2020 01:00:41 +0000 (04:00 +0300)]
Introduce static history
The idea of this patch can be described as following: we update static
history stats based on comparison of the static evaluations of the
position before and after the move. If the move increases static evaluation
it's assigned positive bonus, if it decreases static evaluation
it's assigned negative bonus. These stats are used in movepicker
to sort quiet moves.
Include scaling change as suggested by Dietrich Kappe,
the one who trained net for Komodo. According to him,
some nets may require different scaling in order to utilize its full strength.
syzygy1 [Sun, 29 Nov 2020 11:05:26 +0000 (12:05 +0100)]
Remove piece lists
This patch removes the incrementally updated piece lists from the Position object.
This has been tried before but always failed. My reasons for trying again are:
* 32-bit systems (including phones) are now much less important than they were some years ago (and are absent from fishtest);
* NNUE may have made SF less finely tuned to the order in which moves were generated.
Lolligerhans [Fri, 20 Nov 2020 17:09:41 +0000 (18:09 +0100)]
Refine rook penalty on closed files
+-----------------+
| . . . . . . . . | All files are closed. Some files are
| . . . . . o o . | more valuable for rooks, because
| . . . . o . . o | they might open in the future.
| . . . o x . . x |
| o . o x . x x . |
| x o x . . . . . | x our pawns
| . x . . . . . . | o their pawns
| . . . . . . . . | ^ rooks are scored higher on these files
+-----------------+
^ ^
Files containing none of our own pawns are open or half-open (otherwise
they are closed). Rooks on (half-)open files recieve a bonus for the
future potential to act along all ranks.
This commit refines the (relative) penalty of rooks on closed files.
Files that contain one of our blocked pawns are considered less likely
to open in the future; rooks on these files are now penalized stronger.
This bonus does not generally correlate with mobility. If the condition
is sufficiently refined in the future, it may be beneficial to adjust or
override mobility scores in some cases.