aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <adammegarules1@gmail.com>2026-08-11 16:54:01 +0200
committerAdam <adammegarules1@gmail.com>2026-08-11 16:54:01 +0200
commit1cf875772801fd3315acd2497ac3652bb97fa307 (patch)
treea1f428d13ecf11e1a2e04d30c72d6cd6a3a03a8d
parentf5d0d8d22b5d734822a684c60da184daa81c60c7 (diff)
improvign bot by giving king endgame table
-rw-r--r--src/bot.cpp13
-rw-r--r--src/evaluate.cpp25
2 files changed, 30 insertions, 8 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index ef6f647..13e3c57 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -208,9 +208,14 @@ static int search(int depth, Game *b, int alpha, int beta, int ply) {
}
}
if (!searchStopped) {
- const Flag flag = bestScore <= alphaOrig ? UPPERBOUND
- : bestScore >= beta ? LOWERBOUND
- : EXACT;
+
+ Flag flag = EXACT;
+ if (bestScore > beta) {
+ flag = UPPERBOUND;
+ }
+ if (bestScore < alphaOrig) {
+ flag = LOWERBOUND;
+ }
(*b->Transpositions)[gameHash] = {
.depth = depth, .Eval = bestScore, .flag = flag, .bestMove = bestMove};
@@ -299,7 +304,7 @@ Move GetBestMove(Game *b, int maxDepth, move_options options) {
int increment = b->turn ? options.wncr : options.bncr;
double time_remaning = b->turn ? options.wtime : options.btime;
- timeToThingMS = (time_remaning / 20 + increment * 0.8);
+ timeToThingMS = ((time_remaning / 20) + (increment * 0.8));
}
bool continueSearching = true;
diff --git a/src/evaluate.cpp b/src/evaluate.cpp
index b1fc4f1..d2ee734 100644
--- a/src/evaluate.cpp
+++ b/src/evaluate.cpp
@@ -80,7 +80,19 @@ static std::array<int, 64> KING_TABLE_EARLY = {
20, 30, 10, 0, 0, 10, 30, 20, //
};
-int EvaluateBoard(Game *g) {
+static std::array<int, 64> KING_TABLE_LATE =
+ {
+ -50, -40, -30, -20, -20, -30, -40, -50, //
+ -30, -20, -10, 0, 0, -10, -20, -30, //
+ -30, -10, 20, 30, 30, 20, -10, -30, //
+ -30, -10, 30, 40, 40, 30, -10, -30, //
+ -30, -10, 30, 40, 40, 30, -10, -30, //
+ -30, -10, 20, 30, 30, 20, -10, -30, //
+ -30, -30, 0, 0, 0, 0, -30, -30, //
+ -50, -30, -30, -30, -30, -30, -30, -50, //
+}
+
+int EvaluateBoard(Game * g) {
int score = EvaluateBoardForWhite(g);
return g->turn ? score : score * -1;
};
@@ -111,7 +123,7 @@ static int ForceKingToEdgeBonus(const Position enemyKing,
return bonus;
}
-int CountBoardMaterial(Game *g) {
+int CountBoardMaterial(Game *g, bool isEndgame) {
int score = 0;
uint64_t piece_bitboard = g->PieceBitboard;
@@ -151,7 +163,11 @@ int CountBoardMaterial(Game *g) {
value += QUEEN_TABLE[RotateBoardForBlack(i, piece.color)];
break;
case KING:
- value = KING_TABLE_EARLY[RotateBoardForBlack(i, piece.color)];
+ if (isEndgame) {
+ value = KING_TABLE_LATE[RotateBoardForBlack(i, piece.color)];
+ } else {
+ value = KING_TABLE_EARLY[RotateBoardForBlack(i, piece.color)];
+ }
break;
default:
break;
@@ -204,9 +220,10 @@ int EvaluateBoardForWhite(Game *g) {
int score = 0;
+ bool isEndGame = IsEndgame(g);
score += CountBoardMaterial(g);
- if (IsEndgame(g)) {
+ if (isEndGame) {
Position whiteKing = FindKing(g, true);
Position blackKing = FindKing(g, false);