From 4139c262fd6ef87b8ab7e75c96d595740bb6675e Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:11:14 +0700 Subject: [PATCH 1/4] Update types.h --- types.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/types.h b/types.h index 3579972..ed6cfc1 100644 --- a/types.h +++ b/types.h @@ -4,6 +4,7 @@ #include #include #include +#include #if defined(_MSC_VER) #define UNREACHABLE() __assume(false) #elif defined(__clang__) || defined(__GNUC__) @@ -337,14 +338,16 @@ template class ValueList { using Movelist = ValueList; constexpr int square_distance(Square a, Square b) { return std::max(std::abs(file_of(a) - file_of(b)), std::abs(rank_of(a) - rank_of(b))); } constexpr Square parse_square(std::string_view sv) { return make_sq(File(sv[0] - 'a'), Rank(sv[1] - '1')); } -constexpr PieceType parse_pt(std::string_view sv) { +constexpr PieceType parse_pt(unsigned char c) { const char a[] = "pnbrqk"; int p = 0; + c = tolower(c); for (size_t i = 0; i < sizeof(a); i++) { - if (sv[0] == a[i]) + if (c == a[i]) p = i; } return static_cast(p + 1); } } // namespace chess + From 7ebce11dafab015abd88c0c9359e4d1a200c45ee Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:12:10 +0700 Subject: [PATCH 2/4] Update moves_io.cpp --- moves_io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/moves_io.cpp b/moves_io.cpp index fe3f952..5c5db78 100644 --- a/moves_io.cpp +++ b/moves_io.cpp @@ -101,7 +101,7 @@ template Move uciToMove(const _Position &pos, std return Move::NO_MOVE; } - return Move::make(source, target, parse_pt(uci.substr(4, 1))); + return Move::make(source, target, parse_pt(uci[4])); } auto move = (uci.length() == 4) ? Move::make(source, target) : Move::NO_MOVE; Movelist moves; @@ -124,4 +124,4 @@ INSTANTITATE(ContiguousMappingPiece) #undef INSTANTITATE } // namespace uci std::string Move::uci() const { return uci::moveToUci(*this); } -} // namespace chess \ No newline at end of file +} // namespace chess From 4e50fc47ea5d07a639ebde0d03ad503e2cd062e6 Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:16:36 +0700 Subject: [PATCH 3/4] Update moves_io.cpp --- moves_io.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/moves_io.cpp b/moves_io.cpp index 5c5db78..49acb17 100644 --- a/moves_io.cpp +++ b/moves_io.cpp @@ -92,16 +92,18 @@ template Move uciToMove(const _Position &pos, std // promotion if (pt == PAWN && uci.length() == 5 && (rank_of(target) == (pos.sideToMove() == WHITE ? RANK_8 : RANK_1))) { - auto promotion = parse_pt(uci.substr(4, 1)); + auto promotion = parse_pt(uci[4]); if (promotion == NO_PIECE_TYPE || promotion == KING || promotion == PAWN) { -#ifdef __EXCEPTIONS +#if defined(_DEBUG) || !defined(NDEBUG) + assert(false && "promotions: NRBQ"); +#elif defined(__EXCEPTIONS) && (defined(_DEBUG) || !defined(NDEBUG)) throw std::invalid_argument("promotions: NRBQ"); #endif return Move::NO_MOVE; } - return Move::make(source, target, parse_pt(uci[4])); + return Move::make(source, target, promotion); } auto move = (uci.length() == 4) ? Move::make(source, target) : Move::NO_MOVE; Movelist moves; From f4c2550741f53d4603ed2850c3398af035c2862c Mon Sep 17 00:00:00 2001 From: winapiadmin <138602885+winapiadmin@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:19:29 +0700 Subject: [PATCH 4/4] Update types.h bonus: fixes c isn't in "PNBRQK" --- types.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types.h b/types.h index ed6cfc1..6818203 100644 --- a/types.h +++ b/types.h @@ -4,7 +4,6 @@ #include #include #include -#include #if defined(_MSC_VER) #define UNREACHABLE() __assume(false) #elif defined(__clang__) || defined(__GNUC__) @@ -340,8 +339,8 @@ constexpr int square_distance(Square a, Square b) { return std::max(std::abs(fil constexpr Square parse_square(std::string_view sv) { return make_sq(File(sv[0] - 'a'), Rank(sv[1] - '1')); } constexpr PieceType parse_pt(unsigned char c) { const char a[] = "pnbrqk"; - int p = 0; - c = tolower(c); + int p = -1; + (c >='A' && c<='Z') ? (c += 32) : (c); // tolower for (size_t i = 0; i < sizeof(a); i++) { if (c == a[i]) p = i; @@ -351,3 +350,4 @@ constexpr PieceType parse_pt(unsigned char c) { } // namespace chess +