Skip to content

Commit 0868f87

Browse files
Null move fix (1) (#47)
* Update position.h * Apply clang-format * Modify hash calculation for en passant state * Apply clang-format * Update position.h * Apply clang-format * Refactor code structure and apply clang-format and remove `current_state` (#48) * Refactor code structure for improved readability and maintainability (bonus: removed current_state weirdness) WIP: remove unneeded state() calls * Apply clang-format --------- Co-authored-by: GitHub Actions <actions@github.com> --------- Co-authored-by: GitHub Actions <actions@github.com>
1 parent c272207 commit 0868f87

7 files changed

Lines changed: 6102 additions & 5957 deletions

File tree

CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ if(BUILD_TESTING)
5656
FetchContent_MakeAvailable(doctest)
5757

5858
# --- Test executable ---
59-
add_executable(test_chess tests.cpp)
59+
add_executable(test_normal tests.cpp)
60+
add_executable(test_chess960 chess960_tests.cpp)
6061
add_executable(NonImportantTests non_core_tests.cpp)
6162

62-
target_link_libraries(test_chess PRIVATE chesslib doctest::doctest)
63+
target_link_libraries(test_normal PRIVATE chesslib doctest::doctest)
6364
target_link_libraries(NonImportantTests PRIVATE chesslib doctest::doctest)
65+
target_link_libraries(test_chess960 PRIVATE chesslib doctest::doctest)
6466

65-
add_test(NAME test_core COMMAND test_chess)
66-
add_test(NAME api_tests COMMAND NonImportantTests)
67+
add_test(NAME test_normal COMMAND test_normal)
68+
add_test(NAME test_api COMMAND NonImportantTests)
69+
add_test(NAME test_chess960 COMMAND test_chess960)
6770
if (UNIX AND CMAKE_BUILD_TYPE MATCHES "Debug")
6871
set(SANITIZERS "" CACHE STRING "sanitizers such as undefined,address")
6972

chess960_tests.cpp

Lines changed: 5897 additions & 0 deletions
Large diffs are not rendered by default.

moves_io.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ template <typename T, typename P> Move parseSan(const _Position<T, P> &pos, std:
146146
// 1) Castling shortcuts
147147
if (san == "O-O" || san == "0-0" || san == "O-O+" || san == "0-0+" || san == "O-O#" || san == "0-0#") {
148148
const auto from = pos.kingSq(pos.side_to_move());
149-
const auto to = pos.state().castlingMetadata[pos.side_to_move()].rook_start_ks;
149+
const auto to = pos.getCastlingMetadata(pos.sideToMove()).rook_start_ks;
150150
Move km = chess::Move::make<CASTLING>(from, to);
151151

152152
if (std::find(moves.begin(), moves.end(), km) != moves.end())
@@ -156,7 +156,7 @@ template <typename T, typename P> Move parseSan(const _Position<T, P> &pos, std:
156156
}
157157
if (san == "O-O-O" || san == "0-0-0" || san == "O-O-O+" || san == "0-0-0+" || san == "O-O-O#" || san == "0-0-0#") {
158158
const auto from = pos.kingSq(pos.side_to_move());
159-
const auto to = pos.state().castlingMetadata[pos.side_to_move()].rook_start_qs;
159+
const auto to = pos.getCastlingMetadata(pos.sideToMove()).rook_start_qs;
160160
Move qm = chess::Move::make<CASTLING>(from, to);
161161

162162
if (std::find(moves.begin(), moves.end(), qm) != moves.end())

non_core_tests.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ TEST_CASE("was_into_check") {
241241
};
242242
check_was_into_check<PolyglotPiece>(tests);
243243
check_was_into_check<EnginePiece>(tests);
244+
check_was_into_check<ContiguousMappingPiece>(tests);
244245
}
245246
TEST_CASE("Zobrist mapping?") {
246247
REQUIRE(zobrist::RandomPiece[enum_idx<PolyglotPiece>()][(int)PolyglotPiece::BPAWN][0] == 0x9D39247E33776D41);
@@ -252,16 +253,24 @@ struct repetitions_t {
252253
};
253254
void check_repetitions(std::vector<TestEntry<repetitions_t, bool>> &tests) {
254255
for (auto &tc : tests) {
255-
_Position<PolyglotPiece> pos(tc.input.FEN);
256-
for (auto &move : tc.input.moves)
257-
pos.doMove(move);
258-
REQUIRE(pos.is_repetition(tc.input.repetition) == tc.info);
259-
}
260-
for (auto &tc : tests) {
261-
_Position<EnginePiece> pos(tc.input.FEN);
262-
for (auto &move : tc.input.moves)
263-
pos.doMove(move);
264-
REQUIRE(pos.is_repetition(tc.input.repetition) == tc.info);
256+
{
257+
_Position<PolyglotPiece> pos(tc.input.FEN);
258+
for (auto &move : tc.input.moves)
259+
pos.doMove(move);
260+
REQUIRE(pos.is_repetition(tc.input.repetition) == tc.info);
261+
}
262+
{
263+
_Position<EnginePiece> pos(tc.input.FEN);
264+
for (auto &move : tc.input.moves)
265+
pos.doMove(move);
266+
REQUIRE(pos.is_repetition(tc.input.repetition) == tc.info);
267+
}
268+
{
269+
_Position<ContiguousMappingPiece> pos(tc.input.FEN);
270+
for (auto &move : tc.input.moves)
271+
pos.doMove(move);
272+
REQUIRE(pos.is_repetition(tc.input.repetition) == tc.info);
273+
}
265274
}
266275
}
267276
TEST_CASE("is_repetition") {

0 commit comments

Comments
 (0)