aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-07-28 15:14:27 +0200
committerAdam <adammegarules1@gmail.com>2026-07-28 15:14:27 +0200
commit8bad9b3bff87d63cb4bfa1c7ae4b974c5fd46f95 (patch)
treea3b83b87d67b6e32ba6c7a18d056478f9e3f5c70 /src/bot.cpp
parent63b9e2cb8451d4491c3ba7e4fdb3e0eca363bd4b (diff)
optimazing
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp28
1 files changed, 10 insertions, 18 deletions
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);