diff options
Diffstat (limited to 'src/bot.cpp')
| -rw-r--r-- | src/bot.cpp | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/src/bot.cpp b/src/bot.cpp index 9e9b624..8fe491e 100644 --- a/src/bot.cpp +++ b/src/bot.cpp @@ -18,8 +18,8 @@ #include "hash.hpp" #include "moves.hpp" -constexpr int DEFAULT_TIME = 7; -constexpr int Q_DEPTH_LIMIT = 4; +constexpr int DEFAULT_TIME = 10; +constexpr int Q_DEPTH_LIMIT = 10; constexpr int BOOK_DEPTH = 100; constexpr int MATE = 10000; @@ -113,20 +113,21 @@ static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) { } } - const int standPat = EvaluateBoard(b); + auto moves = GetSortedLegalMoves(b, ALL, nullptr); - switch (b->state) { + GameState state = GetboardState(b, moves); + switch (state) { case WHITE_WON: case BLACK_WON: return -(MATE - ply); - break; case DRAW: return 0; - break; case TURN: break; } + const int standPat = EvaluateBoard(b); + if (qdepth >= Q_DEPTH_LIMIT) { return standPat; } @@ -136,9 +137,10 @@ static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) { } alpha = std::max(alpha, standPat); - auto moves = GetSortedLegalMoves(b, CAPTUARES_ONLY, nullptr); - for (uint16_t move : moves) { + if (((1ULL << getToValueFromMove(move)) & b->PieceBitboard) == 0) { + continue; + } Undo undo = MakeMove(move, b); int score = -quiescenceSearch(b, qdepth + 1, -beta, -alpha, ply + 1); @@ -155,7 +157,7 @@ static int quiescenceSearch(Game *b, int qdepth, int alpha, int beta, int ply) { }; return alpha; }; -static int search(int depth, Game *b, int alpha, int beta, int ply) { +static int search(int depth, Game *g, int alpha, int beta, int ply) { if (timeToThingMS == -1) { assert(false && "Expected set time: internal error"); exit(1); @@ -171,13 +173,13 @@ static int search(int depth, Game *b, int alpha, int beta, int ply) { return 0; } } - if (isRepetionDraw(b->hash, b)) { + if (isRepetionDraw(g->hash, g)) { return 0; }; TranspositionsEntry *entry = nullptr; - if (auto it = b->Transpositions->find(b->hash); - it != b->Transpositions->end()) { + if (auto it = g->Transpositions->find(g->hash); + it != g->Transpositions->end()) { entry = &it->second; if (entry->depth >= depth) { if (entry->flag == EXACT) { @@ -196,17 +198,20 @@ static int search(int depth, Game *b, int alpha, int beta, int ply) { } if (depth <= 0) { - return quiescenceSearch(b, 0, alpha, beta, ply); + return quiescenceSearch(g, 0, alpha, beta, ply); } uint16_t ttBestMove = entry != nullptr ? entry->bestMove : uint16_t{}; - std::vector<uint16_t> moves = GetSortedLegalMoves(b, ALL, &ttBestMove); + std::vector<uint16_t> moves = GetSortedLegalMoves(g, ALL, &ttBestMove); - if (moves.empty()) { - if (IsSquareAttacked(*b, FindKing(*b, b->turn), !b->turn)) { - return -(MATE - ply); // mated - } - return 0; // stalemate + switch (GetboardState(g, moves)) { + case WHITE_WON: + case BLACK_WON: + return -(MATE - ply); + case DRAW: + return 0; + case TURN: + break; } uint16_t bestMove = moves[0]; @@ -214,11 +219,11 @@ static int search(int depth, Game *b, int alpha, int beta, int ply) { int bestScore = -INF; for (uint16_t move : moves) { - Undo undo = MakeMove(move, b); + Undo undo = MakeMove(move, g); - int score = -search(depth - 1, b, -beta, -alpha, ply + 1); + int score = -search(depth - 1, g, -beta, -alpha, ply + 1); - UndoMove(undo, b); + UndoMove(undo, g); if (searchStopped) { break; } @@ -239,7 +244,7 @@ static int search(int depth, Game *b, int alpha, int beta, int ply) { flag = UPPERBOUND; } - (*b->Transpositions)[b->hash] = { + (*g->Transpositions)[g->hash] = { .depth = depth, .Eval = bestScore, .flag = flag, .bestMove = bestMove}; } return bestScore; |
