aboutsummaryrefslogtreecommitdiff
path: root/src/bot.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bot.cpp')
-rw-r--r--src/bot.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 4137f05..dc58fe0 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -57,7 +57,7 @@ int ROOK_TABLE[64] = {
0, 0, 5, 10, 10, 5, 0, 0, //
};
-const int SEARCH_DEPTH = 4;
+const int SEARCH_DEPTH = 5;
#include <fstream>
@@ -89,6 +89,7 @@ Move EngineGetBestMove(Game *b) {
float beta = INFINITY;
float eval = minimax(SEARCH_DEPTH - 1, &TestBoard, alpha, beta);
+
if (b->turn) {
if (eval > BestEval) {
BestEval = eval;
@@ -105,11 +106,11 @@ Move EngineGetBestMove(Game *b) {
}
float minimax(int depth, Game *b, float alpha, float beta) {
if (depth == 0) {
- return EvaluateBoardForWhite(b);
+ return EvaluateBoardForWhite(b, depth);
}
auto moves = GetLegalMoves(b);
if (moves.size() == 0) {
- return EvaluateBoardForWhite(b);
+ return EvaluateBoardForWhite(b, depth);
}
if (b->turn) {
float bestEval = -INFINITY;
@@ -118,7 +119,11 @@ float minimax(int depth, Game *b, float alpha, float beta) {
Game next = *b;
PlayMove(move, &next);
- float eval = minimax(depth - 1, &next, alpha, beta);
+ int newDepth = depth - 1;
+ if (IsPieceTypeAttacked(b, KING, b->turn)) {
+ newDepth += 1;
+ };
+ float eval = minimax(newDepth, &next, alpha, beta);
bestEval = std::max(bestEval, eval);
alpha = std::max(alpha, bestEval);
@@ -136,7 +141,11 @@ float minimax(int depth, Game *b, float alpha, float beta) {
Game next = *b;
PlayMove(move, &next);
- float eval = minimax(depth - 1, &next, alpha, beta);
+ int newDepth = depth - 1;
+ if (IsPieceTypeAttacked(b, KING, b->turn)) {
+ newDepth += 1;
+ };
+ float eval = minimax(newDepth, &next, alpha, beta);
BestEval = std::min(BestEval, eval);
@@ -150,17 +159,17 @@ float minimax(int depth, Game *b, float alpha, float beta) {
}
int PSTIndex(int square, bool white) { return white ? square : (56 ^ square); }
-float EvaluateBoardForWhite(Game *b) {
+float EvaluateBoardForWhite(Game *b, int depth) {
float score = 0;
bool isStaleMate = false;
GetLegalMoves(b);
if (b->state == WHITE_WON) {
- return MATE;
+ return MATE - depth;
}
if (b->state == BLACK_WON) {
- return -MATE;
+ return -MATE + depth;
}
if (b->state == STALEMATE || b->state == DRAW) {
isStaleMate = true;