From 1cf875772801fd3315acd2497ac3652bb97fa307 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 11 Aug 2026 16:54:01 +0200 Subject: improvign bot by giving king endgame table --- src/bot.cpp | 13 +++++++++---- src/evaluate.cpp | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) (limited to 'src') 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 KING_TABLE_EARLY = { 20, 30, 10, 0, 0, 10, 30, 20, // }; -int EvaluateBoard(Game *g) { +static std::array 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); -- cgit v1.2.3