Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions moves_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,18 @@ template <typename T, typename V> Move uciToMove(const _Position<T, V> &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<PROMOTION>(source, target, parse_pt(uci.substr(4, 1)));
return Move::make<PROMOTION>(source, target, promotion);
}
auto move = (uci.length() == 4) ? Move::make(source, target) : Move::NO_MOVE;
Movelist moves;
Expand All @@ -124,4 +126,4 @@ INSTANTITATE(ContiguousMappingPiece)
#undef INSTANTITATE
} // namespace uci
std::string Move::uci() const { return uci::moveToUci(*this); }
} // namespace chess
} // namespace chess
9 changes: 6 additions & 3 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,17 @@ template <typename T, std::size_t MaxSize> class ValueList {
using Movelist = ValueList<Move, 256>;
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<PieceType>(p + 1);
}

} // namespace chess