Introduce pawn structure based history Original idea by Seer chess engine https://github.com/connormcmonigle/seer-nnue, coding done by @Disservin, code refactoring done by @locutus2 to match the style of other histories. This patch introduces pawn structure based history, which assings moves values based on last digits of pawn structure hash and piece type of moved piece and landing square of the move. Idea is that good places for pieces are quite often determined by pawn structure of position. Used in 3 different places - sorting of quiet moves, sorting of quiet check evasions and in history based pruning in search. Passed STC: https://tests.stockfishchess.org/tests/view/65391d08cc309ae83955dbaf LLR: 2.95 (-2.94,2.94) <0.00,2.00> Total: 155488 W: 39408 L: 38913 D: 77167 Ptnml(0-2): 500, 18427, 39408, 18896, 513 Passed LTC: https://tests.stockfishchess.org/tests/view/653a36a2cc309ae83955f181 LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 70110 W: 17548 L: 17155 D: 35407 Ptnml(0-2): 33, 7859, 18889, 8230, 44 closes https://github.com/official-stockfish/Stockfish/pull/4849 Bench: 1257882 Co-Authored-By: Disservin <disservin.social@gmail.com> Co-Authored-By: Stefan Geschwentner <locutus2@users.noreply.github.com>
add clang-format This introduces clang-format to enforce a consistent code style for Stockfish. Having a documented and consistent style across the code will make contributing easier for new developers, and will make larger changes to the codebase easier to make. To facilitate formatting, this PR includes a Makefile target (`make format`) to format the code, this requires clang-format (version 17 currently) to be installed locally. Installing clang-format is straightforward on most OS and distros (e.g. with https://apt.llvm.org/, brew install clang-format, etc), as this is part of quite commonly used suite of tools and compilers (llvm / clang). Additionally, a CI action is present that will verify if the code requires formatting, and comment on the PR as needed. Initially, correct formatting is not required, it will be done by maintainers as part of the merge or in later commits, but obviously this is encouraged. fixes https://github.com/official-stockfish/Stockfish/issues/3608 closes https://github.com/official-stockfish/Stockfish/pull/4790 Co-Authored-By: Joost VandeVondele <Joost.VandeVondele@gmail.com>
Standardize Comments use double slashes (//) only for comments. closes #4820 No functional change.
Remove unused see_ge() code closes https://github.com/official-stockfish/Stockfish/pull/4805 No functional change
Simplify slider_blocker calculation Now that classical evaluation was removed, we can adapt this method to the needs of set_check_info. STC: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 298176 W: 75802 L: 75868 D: 146506 Ptnml(0-2): 908, 33608, 80192, 33402, 978 https://tests.stockfishchess.org/tests/view/64e70b899009777747557b43 closes https://github.com/official-stockfish/Stockfish/pull/4753 no functional change
Cleanup includes Reorder a few includes, include "position.h" where it was previously missing and apply include-what-you-use suggestions. Also make the order of the includes consistent, in the following way: 1. Related header (for .cpp files) 2. A blank line 3. C/C++ headers 4. A blank line 5. All other header files closes https://github.com/official-stockfish/Stockfish/pull/4763 fixes https://github.com/official-stockfish/Stockfish/issues/4707 No functional change
Remove classical psqt Based on vondele's deletepsqt branch: https://github.com/vondele/Stockfish/commit/369f5b051 This huge simplification uses a weighted material differences instead of the positional piece square tables (psqt) in the semi-classical complexity calculation. Tuned weights using spsa at 45+0.45 with: int pawnMult = 100; int knightMult = 325; int bishopMult = 350; int rookMult = 500; int queenMult = 900; TUNE(SetRange(0, 200), pawnMult); TUNE(SetRange(0, 650), knightMult); TUNE(SetRange(0, 700), bishopMult); TUNE(SetRange(200, 800), rookMult); TUNE(SetRange(600, 1200), queenMult); The values obtained via this tuning session were for a model where the psqt replacement formula was always from the point of view of White, even if the side to move was Black. We re-used the same values for an implementation with a psqt replacement from the point of view of the side to move, testing the result both on our standard book on positions with a strong White bias, and an alternate book with positions with a strong Black bias. We note that with the patch the last use of the venerable "Score" type disappears in Stockfish codebase (the Score type was used in classical evaluation to get a tampered eval interpolating values smoothly from the early midgame stage to the endgame stage). We leave it to another commit to clean all occurrences of Score in the code and the comments. ------- Passed non-regression LTC: LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 142542 W: 36264 L: 36168 D: 70110 Ptnml(0-2): 76, 15578, 39856, 15696, 65 https://tests.stockfishchess.org/tests/view/64c8cb495b17f7c21c0cf9f8 Passed non-regression LTC (with a book with Black bias): https://tests.stockfishchess.org/tests/view/64c8f9295b17f7c21c0cfdaf LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 494814 W: 125565 L: 125827 D: 243422 Ptnml(0-2): 244, 53926, 139346, 53630, 261 ------ closes https://github.com/official-stockfish/Stockfish/pull/4713 Bench: 1655985
Removes a few Bitboards and functions No longer used closes https://github.com/official-stockfish/Stockfish/pull/4695 No functional change
Remove pawnKey from StateInfo Remove pawnKey since it is not used anymore. Passed Non-regression STC: https://tests.stockfishchess.org/tests/view/64b023110cdec37b9573265c LLR: 2.96 (-2.94,2.94) <-1.75,0.25> Total: 334848 W: 85440 L: 85545 D: 163863 Ptnml(0-2): 1134, 38101, 89075, 37964, 1150 closes https://github.com/official-stockfish/Stockfish/pull/4687 No functional change
Simplify lookup_count and clean up pieces(). https://github.com/official-stockfish/Stockfish/pull/4656 No functional change
Reintroduce SEE verification against discovered attacks Reintroduces https://github.com/official-stockfish/Stockfish/pull/4453 along with https://github.com/official-stockfish/Stockfish/pull/4469 Leaving out https://github.com/official-stockfish/Stockfish/pull/4533 https://github.com/official-stockfish/Stockfish/pull/4572 Passed STC: https://tests.stockfishchess.org/tests/view/647d8c37726f6b400e408a0a LLR: 2.93 (-2.94,2.94) <0.00,2.00> Total: 143168 W: 38346 L: 37892 D: 66930 Ptnml(0-2): 352, 15672, 39164, 15962, 434 Passed LTC: https://tests.stockfishchess.org/tests/view/647ee8c528c4431bcb58e432 LLR: 2.94 (-2.94,2.94) <0.50,2.50> Total: 71538 W: 19560 L: 19190 D: 32788 Ptnml(0-2): 49, 6905, 21499, 7259, 57 closes https://github.com/official-stockfish/Stockfish/pull/4609 bench: 2595430
Simplify away SEE verification After 4 simplificatons over PR#4453 the idea does not yield significant improvement anymore. Maybe also https://tests.stockfishchess.org/tests/view/640c88092644b62c3394c1c5 was a fluke. Passed non-regression bounds: STC: https://tests.stockfishchess.org/tests/view/64705389c079b6583146d873 LLR: 2.93 (-2.94,2.94) <-1.75,0.25> Total: 131936 W: 35040 L: 34930 D: 61966 Ptnml(0-2): 336, 14559, 36035, 14735, 303 LTC: https://tests.stockfishchess.org/tests/view/6471a2ade549d9cf2fb213cd LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 407700 W: 109999 L: 110164 D: 187537 Ptnml(0-2): 279, 39913, 123689, 39632, 337 closes https://github.com/official-stockfish/Stockfish/pull/4595 bench: 2675974
Reduce Position::pieces() overloads Reduce the number of overloads for pieces() by using a more general template implementation. Secondly simplify some code in search.cpp using the new general functionality. TC https://tests.stockfishchess.org/tests/view/642ce27877ff3301150dc193 LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 269640 W: 71775 L: 71809 D: 126056 Ptnml(0-2): 687, 27294, 78885, 27274, 680 closes https://github.com/official-stockfish/Stockfish/pull/4501 No functional change.
Clean up repetitive declarations for see_ge The occupied bitboard is only used in one place and is otherwise thrown away. To simplify use, see_ge function can instead be overloaded. Repetitive declarations for occupied bitboard can be removed. Passed non-regression test https://tests.stockfishchess.org/tests/view/6421c286db43ab2ba6f908eb LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 48912 W: 13196 L: 13001 D: 22715 Ptnml(0-2): 146, 5003, 13967, 5190, 150 closes https://github.com/official-stockfish/Stockfish/pull/4469 No functional change.
Verified SEE pruning for capturing and checking moves. Patch analyzes field after SEE exchanges concluded with a recapture by the opponent: if opponent Queen/Rook/King results under attack after the exchanges, we consider the move sharp and don't prune it. Important note: By accident I forgot to adjust 'occupied' when the king takes part in the exchanges. As result of this a move is considered sharp too, when opponent king apparently can evade check by recapturing. Surprisingly this seems contribute to patch's strength. STC: https://tests.stockfishchess.org/tests/view/640b16132644b62c33947397 LLR: 2.96 (-2.94,2.94) <0.00,2.00> Total: 116400 W: 31239 L: 30817 D: 54344 Ptnml(0-2): 350, 12742, 31618, 13116, 374 LTC: https://tests.stockfishchess.org/tests/view/640c88092644b62c3394c1c5 LLR: 2.95 (-2.94,2.94) <0.50,2.50> Total: 177600 W: 47988 L: 47421 D: 82191 Ptnml(0-2): 62, 16905, 54317, 17436, 80 closes https://github.com/official-stockfish/Stockfish/pull/4453 bench: 5012145
Remove 'si' StateInfo variable/parameter. Since st is a member of position we don't need to pass it separately as parameter. While being there also remove some line in pos_is_ok, where a copy of StateInfo was made by using default copy constructor and then verified it's correctedness by doing a memcmp. There is no point in doing that. Passed non-regression test https://tests.stockfishchess.org/tests/view/64098d562644b62c33942b35 LLR: 3.24 (-2.94,2.94) <-1.75,0.25> Total: 548960 W: 145834 L: 146134 D: 256992 Ptnml(0-2): 1617, 57652, 156261, 57314, 1636 closes https://github.com/official-stockfish/Stockfish/pull/4444 No functional change
Remove redundant condition from capture_stage() Change a non functional promotion check to an assert. closes https://github.com/official-stockfish/Stockfish/pull/4436 No functional change
Fix TB after capture_stage fix https://github.com/official-stockfish/Stockfish/commit/5c75c1c2fbb7bb4f0bf7c44fb855c415b788cbf7 introduced a capture_stage() function, but TB usage needs a pure capture() function. closes https://github.com/official-stockfish/Stockfish/pull/4428 No functional change.
Fix duplicated moves generation in movepicker in a some of cases movepicker returned some moves more than once which lead to them being searched more than once. This bug was possible because of how we use queen promotions - they are generated as a captures but are not included in position function which checks if move is a capture. Thus if any refutation (killer or countermove) was a queen promotion it was searched twice - once as a capture and one as a refutation. This patch affects various things, namely stats assignments for queen promotions and other moves if best move is queen promotion, also some heuristics in search and qsearch. With this patch every queen promotion is now considered a capture. After this patch number of found duplicated moves is 0 during normal 13 depth bench run. Passed STC: https://tests.stockfishchess.org/tests/view/63f77e01e74a12625bcd87d7 LLR: 2.95 (-2.94,2.94) <-1.75,0.25> Total: 80920 W: 21455 L: 21289 D: 38176 Ptnml(0-2): 198, 8839, 22241, 8963, 219 Passed LTC: https://tests.stockfishchess.org/tests/view/63f7e020e74a12625bcd9a76 LLR: 2.94 (-2.94,2.94) <-1.75,0.25> Total: 89712 W: 23674 L: 23533 D: 42505 Ptnml(0-2): 24, 8737, 27202, 8860, 33 closes https://github.com/official-stockfish/Stockfish/pull/4405 bench 4681731
Unify type alias declarations The commit unifies the declaration of type aliases by replacing all typedefs with corresponding using statements. closing https://github.com/official-stockfish/Stockfish/pull/4412 No functional change