Skip to content

Commit

Permalink
Merge pull request #12 from Dannyj1/late-move-reduction
Browse files Browse the repository at this point in the history
Late move reduction

ELO | 7.96 +- 4.98 (95%)
SPRT | 10.0+0.10s Threads=1 Hash=64MB
LLR | 2.96 (-2.94, 2.94) [0.00, 3.00]
GAMES | N: 16448 W: 7443 L: 7066 D: 1939

Bench: 5504456
  • Loading branch information
Dannyj1 authored Jan 25, 2023
2 parents 530b135 + 4b8aa3d commit 9dff520
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/movepicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ namespace Zagreus {
int MovePicker::size() {
return moveList.size;
}

int MovePicker::remaining() {
return moveList.size - searchStartIndex;
}

int MovePicker::movesSearched() {
return searchStartIndex;
}
}
3 changes: 3 additions & 0 deletions src/movepicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ namespace Zagreus {

int size();

int remaining();

int movesSearched();
};
}
28 changes: 27 additions & 1 deletion src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ namespace Zagreus {
return bestMove;
}

// TODO: use template
int SearchManager::search(Bitboard &board, int depth, int alpha, int beta, Move &rootMove,
Move &previousMove,
std::chrono::time_point<std::chrono::high_resolution_clock> &endTime, Line &pvLine, ZagreusEngine &engine, bool isPv) {
Expand Down Expand Up @@ -241,6 +242,16 @@ namespace Zagreus {
return ttScore;
}

bool isOwnKingInCheck = false;

if (depth >= 3) {
if (board.getMovingColor() == PieceColor::WHITE) {
isOwnKingInCheck = board.isKingInCheck<PieceColor::WHITE>();
} else {
isOwnKingInCheck = board.isKingInCheck<PieceColor::BLACK>();
}
}

while (moves.hasNext()) {
if (searchStats.nodes % 2048 == 0 && (engine.stopRequested() || std::chrono::high_resolution_clock::now() > endTime)) {
return beta;
Expand All @@ -262,8 +273,23 @@ namespace Zagreus {
}
}

int depthReduction = 0;
bool isOpponentKingInCheck = false;

if (depth >= 3) {
if (board.getMovingColor() == PieceColor::WHITE) {
isOpponentKingInCheck = board.isKingInCheck<PieceColor::WHITE>();
} else {
isOpponentKingInCheck = board.isKingInCheck<PieceColor::BLACK>();
}
}

if (depth >= 3 && move.captureScore != -1 && move.promotionPiece == PieceType::EMPTY && !isOwnKingInCheck && !isOpponentKingInCheck) {
depthReduction = depth / 2;
}

int score;
score = search(board, depth - 1, -alpha - 1, -alpha, rootMove, previousMove, endTime, line, engine, false);
score = search(board, depth - 1 - depthReduction, -alpha - 1, -alpha, rootMove, previousMove, endTime, line, engine, false);
score *= -1;

if (score > alpha && score < beta) {
Expand Down

0 comments on commit 9dff520

Please sign in to comment.