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
11 changes: 6 additions & 5 deletions moves_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "position.h"
#include "types.h"
#include <algorithm>
#include <cctype>
#include <string_view>
#if defined(_CHESSLIB_ERROR_MODE_THROW)
#define INVALID_ARG_IF(c, exception) \
Expand Down Expand Up @@ -174,10 +175,10 @@ template <typename T, typename V> Move uciToMove(const _Position<T, V> &pos, std
/// @tparam T Piece enum type.
/// @tparam P Position tag.
/// @param pos The position.
/// @param san SAN string (e.g. "Nf3", "O-O").
/// @param raw_san SAN string (e.g. "Nf3", "O-O").
/// @param remove_illegals If true, return Move::NO_MOVE instead of throwing.
/// @return The parsed Move.
template <typename T, typename P> Move parseSan(const _Position<T, P> &pos, std::string_view san, bool remove_illegals) {
template <typename T, typename P> Move parseSan(const _Position<T, P> &pos, std::string_view raw_san, bool remove_illegals) {
auto do_parse = [&](std::string_view input_san) -> Move {
if (input_san.empty())
return Move::none();
Expand Down Expand Up @@ -404,17 +405,17 @@ template <typename T, typename P> Move parseSan(const _Position<T, P> &pos, std:
};

if (remove_illegals) {
std::string trimmed_san(san);
std::string trimmed_san(raw_san);
while (!trimmed_san.empty()) {
Move attempt = do_parse(trimmed_san);
if (attempt.is_ok())
return attempt;
trimmed_san.pop_back();
}
INVALID_ARG_IF(trimmed_san.empty(), IllegalMoveException("illegal san: '" + std::string(san) + "' in " + pos.fen()));
INVALID_ARG_IF(trimmed_san.empty(), IllegalMoveException("illegal san: '" + std::string(raw_san) + "' in " + pos.fen()));
return Move::none();
} else
return do_parse(san);
return do_parse(raw_san);
}
/// @brief Convert a Move to SAN or LAN (Long Algebraic Notation) string.
template <typename T, typename P> std::string moveToSan(const _Position<T, P> &pos, Move move, bool long_, bool suffix) {
Expand Down
14 changes: 7 additions & 7 deletions moves_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ template <typename T, typename P = void> Move uciToMove(const _Position<T, P> &p
/// @tparam T Piece enum type.
/// @tparam P Position tag.
/// @param pos The position.
/// @param san SAN string (e.g. "Nf3", "O-O").
/// @param raw_san SAN string (e.g. "Nf3", "O-O").
/// @param remove_illegals If true, return Move::NO_MOVE instead of throwing.
/// @return The parsed Move.
template <typename T, typename P = void>
Move parseSan(const _Position<T, P> &pos, std::string_view san, bool remove_illegals = false);
Move parseSan(const _Position<T, P> &pos, std::string_view raw_san, bool remove_illegals = false);

/// @brief Alias for parseSan.
/// @copydoc parseSan
template <typename T, typename P = void>
Move parse_san(const _Position<T, P> &pos, std::string_view san, bool remove_illegals = false) {
return parseSan(pos, san, remove_illegals);
inline Move parse_san(const _Position<T, P> &pos, std::string_view raw_san, bool remove_illegals = false) {
return parseSan(pos, raw_san, remove_illegals);
}

/// @brief Convert a Move to SAN string for the given position.
Expand All @@ -106,9 +106,9 @@ Move parse_san(const _Position<T, P> &pos, std::string_view san, bool remove_ill
template <typename T, typename P = void>
std::string moveToSan(const _Position<T, P> &pos, Move move, bool long_ = false, bool suffix = true);

/// @brief Alias for moveToSan.
/// @copydoc moveToSan
template <typename T, typename P = void>
std::string move_to_san(const _Position<T, P> &pos, Move move, bool long_ = false, bool suffix = true) {
inline std::string move_to_san(const _Position<T, P> &pos, Move move, bool long_ = false, bool suffix = true) {
return moveToSan(pos, move, long_, suffix);
}
} // namespace chess::uci
8 changes: 6 additions & 2 deletions position.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ template <typename PieceC = EnginePiece, typename = std::enable_if_t<is_piece_en
}
}
/// @brief Undo the last move (snake_case). Returns saved HistoryEntry when RetAll=true.
template <bool RetAll = false> inline auto undo_move() -> std::conditional_t<RetAll, HistoryEntry<PieceC>, void> {
template <bool RetAll = false>
inline auto undo_move() -> std::conditional_t<RetAll, HistoryEntry<PieceC>, void> {
return undoMove<RetAll>();
}

Expand Down Expand Up @@ -343,7 +344,7 @@ template <typename PieceC = EnginePiece, typename = std::enable_if_t<is_piece_en
refresh_attacks();
}
/// @brief Perform a null move (pass the turn).
inline void do_null_move() { doNullMove(); }
[[deprecated("Pending to remove")]] inline void do_null_move() { doNullMove(); }

/// @name Occupancy queries
/// @{
Expand Down Expand Up @@ -994,6 +995,9 @@ template <typename PieceC = EnginePiece, typename = std::enable_if_t<is_piece_en
_check_mask = other._check_mask;
_pin_mask = other._pin_mask;
}
// @brief Get the amount of moves played since position construction
// @return size of history
inline size_t history_count() const { return history.size(); }
Comment thread
winapiadmin marked this conversation as resolved.
};

namespace attacks {
Expand Down
2 changes: 1 addition & 1 deletion types.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
#pragma once

#include "fwd_decl.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <string>

/// @file types.h
/// @brief Core chess type definitions: squares, pieces, colours, move encoding, and ValueList.
#if defined(__clang__) || defined(__GNUC__)
Expand Down