aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/board.cpp2
-rw-r--r--src/board.hpp4
-rw-r--r--src/bot.cpp28
-rw-r--r--src/moves.cpp2
-rw-r--r--src/uci.cpp6
5 files changed, 17 insertions, 25 deletions
diff --git a/src/board.cpp b/src/board.cpp
index 446f6b5..41eef19 100644
--- a/src/board.cpp
+++ b/src/board.cpp
@@ -249,7 +249,7 @@ UndoMove MakeMove(Move move, Game *g) {
return undo;
};
-void UnMake(UndoMove undo, Game *g) {
+void UnMakeMove(UndoMove undo, Game *g) {
g->pieces[PositionToIndex(undo.from)] = undo.movedPiece;
g->pieces[PositionToIndex(undo.to)] = undo.capturedPiece;
diff --git a/src/board.hpp b/src/board.hpp
index 70c5502..2c3bba9 100644
--- a/src/board.hpp
+++ b/src/board.hpp
@@ -80,8 +80,8 @@ struct UndoMove {
void printBoard(Game *b);
Piece createPiece(PieceType type, bool color, bool moved = false);
-void PlayMove(Move move, Game *b);
+// void PlayMove(Move move, Game *b);
int PositionToIndex(Position i);
UndoMove MakeMove(Move move, Game *g);
-void UnMake(UndoMove undo, Game *g);
+void UnMakeMove(UndoMove undo, Game *g);
#endif /* SRC_BOARD_H_ */
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);
diff --git a/src/moves.cpp b/src/moves.cpp
index b8d86df..9841e4b 100644
--- a/src/moves.cpp
+++ b/src/moves.cpp
@@ -184,7 +184,7 @@ std::vector<Move> GetLegalMoves(Game *b) {
if (isLegal) {
legalMove.push_back(move);
};
- UnMake(undo, b);
+ UnMakeMove(undo, b);
}
if (legalMove.size() == 0) {
bool isCheck = false;
diff --git a/src/uci.cpp b/src/uci.cpp
index 42be55d..6f0e5e6 100644
--- a/src/uci.cpp
+++ b/src/uci.cpp
@@ -156,7 +156,7 @@ void Uci() {
while (ss >> token) {
Move move = UciToMove(token);
- PlayMove(move, &game);
+ MakeMove(move, &game);
}
}
}
@@ -196,7 +196,7 @@ int startREPL() {
if (b->state == TURN) {
if (true) {
Move move = EngineGetBestMove(b);
- PlayMove(move, b);
+ MakeMove(move, b);
printBoard(b);
continue;
}
@@ -286,7 +286,7 @@ int startREPL() {
continue;
}
std::println();
- PlayMove(move, b);
+ MakeMove(move, b);
printBoard(b);
}
}