From 3afcd12ffc6f8dc1e44fbb69cc7d0dc5d71f1695 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 11:43:21 +0700 Subject: [PATCH 01/19] Refactor attacks.h with additional includes and functions --- attacks.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/attacks.h b/attacks.h index 32b5e94..0abaa68 100644 --- a/attacks.h +++ b/attacks.h @@ -1,4 +1,5 @@ #pragma once +#include "fwd_decl.h" #include "bitboard.h" #include "types.h" #include @@ -270,6 +271,15 @@ template [[nodiscard]] constexpr Bitboard pawn(const Bitboard pawns) { */ [[nodiscard]] constexpr Bitboard king(Square sq) { return KingAttacks[(int)sq]; } +/** + * @brief Returns the attacks for a given piece on a given square + * @param board + * @param color + * @param square + * @return + */ + +[[nodiscard]] Bitboard attackers(const _Position &board, Color color, Square square) noexcept; /** * @brief Returns the slider attacks for a given square * @param sq @@ -288,4 +298,5 @@ template [[nodiscard]] constexpr Bitboard slider(Square sq, Bitbo return queen(sq, occupied); } -} // namespace chess::attacks \ No newline at end of file + +} // namespace chess::attacks From 6d466bd0dd0465ebea1649591434e1b460fa9285 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 11:45:28 +0700 Subject: [PATCH 02/19] remove the problematic attackers() --- attacks.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/attacks.h b/attacks.h index 0abaa68..081b281 100644 --- a/attacks.h +++ b/attacks.h @@ -271,15 +271,6 @@ template [[nodiscard]] constexpr Bitboard pawn(const Bitboard pawns) { */ [[nodiscard]] constexpr Bitboard king(Square sq) { return KingAttacks[(int)sq]; } -/** - * @brief Returns the attacks for a given piece on a given square - * @param board - * @param color - * @param square - * @return - */ - -[[nodiscard]] Bitboard attackers(const _Position &board, Color color, Square square) noexcept; /** * @brief Returns the slider attacks for a given square * @param sq @@ -300,3 +291,4 @@ template [[nodiscard]] constexpr Bitboard slider(Square sq, Bitbo } // namespace chess::attacks + From d65af04af5bbdec186015faf875546418b65fe2b Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 11:48:56 +0700 Subject: [PATCH 03/19] add some aliases and API wrappers --- position.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/position.h b/position.h index 28f89f3..36d1034 100644 --- a/position.h +++ b/position.h @@ -684,5 +684,21 @@ template ; // for some fun because I HATE HARDCODING +namespace attacks{ +/** + * @brief Returns the attacks for a given piece on a given square + * @param board + * @param color + * @param square + * @return + */ + +[[nodiscard]] __FORCEINLINE Bitboard attackers(const _Position &board, Color color, Square square) noexcept { + return board.attackers(color, square); +} +} +// Aliases +using Position = _Position; +using Board = _Position; }; // namespace chess + From aaf04218335fdced3722dbe328446a0b126b2a13 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 11:58:14 +0700 Subject: [PATCH 04/19] added more apis --- position.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/position.h b/position.h index 36d1034..26b50ae 100644 --- a/position.h +++ b/position.h @@ -19,13 +19,11 @@ template struct alignas(64) HistoryEntry { Color turn; // true if white to move Move mv; Key hash; - struct { - uint8_t halfMoveClock; // Half-move clock for 50/75-move rule - uint16_t fullMoveNumber; // Full-move number (starts at 1) - bool epIncluded; - int8_t repetition = 0; - uint8_t pliesFromNull = 0; - }; + uint8_t halfMoveClock; // Half-move clock for 50/75-move rule + uint16_t fullMoveNumber; // Full-move number (starts at 1) + bool epIncluded; + int8_t repetition = 0; + uint8_t pliesFromNull = 0; Square enPassant = SQ_NONE; // En passant target square Square kings[COLOR_NB] = { SQ_NONE }; CastlingRights castlingRights; // Castling rights bitmask @@ -448,6 +446,7 @@ template &state() const { return current_state; } uint64_t zobrist() const; __FORCEINLINE PieceC piece_at(Square sq) const { return piece_on(sq); } - __FORCEINLINE PieceC at(Square sq) const { return piece_at(sq); } + template + __FORCEINLINE PieceC at(Square sq) const { + assert(is_valid(sq)); + if constexpr (std::is_same_v) return piece_of(piece_at(sq)); + else return piece_at(sq); + } __FORCEINLINE Square enpassantSq() const { return ep_square(); } CastlingRights clean_castling_rights() const; void setFEN(const std::string &str); @@ -524,6 +527,8 @@ template (c)!=0 || count(c)!=0 || count(c)!=0 || count(c)!=0; } __FORCEINLINE bool inCheck() const { return checkers() != 0; } __FORCEINLINE bool is_check() const { return checkers() != 0; } __FORCEINLINE bool has_castling_rights(Color c) const { return castlingRights(c) != 0; } @@ -702,3 +707,4 @@ using Position = _Position; using Board = _Position; }; // namespace chess + From 150fc4d9ec6834ac1630fbef5a5ad92ac8f3a759 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:07:16 +0700 Subject: [PATCH 05/19] Update position.h --- position.h | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/position.h b/position.h index 26b50ae..0f988d2 100644 --- a/position.h +++ b/position.h @@ -179,7 +179,8 @@ template , 2> castling_path={{0xe, 0x60}, {0xe00000000000000, 0x6000000000000000}}; public: // Legal move generation functions template __FORCEINLINE void legals(Movelist &out) const { @@ -391,7 +392,7 @@ template __FORCEINLINE void placePiece(Square sq, Color c) { if constexpr (pt != NO_PIECE_TYPE) { Bitboard v = 1ULL << sq; @@ -528,7 +529,7 @@ template (c)!=0 || count(c)!=0 || count(c)!=0 || count(c)!=0; } + __FORCEINLINE bool hasNonPawnMaterial(Color c) const { return bool(us(color) ^ (pieces(PAWN, KING) & us(color))); } __FORCEINLINE bool inCheck() const { return checkers() != 0; } __FORCEINLINE bool is_check() const { return checkers() != 0; } __FORCEINLINE bool has_castling_rights(Color c) const { return castlingRights(c) != 0; } @@ -588,6 +589,16 @@ template bool is_valid() const; CheckType givesCheck(Move move) const; - + /** + * @brief Checks if the current position is a draw by 50 move rule. + * Keep in mind that by the rules of chess, if the position has 50 half + * moves it's not necessarily a draw, since checkmate has higher priority, + * call getHalfMoveDrawType, + * to determine whether the position is a draw or checkmate. + * @return + */ + [[nodiscard]] __FORCEINLINE bool isHalfMoveDraw() const noexcept { return halfmoveClock() >= 100; } private: template [[nodiscard]] __FORCEINLINE Bitboard pinMask(Color c, Square sq) const { static_assert(pt == BISHOP || pt == ROOK, "Only bishop or rook allowed!"); @@ -708,3 +727,4 @@ using Board = _Position; }; // namespace chess + From d1cafa3fbc781b819914bbdac3f7e23a7ea0091d Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:10:22 +0700 Subject: [PATCH 06/19] fixed some bugs about stm in _valid_ep_square --- position.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/position.cpp b/position.cpp index 7f8a48d..70f95dc 100644 --- a/position.cpp +++ b/position.cpp @@ -629,7 +629,6 @@ template void _Position::refresh_attack } template uint64_t _Position::zobrist() const { uint64_t hash = 0; -#pragma unroll(64) for (int sq = 0; sq < 64; ++sq) { auto p = piece_on((Square)sq); hash ^= (p == PieceC::NO_PIECE) ? 0 : zobrist::RandomPiece[enum_idx()][(int)p][sq]; @@ -674,6 +673,7 @@ template Square _Position::_valid_ep_sq Bitboard mask = 1ULL << ep_square(); Bitboard pawn_mask = mask << 8; Bitboard org_pawn_mask = mask >> 8; + if (sideToMove() == BLACK) std::swap(pawn_mask, org_pawn_mask); // rank 3 or rank 6, depending on color if (rank_of(ep_square()) != ep_rank) return SQ_NONE; @@ -787,3 +787,4 @@ INSTANTIATE(EnginePiece) INSTANTIATE(ContiguousMappingPiece) #undef INSTANTIATE } // namespace chess + From ed5589c4039229b4ebb0347b7bd458444934ff7f Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:17:09 +0700 Subject: [PATCH 07/19] more api for castling path (note: upcoming chess960 support) --- position.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/position.h b/position.h index 0f988d2..7366547 100644 --- a/position.h +++ b/position.h @@ -615,6 +615,7 @@ template = 100; } + [[nodiscard]] __FORCEINLINE Bitboard getCastlingPath(Color c, bool isKingSide) const { return castling_path[c][isKingSide]; } private: template [[nodiscard]] __FORCEINLINE Bitboard pinMask(Color c, Square sq) const { static_assert(pt == BISHOP || pt == ROOK, "Only bishop or rook allowed!"); @@ -728,3 +729,4 @@ using Board = _Position; + From 068c20e7372cbb58e64a0d4a20c6621a21e921c0 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:18:57 +0700 Subject: [PATCH 08/19] more api for compatibility --- types.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/types.h b/types.h index 554d67b..78852f0 100644 --- a/types.h +++ b/types.h @@ -123,13 +123,14 @@ enum Direction : int8_t { }; // clang-format on inline constexpr Square relative_square(Color c, Square s) { return Square(s ^ (c * 56)); } +inline constexpr Square castling_king_square(Color c, bool is_king_side) { return relative_square(c, is_king_side ? SQ_F1 : Square::SQ_D1); } +inline constexpr Square castling_rook_square(Color c, bool is_king_side) { return relative_square(c, is_king_side ? SQ_G1 : Square::SQ_C1); } inline constexpr Rank relative_rank(Color c, Rank r) { return Rank(r ^ (c * 7)); } inline constexpr Rank relative_rank(Color c, Square s) { return relative_rank(c, rank_of(s)); } inline constexpr Direction relative_direction(Color c, Direction d) { return static_cast(c == WHITE ? d : -d); } - inline constexpr Direction pawn_push(Color c) { return c == WHITE ? NORTH : SOUTH; } #define ENABLE_INCR_OPERATORS_ON(T) \ @@ -437,3 +438,4 @@ constexpr PieceType parse_pt(unsigned char c) { } } // namespace chess + From 173373ec69c832abe02f92b17bdd06c01aaadc43 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:19:58 +0700 Subject: [PATCH 09/19] modularize from castling_(rook|king)_square --- position.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/position.cpp b/position.cpp index 70f95dc..e87977b 100644 --- a/position.cpp +++ b/position.cpp @@ -101,8 +101,8 @@ template template void _Position(rook_dest, us); placePiece(king_dest, us); current_state.incr_sqs[0] = from_sq; @@ -788,3 +788,4 @@ INSTANTIATE(ContiguousMappingPiece) #undef INSTANTIATE } // namespace chess + From c4d335d19787aa156424ed6cdf6770b1fcb18af6 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:22:09 +0700 Subject: [PATCH 10/19] modularized (a bit) castling code for upcoming Chess960 --- movegen.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/movegen.cpp b/movegen.cpp index 29a77de..9899578 100644 --- a/movegen.cpp +++ b/movegen.cpp @@ -267,21 +267,15 @@ template void movegen::genKingMoves(con if (pos.checkers()) return; - // Precompute all castling masks - constexpr Bitboard WHITE_OO_EMPTY = (1ULL << SQ_F1) | (1ULL << SQ_G1); - constexpr Bitboard WHITE_OO_SAFE = (1ULL << SQ_F1) | (1ULL << SQ_G1); - constexpr Bitboard WHITE_OOO_EMPTY = (1ULL << SQ_B1) | (1ULL << SQ_C1) | (1ULL << SQ_D1); - constexpr Bitboard WHITE_OOO_SAFE = (1ULL << SQ_C1) | (1ULL << SQ_D1); - - constexpr Bitboard BLACK_OO_EMPTY = (1ULL << SQ_F8) | (1ULL << SQ_G8); - constexpr Bitboard BLACK_OO_SAFE = (1ULL << SQ_F8) | (1ULL << SQ_G8); - constexpr Bitboard BLACK_OOO_EMPTY = (1ULL << SQ_B8) | (1ULL << SQ_C8) | (1ULL << SQ_D8); - constexpr Bitboard BLACK_OOO_SAFE = (1ULL << SQ_C8) | (1ULL << SQ_D8); - Bitboard occupancy = pos.occ(); Bitboard enemy_attacks = enemyAttacks; if constexpr (c == WHITE) { + Bitboard WHITE_OO_EMPTY = pos.getCastlingPath(WHITE, true); + Bitboard WHITE_OO_SAFE = between(sq, castling_king_square(WHITE, true)); + Bitboard WHITE_OOO_EMPTY = pos.getCastlingPath(WHITE, false); + Bitboard WHITE_OOO_SAFE = between(sq, castling_king_square(WHITE, false)); + if ((pos.castlingRights() & WHITE_OO) && !(occupancy & WHITE_OO_EMPTY) && !(enemy_attacks & WHITE_OO_SAFE)) { out.push_back(Move::make(SQ_E1, SQ_H1)); } @@ -289,6 +283,11 @@ template void movegen::genKingMoves(con out.push_back(Move::make(SQ_E1, SQ_A1)); } } else { + Bitboard BLACK_OO_EMPTY = pos.getCastlingPath(BLACK, true); + Bitboard BLACK_OO_SAFE = between(sq, castling_king_square(BLACK, true)); + Bitboard BLACK_OOO_EMPTY = pos.getCastlingPath(BLACK, false); + Bitboard BLACK_OOO_SAFE = between(sq, castling_king_square(BLACK, false)); + if ((pos.castlingRights() & BLACK_OO) && !(occupancy & BLACK_OO_EMPTY) && !(enemy_attacks & BLACK_OO_SAFE)) { out.push_back(Move::make(SQ_E8, SQ_H8)); } From 83735e5bbcb5126d9c702c1866778f940cef1b4a Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:24:55 +0700 Subject: [PATCH 11/19] Update position.h --- position.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/position.h b/position.h index 7366547..2120d70 100644 --- a/position.h +++ b/position.h @@ -447,7 +447,7 @@ template ; + From 520db1ec564f508381a4fee71a5f759f93af6afd Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:26:46 +0700 Subject: [PATCH 12/19] Update clang-format workflow triggers Modify clang-format workflow to trigger on successful completion of another workflow. --- .github/workflows/clang-format.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml index ce9c419..88b50d7 100644 --- a/.github/workflows/clang-format.yml +++ b/.github/workflows/clang-format.yml @@ -1,14 +1,19 @@ name: clang-format on: - pull_request: - branches: [ "main" ] - + workflow_run: + workflows: ["CMake on multiple platforms"] + types: + - completed + jobs: format: + if: > + github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.event == 'pull_request' runs-on: ubuntu-latest permissions: - contents: write # required to push back into PR + contents: write steps: - uses: actions/checkout@v4 From 17433a3799f9b1205c04d95945e13ae4b493366a Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 12:30:46 +0700 Subject: [PATCH 13/19] Update position.h --- position.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/position.h b/position.h index 2120d70..e6318a3 100644 --- a/position.h +++ b/position.h @@ -180,7 +180,12 @@ template , 2> castling_path={{0xe, 0x60}, {0xe00000000000000, 0x6000000000000000}}; +constexpr std::array, 2> castling_path = +{{ + {{ 0xe, 0x60 }}, + {{ 0xe00000000000000, 0x6000000000000000 }} +}}; + public: // Legal move generation functions template __FORCEINLINE void legals(Movelist &out) const { @@ -505,7 +510,7 @@ template __FORCEINLINE PieceC at(Square sq) const { - assert(is_valid(sq)); + assert(chess::is_valid(sq)); if constexpr (std::is_same_v) return piece_of(piece_at(sq)); else return piece_at(sq); } @@ -717,7 +722,7 @@ namespace attacks{ * @param square * @return */ - +template ::value>> [[nodiscard]] __FORCEINLINE Bitboard attackers(const _Position &board, Color color, Square square) noexcept { return board.attackers(color, square); } @@ -731,3 +736,4 @@ using Board = _Position; + From 2e099cb2b6d1387f5c0fa5cff10f7b965ca5fab2 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:09:24 +0700 Subject: [PATCH 14/19] fix compile error --- position.h | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/position.h b/position.h index e6318a3..a4bf18a 100644 --- a/position.h +++ b/position.h @@ -722,7 +722,7 @@ namespace attacks{ * @param square * @return */ -template ::value>> +template ::value>> [[nodiscard]] __FORCEINLINE Bitboard attackers(const _Position &board, Color color, Square square) noexcept { return board.attackers(color, square); } @@ -731,9 +731,3 @@ template ::value>> using Position = _Position; using Board = _Position; }; // namespace chess - - - - - - From 815948ceef53c1fd49519f385293772d4a6f2664 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:11:48 +0700 Subject: [PATCH 15/19] fix compile errors --- position.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/position.h b/position.h index a4bf18a..50b13a8 100644 --- a/position.h +++ b/position.h @@ -180,7 +180,7 @@ template , 2> castling_path = +static constexpr std::array, 2> castling_path = {{ {{ 0xe, 0x60 }}, {{ 0xe00000000000000, 0x6000000000000000 }} @@ -534,7 +534,7 @@ constexpr std::array, 2> castling_path = return has_insufficient_material(WHITE) && has_insufficient_material(BLACK); } __FORCEINLINE bool isInsufficientMaterial() const { return is_insufficient_material(); } - __FORCEINLINE bool hasNonPawnMaterial(Color c) const { return bool(us(color) ^ (pieces(PAWN, KING) & us(color))); } + __FORCEINLINE bool hasNonPawnMaterial(Color c) const { return bool(us(c) ^ (pieces(PAWN, KING) & us(c))); } __FORCEINLINE bool inCheck() const { return checkers() != 0; } __FORCEINLINE bool is_check() const { return checkers() != 0; } __FORCEINLINE bool has_castling_rights(Color c) const { return castlingRights(c) != 0; } @@ -731,3 +731,4 @@ template ::value>> using Position = _Position; using Board = _Position; }; // namespace chess + From f0ced246fd79b7e6b107c6e958f2ab174a94ca25 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:13:24 +0700 Subject: [PATCH 16/19] Fix castling move generation with correct king square --- movegen.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/movegen.cpp b/movegen.cpp index 9899578..d242da9 100644 --- a/movegen.cpp +++ b/movegen.cpp @@ -272,27 +272,27 @@ template void movegen::genKingMoves(con if constexpr (c == WHITE) { Bitboard WHITE_OO_EMPTY = pos.getCastlingPath(WHITE, true); - Bitboard WHITE_OO_SAFE = between(sq, castling_king_square(WHITE, true)); + Bitboard WHITE_OO_SAFE = between(kingSq, castling_king_square(WHITE, true)); Bitboard WHITE_OOO_EMPTY = pos.getCastlingPath(WHITE, false); - Bitboard WHITE_OOO_SAFE = between(sq, castling_king_square(WHITE, false)); + Bitboard WHITE_OOO_SAFE = between(kingSq, castling_king_square(WHITE, false)); if ((pos.castlingRights() & WHITE_OO) && !(occupancy & WHITE_OO_EMPTY) && !(enemy_attacks & WHITE_OO_SAFE)) { - out.push_back(Move::make(SQ_E1, SQ_H1)); + out.push_back(Move::make(kingSq, SQ_H1)); } if ((pos.castlingRights() & WHITE_OOO) && !(occupancy & WHITE_OOO_EMPTY) && !(enemy_attacks & WHITE_OOO_SAFE)) { - out.push_back(Move::make(SQ_E1, SQ_A1)); + out.push_back(Move::make(kingSq, SQ_A1)); } } else { Bitboard BLACK_OO_EMPTY = pos.getCastlingPath(BLACK, true); - Bitboard BLACK_OO_SAFE = between(sq, castling_king_square(BLACK, true)); + Bitboard BLACK_OO_SAFE = between(kingSq, castling_king_square(BLACK, true)); Bitboard BLACK_OOO_EMPTY = pos.getCastlingPath(BLACK, false); - Bitboard BLACK_OOO_SAFE = between(sq, castling_king_square(BLACK, false)); + Bitboard BLACK_OOO_SAFE = between(kingSq, castling_king_square(BLACK, false)); if ((pos.castlingRights() & BLACK_OO) && !(occupancy & BLACK_OO_EMPTY) && !(enemy_attacks & BLACK_OO_SAFE)) { - out.push_back(Move::make(SQ_E8, SQ_H8)); + out.push_back(Move::make(kingSq, SQ_H8)); } if ((pos.castlingRights() & BLACK_OOO) && !(occupancy & BLACK_OOO_EMPTY) && !(enemy_attacks & BLACK_OOO_SAFE)) { - out.push_back(Move::make(SQ_E8, SQ_A8)); + out.push_back(Move::make(kingSq, SQ_A8)); } } } From 7917a700c0a2a50affebfd2dd3e1e33b895fd6c1 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 13:30:17 +0700 Subject: [PATCH 17/19] Update position.h --- position.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/position.h b/position.h index 50b13a8..110c2d6 100644 --- a/position.h +++ b/position.h @@ -182,8 +182,8 @@ template , 2> castling_path = {{ - {{ 0xe, 0x60 }}, - {{ 0xe00000000000000, 0x6000000000000000 }} + {{ 0xc, 0x60 }}, + {{ 0xc00000000000000ULL, 0x6000000000000000ULL }} }}; public: @@ -732,3 +732,4 @@ using Position = _Position; using Board = _Position; }; // namespace chess + From 21f6d3fd96572bd4f1420ae8736f664f084e6f1b Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 21:12:20 +0700 Subject: [PATCH 18/19] fix inversed squares --- types.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types.h b/types.h index 78852f0..9ff1230 100644 --- a/types.h +++ b/types.h @@ -123,8 +123,8 @@ enum Direction : int8_t { }; // clang-format on inline constexpr Square relative_square(Color c, Square s) { return Square(s ^ (c * 56)); } -inline constexpr Square castling_king_square(Color c, bool is_king_side) { return relative_square(c, is_king_side ? SQ_F1 : Square::SQ_D1); } -inline constexpr Square castling_rook_square(Color c, bool is_king_side) { return relative_square(c, is_king_side ? SQ_G1 : Square::SQ_C1); } +inline constexpr Square castling_rook_square(Color c, bool is_king_side) { return relative_square(c, is_king_side ? SQ_F1 : Square::SQ_D1); } +inline constexpr Square castling_king_square(Color c, bool is_king_side) { return relative_square(c, is_king_side ? SQ_G1 : Square::SQ_C1); } inline constexpr Rank relative_rank(Color c, Rank r) { return Rank(r ^ (c * 7)); } @@ -439,3 +439,4 @@ constexpr PieceType parse_pt(unsigned char c) { } // namespace chess + From c924f4a209b5c54b9b88ffbec8f40eeb07095fb8 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Thu, 8 Jan 2026 21:12:29 +0700 Subject: [PATCH 19/19] fixes incorrect castling path --- position.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/position.h b/position.h index 110c2d6..6aa9376 100644 --- a/position.h +++ b/position.h @@ -158,9 +158,7 @@ template , 6144> - history; // ahh, but i hope it fulfils before I manages to find the absolute limit of a game - // Move generation functions, but INTERNAL. (they're kind of long so i put them into a source - // file) Pawns (fully extensively tested) + history; Bitboard _rook_pin; Bitboard _bishop_pin; Bitboard _checkers; @@ -180,11 +178,11 @@ template , 2> castling_path = -{{ - {{ 0xc, 0x60 }}, - {{ 0xc00000000000000ULL, 0x6000000000000000ULL }} -}}; + static constexpr std::array, 2> castling_path = + {{ + {{ 0xe, 0x60 }}, + {{ 0xe00000000000000ULL, 0x6000000000000000ULL }} + }}; public: // Legal move generation functions @@ -733,3 +731,4 @@ using Board = _Position; }; // namespace chess +