From eb2cc35239fc52bf49fcfb9ee9cdb9658d6eb02e Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 25 Mar 2025 19:05:00 +0100 Subject: [PATCH 1/3] added fifty move rule | bench 902872 --- source/board.cpp | 15 +++++++++++++++ source/board.h | 3 +++ source/search.cpp | 6 +++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/source/board.cpp b/source/board.cpp index 3b4c619..f7f4dcf 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -9,6 +9,10 @@ void Board::Reset() { castlingRights = 0; enPassantTarget = noEPTarget; + + halfMoves = 0; + fullMoves = 1; + sideToMove = White; occupied = 0ULL; @@ -65,6 +69,12 @@ void Board::SetByFen(std::string_view fen) { if (tokens[3] != "-") enPassantTarget = UTILS::parseSquare(tokens[3]); + // full and half move + if (tokens.size() > 4) { + halfMoves = std::stoi(tokens[4]); + fullMoves = std::stoi(tokens[5]); + } + occupied = colors[White] | colors[Black]; hashKey = UTILS::GetHashKey(*this); MOVEGEN::GenThreatMaps(*this); @@ -340,6 +350,11 @@ bool Board::MakeMove(Move move) { if (InCheck()) return false; sideToMove = !sideToMove; + if (attackerColor == Black) fullMoves++; + if (attackerPiece == Pawn || move.IsCapture()) { + halfMoves = 0; + } + positionIndex++; positionHistory[positionIndex] = hashKey; diff --git a/source/board.h b/source/board.h index 2d3d88c..5d4cc75 100644 --- a/source/board.h +++ b/source/board.h @@ -32,6 +32,9 @@ public: uint8_t castlingRights = 0; int enPassantTarget = noEPTarget; + int halfMoves = 0; + int fullMoves = 1; + U64 hashKey = 0ULL; void Init(); diff --git a/source/search.cpp b/source/search.cpp index 42db995..f3de4c6 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -98,6 +98,10 @@ static bool IsThreefold(Board &board) { return false; } +static bool IsFifty(Board &board) { + return board.halfMoves >= 50; +} + static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) { int reduction = 0; @@ -170,7 +174,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { } pvLine.SetLength(ply); - if (ply && IsThreefold(board)) return 0; + if (ply && (IsThreefold(board) || IsFifty(board))) return 0; // if NOT PV node then we try to hit the TTable -- 2.47.3 From 05a94a59d356105259a88b7c2079abff6bdb4aac Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 25 Mar 2025 22:46:06 +0100 Subject: [PATCH 2/3] bugfix: didnt increment halfmoves | bench 902872 --- source/board.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/board.cpp b/source/board.cpp index f7f4dcf..77444e4 100644 --- a/source/board.cpp +++ b/source/board.cpp @@ -353,6 +353,8 @@ bool Board::MakeMove(Move move) { if (attackerColor == Black) fullMoves++; if (attackerPiece == Pawn || move.IsCapture()) { halfMoves = 0; + } else { + halfMoves++; } positionIndex++; -- 2.47.3 From 3cb05b15daf852144475db0af1ecf2b2c5e8db2d Mon Sep 17 00:00:00 2001 From: rektdie Date: Tue, 25 Mar 2025 23:14:38 +0100 Subject: [PATCH 3/3] checking for 100 halfmoves, not 50 | bench 902872 --- source/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index f3de4c6..88b0ca6 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -99,7 +99,7 @@ static bool IsThreefold(Board &board) { } static bool IsFifty(Board &board) { - return board.halfMoves >= 50; + return (board.halfMoves >= 100); } static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) { -- 2.47.3