Skip to content

Commit

Permalink
Fixed some SE bugs. Untuned, may be elo loss.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyan11 committed Oct 27, 2015
1 parent c3ff52c commit bd1a001
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,9 +623,9 @@ int PVS(Board &b, int depth, int alpha, int beta, SearchPV *pvLine) {
}


int extension = 0;
// Check extensions
bool isCheckExtension = false;
int extension = 0;
if (depth >= 5 && reduction == 0
&& searchParams.extensions < 2 + searchParams.rootDepth / 4
&& copy.isInCheck(color^1)
Expand All @@ -637,29 +637,40 @@ int PVS(Board &b, int depth, int alpha, int beta, SearchPV *pvLine) {


// Singular extensions
// If one move appears to be much better than all others, extend the move
if (depth >= 6 && reduction == 0 && extension == 0
&& !searchParams.lastSingular && m == hashed
&& ((hashScore >= beta && entry->depth >= depth - 4)
&& searchParams.singularExtensions <= searchParams.rootDepth
&& m == hashed
&& abs(hashScore) < 2 * QUEEN_VALUE
&& ((hashScore >= beta && (nodeType == CUT_NODE || nodeType == PV_NODE)
&& entry->depth >= depth - 4)
|| (isPVNode && nodeType == PV_NODE && entry->depth >= depth - 2))) {

bool isSingular = true;

// Do a reduced depth search with a lowered window for a fail low check
for (unsigned int i = 0; i < legalMoves.size(); i++) {
Move seMove = legalMoves.get(i);
Board copy = b.staticCopy();
if (m == hashed)
// Search every move except the hash move
if (seMove == hashed)
continue;
if (!copy.doPseudoLegalMove(m, color))
if (!copy.doPseudoLegalMove(seMove, color))
continue;

int SEWindow = isPVNode ? -hashScore - 150 - 3 * depth
: -alpha - 100 - 2 * depth;
int SEDepth = isPVNode ? 3 * depth / 4 - 2
// The window is lowered more for PV nodes and for higher depths
int SEWindow = isPVNode ? hashScore - 80 - 3 * depth
: alpha - 20 - 2 * depth;
// Do a reduced search for fail-low confirmation
int SEDepth = isPVNode ? 3 * depth / 4 - 1
: depth / 2 - 1;

searchParams.ply++;
score = -PVS(copy, SEDepth, SEWindow - 1, SEWindow, &line);
score = -PVS(copy, SEDepth, -SEWindow - 1, -SEWindow, &line);
searchParams.ply--;

if (score >= SEWindow) {
// If a move did not fail low, no singular extension
if (score > SEWindow) {
isSingular = false;
break;
}
Expand All @@ -669,7 +680,7 @@ int PVS(Board &b, int depth, int alpha, int beta, SearchPV *pvLine) {
// the singular move
if (isSingular) {
extension++;
searchParams.lastSingular = true;
searchParams.singularExtensions++;
}
}

Expand Down Expand Up @@ -711,7 +722,7 @@ int PVS(Board &b, int depth, int alpha, int beta, SearchPV *pvLine) {
searchParams.extensions -= extension;
// If the extension was a singular extension, reset the consecutive singular check
else if (extension)
searchParams.lastSingular = false;
searchParams.singularExtensions--;

// Beta cutoff
if (score >= beta) {
Expand Down
4 changes: 2 additions & 2 deletions searchparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct SearchParameters {
int nullMoveCount;
int extensions;
int selectiveDepth;
bool lastSingular;
int singularExtensions;
ChessTime startTime;
uint64_t timeLimit;
Move killers[MAX_DEPTH][2];
Expand All @@ -44,7 +44,7 @@ struct SearchParameters {
nullMoveCount = 0;
extensions = 0;
selectiveDepth = 0;
lastSingular = false;
singularExtensions = 0;
for (int i = 0; i < MAX_DEPTH; i++) {
killers[i][0] = NULL_MOVE;
killers[i][1] = NULL_MOVE;
Expand Down

0 comments on commit bd1a001

Please sign in to comment.