From d6aa977a1586b3cb60af89e6a106f9112562d6e5 Mon Sep 17 00:00:00 2001 From: Karma Riuk Date: Thu, 6 Feb 2025 22:39:11 +0100 Subject: [PATCH] added the 50-move draw rule --- cpp/src/model/board/board.cpp | 6 ++++++ cpp/src/model/board/board.hpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cpp/src/model/board/board.cpp b/cpp/src/model/board/board.cpp index 4760373..97c2b10 100644 --- a/cpp/src/model/board/board.cpp +++ b/cpp/src/model/board/board.cpp @@ -267,6 +267,12 @@ Board Board::make_move(Move move) const { } } + ret.n_half_moves = n_half_moves + 1; + if (is_capturing || piece_at(move.source_square) == Piece::Pawn) + ret.n_half_moves = 0; + if (!white_to_play) + ret.n_full_moves = n_full_moves + 1; + return ret; } diff --git a/cpp/src/model/board/board.hpp b/cpp/src/model/board/board.hpp index 7233f2f..000ab22 100644 --- a/cpp/src/model/board/board.hpp +++ b/cpp/src/model/board/board.hpp @@ -43,7 +43,7 @@ struct Board { } bool is_terminal() const { - return insufficient_material() || white_to_play + return n_half_moves == 100 || insufficient_material() || white_to_play ? is_checkmate_for(White) || is_stalemate_for(White) : is_checkmate_for(Black) || is_stalemate_for(Black); }