stellar

Stellar - UCI Chess engine written in C++20
git clone git://git.dimitrijedobrota.com/stellar.git
Log | Files | Refs | README | LICENSE

commit 952df70fdab44c483e4eed4ecc7ef5c9451198c7
parent b3660d9286bcd94407d954d7932be4f0956e8592
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Sat, 26 Aug 2023 21:22:14 +0200

CTest perft testsuite

Diffstat:
MCMakeLists.txt | 2++
Msrc/move/move.cpp | 5++---
Msrc/perft/CMakeLists.txt | 37+++++++++++++++++++++++++++++++++++++
3 files changed, 41 insertions(+), 3 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -8,11 +8,13 @@ project( HOMEPAGE_URL https://git.dimitrijedobrota.com/stellar.git LANGUAGES C CXX ) +enable_testing() set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) + include(CheckCXXCompilerFlag) option(STELLAR_ENABLE_PCH "Build using pre-compiled headers" ON) diff --git a/src/move/move.cpp b/src/move/move.cpp @@ -84,9 +84,8 @@ bool Move::make(Board &board, bool attack_only) const { } } - const U64 mask = - castling_rights[to_underlying(this->source())] && castling_rights[to_underlying(this->target())]; - board.and_castle(mask); + board.and_castle(castling_rights[to_underlying(this->source())] & + castling_rights[to_underlying(this->target())]); if (!board.is_check()) { board.switch_side(); diff --git a/src/perft/CMakeLists.txt b/src/perft/CMakeLists.txt @@ -21,3 +21,40 @@ set_target_properties(perft PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" ) + +# position and results taken from chessprogramming.com + +set(STELLAR_PERFT_START_TEST "Start" "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1") +set(STELLAR_PERFT_START_RESULTS 20 400 8902 197281 4865609 119060324 3195901860) + +set(STELLAR_PERFT_TRICKY_TEST "Tricky" "r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1") +set(STELLAR_PERFT_TRICKY_RESULTS 48 2039 97862 4085603 193690690 8031647685) + +set(STELLAR_PERFT_ENDGAME_TEST "Endgame" "8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -") +set(STELLAR_PERFT_ENDGAME_RESULTS 14 191 2812 43238 674624 11030083 178633661 3009794393) + +set(STELLAR_PERFT_MIDGAME_TEST "Midgame" "r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1") +set(STELLAR_PERFT_MIDGAME_RESULTS 6 264 9467 422333 15833292 706045033) + +set(STELLAR_PERFT_RMIDGAME_TEST "Reverse Midgame" "r2q1rk1/pP1p2pp/Q4n2/bbp1p3/Np6/1B3NBn/pPPP1PPP/R3K2R b KQ - 0 1") +set(STELLAR_PERFT_RMIDGAME_RESULTS 6 264 9467 422333 15833292 706045033) + +set(STELLAR_PERFT_BUGGY_TEST "Buggy" "rnbq1k1r/pp1Pbppp/2p5/8/2B5/8/PPP1NnPP/RNBQK2R w KQ - 1 8") +set(STELLAR_PERFT_BUGGY_RESULTS 44 1486 62379 2103487 89941194) + +set(STELLAR_PERFT_TEST START MIDGAME RMIDGAME ENDGAME TRICKY BUGGY) + +foreach(test_name ${STELLAR_PERFT_TEST}) + set(test STELLAR_PERFT_${test_name}_TEST) + set(res STELLAR_PERFT_${test_name}_RESULTS) + list(GET ${test} 0 name) + list(GET ${test} 1 fen) + list(LENGTH ${res} size) + foreach(depth RANGE 1 ${size}) + math(EXPR index "${depth} - 1") + list(GET ${res} ${index} test_expected) + set(test_name "${name} Position Depth ${depth}") + add_test(NAME ${test_name} COMMAND perft -f "${fen}" -t8 -d${depth}) + set_tests_properties(${test_name} PROPERTIES PASS_REGULAR_EXPRESSION ${test_expected}) + endforeach() +endforeach()