diff --git a/src/board.cpp b/src/board.cpp index c11ee347..a408c422 100644 --- a/src/board.cpp +++ b/src/board.cpp @@ -10,7 +10,7 @@ Board::Board(const std::string &fen) { en_passant_square_ = NO_SQ; castling_rights_.clearAllCastlingRights(); half_move_clock_ = 0; - full_move_number_ = 1; + plies_played_ = 0; board_.fill(NONE); @@ -35,7 +35,7 @@ Board::Board(const Board &other) { castling_rights_ = other.castling_rights_; - full_move_number_ = other.full_move_number_; + plies_played_ = other.plies_played_; half_move_clock_ = other.half_move_clock_; @@ -64,7 +64,7 @@ Board &Board::operator=(const Board &other) { castling_rights_ = other.castling_rights_; - full_move_number_ = other.full_move_number_; + plies_played_ = other.plies_played_; half_move_clock_ = other.half_move_clock_; @@ -124,13 +124,17 @@ void Board::setFen(const std::string &fen, bool update_acc) { const std::string en_passant = params[3]; half_move_clock_ = std::stoi(params.size() > 4 ? params[4] : "0"); - full_move_number_ = std::stoi(params.size() > 4 ? params[5] : "1") * 2; + plies_played_ = std::stoi(params.size() > 5 ? params[5] : "1") * 2 - 2; board_.fill(NONE); pieces_bb_.fill(0ULL); side_to_move_ = (move_right == "w") ? WHITE : BLACK; + if (side_to_move_ == BLACK) { + plies_played_++; + } + occupancy_bb_ = 0ULL; auto square = Square(56); @@ -246,7 +250,7 @@ std::string Board::getFen() const { else ss << " " << SQUARE_TO_STRING[en_passant_square_] << " "; - ss << int(half_move_clock_) << " " << int(full_move_number_ / 2); + ss << halfmoves() << " " << fullMoveNumber(); // Return the resulting FEN string return ss.str(); @@ -331,7 +335,7 @@ void Board::makeNullMove() { en_passant_square_ = NO_SQ; - full_move_number_++; + plies_played_++; side_to_move_ = ~side_to_move_; } @@ -347,7 +351,7 @@ void Board::unmakeNullMove() { castling_rights_ = restore.castling; half_move_clock_ = restore.half_moves; - full_move_number_--; + plies_played_--; side_to_move_ = ~side_to_move_; } @@ -367,8 +371,8 @@ std::ostream &operator<<(std::ostream &os, const Board &b) { os << "Fen: " << b.getFen() << "\n"; os << "Side to move: " << static_cast(b.side_to_move_) << "\n"; os << "Castling: " << b.getCastleString() << "\n"; - os << "Halfmoves: " << static_cast(b.half_move_clock_) << "\n"; - os << "Fullmoves: " << static_cast(b.full_move_number_) / 2 << "\n"; + os << "Halfmoves: " << b.halfmoves() << "\n"; + os << "Fullmoves: " << b.fullMoveNumber() << "\n"; os << "EP: " << static_cast(b.en_passant_square_) << "\n"; os << "Hash: " << b.hash_key_ << "\n"; os << "Chess960: " << b.chess960; diff --git a/src/board.h b/src/board.h index bbe6fef0..adf7cda9 100644 --- a/src/board.h +++ b/src/board.h @@ -39,7 +39,9 @@ class Board { [[nodiscard]] uint8_t halfmoves() const { return half_move_clock_; } - [[nodiscard]] int ply() const { return full_move_number_ * 2; } + [[nodiscard]] int fullMoveNumber() const { return 1 + plies_played_ / 2; } + + [[nodiscard]] int ply() const { return plies_played_ + 1; } [[nodiscard]] Color sideToMove() const { return side_to_move_; } @@ -173,7 +175,7 @@ class Board { CastlingRights castling_rights_; // full moves start at 1 - uint16_t full_move_number_; + uint16_t plies_played_; // halfmoves start at 0 uint8_t half_move_clock_; @@ -354,7 +356,7 @@ void Board::makeMove(const Move move) { if constexpr (updateNNUE) accumulators_->push(); half_move_clock_++; - full_move_number_++; + plies_played_++; // ***************************** // UPDATE HASH @@ -446,7 +448,7 @@ void Board::unmakeMove(Move move) { state_history_.pop_back(); - full_move_number_--; + plies_played_--; side_to_move_ = ~side_to_move_; if (typeOf(move) == CASTLING) {