diff --git a/moves_io.cpp b/moves_io.cpp index fe3f952..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.substr(4, 1))); + return Move::make(source, target, promotion); } auto move = (uci.length() == 4) ? Move::make(source, target) : Move::NO_MOVE; Movelist moves; @@ -124,4 +126,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 diff --git a/types.h b/types.h index 3579972..6818203 100644 --- a/types.h +++ b/types.h @@ -337,14 +337,17 @@ 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; + int p = -1; + (c >='A' && c<='Z') ? (c += 32) : (c); // tolower 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 + +