From 05035f72d77a18321d39e118ed28858b8c25bdad Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 21 Aug 2026 18:35:02 +0200 Subject: refactor(search): making code nicer and little faster --- src/moves.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'src/moves.cpp') diff --git a/src/moves.cpp b/src/moves.cpp index 8990621..9f75c25 100644 --- a/src/moves.cpp +++ b/src/moves.cpp @@ -594,26 +594,24 @@ bool IsSquareAttacked(const Game &g, Position square, bool byColor) { g.PieceBitboards[static_cast(byColor)][QUEEN]; return bishop_attacks > 0; } -GameState GetNewGameState(Game *g) { - // make sure we dont override game ending states - if (g->state == DRAW || g->state == WHITE_WON || g->state == BLACK_WON) { - return g->state; +GameState GetboardState(Game *g, const std::vector &moves) { + if (g->halfMoveClock >= 100) { + return DRAW; } - - auto legalMoves = GetLegalMoves(g, ALL); - - if (legalMoves.empty()) { - Position kingPosition = FindKing(*g, g->turn); - - bool check = IsSquareAttacked(*g, kingPosition, !g->turn); - - if (check) { - g->state = g->turn ? BLACK_WON : WHITE_WON; - } else { - g->state = DRAW; + if (isRepetionDraw(g->hash, g)) { + return DRAW; + }; + if (moves.empty()) { + const bool isCheck = IsSquareAttacked(*g, FindKing(*g, g->turn), !g->turn); + if (isCheck) { + if (g->turn) { + return BLACK_WON; + } + return WHITE_WON; } + return DRAW; } - return g->state; + return TURN; } static void GenerateCastlingMoves(const uint8_t &from, const Game &g, -- cgit v1.2.3