From 8bad9b3bff87d63cb4bfa1c7ae4b974c5fd46f95 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 28 Jul 2026 15:14:27 +0200 Subject: optimazing --- src/bot.cpp | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'src/bot.cpp') diff --git a/src/bot.cpp b/src/bot.cpp index 160c543..ef4a747 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -83,13 +83,13 @@ Move EngineGetBestMove(Game *b) { float BestEval = (b->turn ? -INFINITY : INFINITY); for (Move move : moves) { LogMove(move); - Game TestBoard = *b; - PlayMove(move, &TestBoard); + UndoMove undo = MakeMove(move, b); float alpha = -INFINITY; float beta = INFINITY; - float eval = minimax(SEARCH_DEPTH - 1, &TestBoard, alpha, beta); + float eval = minimax(SEARCH_DEPTH - 1, b, alpha, beta); + UnMakeMove(undo, b); if (b->turn) { if (eval > BestEval) { BestEval = eval; @@ -116,14 +116,10 @@ float minimax(int depth, Game *b, float alpha, float beta) { float bestEval = -INFINITY; for (Move move : moves) { - Game next = *b; - PlayMove(move, &next); - - int newDepth = depth - 1; - if (IsPieceTypeAttacked(b, KING, b->turn)) { - newDepth += 1; - }; - float eval = minimax(newDepth, &next, alpha, beta); + UndoMove undo = MakeMove(move, b); + + float eval = minimax(depth - 1, b, alpha, beta); + UnMakeMove(undo, b); bestEval = std::max(bestEval, eval); alpha = std::max(alpha, bestEval); @@ -138,15 +134,11 @@ float minimax(int depth, Game *b, float alpha, float beta) { float BestEval = INFINITY; for (Move move : moves) { - Game next = *b; - PlayMove(move, &next); - int newDepth = depth - 1; - if (IsPieceTypeAttacked(b, KING, b->turn)) { - newDepth += 1; - }; - float eval = minimax(newDepth, &next, alpha, beta); + UndoMove undo = MakeMove(move, b); + float eval = minimax(depth - 1, b, alpha, beta); + UnMakeMove(undo, b); BestEval = std::min(BestEval, eval); beta = std::min(beta, BestEval); -- cgit v1.2.3