Permalink
Browse files

First try, CST if value > alpha

  • Loading branch information...
MJZ1977 committed Feb 11, 2019
1 parent 3c92f84 commit 3fc5b396cd8b06bef2fbc7196680d4392ad18ca5
Showing with 12 additions and 12 deletions.
  1. +12 −12 src/search.cpp
@@ -104,7 +104,7 @@ namespace {
};

template <NodeType NT>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode);
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool CST);

template <NodeType NT>
Value qsearch(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth = DEPTH_ZERO);
@@ -408,7 +408,7 @@ void Thread::search() {
while (true)
{
Depth adjustedDepth = std::max(ONE_PLY, rootDepth - failedHighCnt * ONE_PLY);
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false);
bestValue = ::search<PV>(rootPos, ss, alpha, beta, adjustedDepth, false, true);

// Bring the best move to the front. It is critical that sorting
// is done with a stable algorithm because all the values but the
@@ -535,7 +535,7 @@ namespace {
// search<>() is the main search function for both PV and non-PV nodes

template <NodeType NT>
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode) {
Value search(Position& pos, Stack* ss, Value alpha, Value beta, Depth depth, bool cutNode, bool CST) {

constexpr bool PvNode = NT == PV;
const bool rootNode = PvNode && ss->ply == 0;
@@ -635,7 +635,7 @@ namespace {
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply) : VALUE_NONE;
ttMove = rootNode ? thisThread->rootMoves[thisThread->pvIdx].pv[0]
: ttHit ? tte->move() : MOVE_NONE;
ttPv = (ttHit && tte->is_pv()) || (PvNode && depth > 4 * ONE_PLY);
ttPv = (ttHit && tte->is_pv()) || (CST && depth > 4 * ONE_PLY);

// At non-PV nodes we check for an early TT cutoff
if ( !PvNode
@@ -790,7 +790,7 @@ namespace {

pos.do_null_move(st);

Value nullValue = -search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
Value nullValue = -search<NonPV>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode, false);

pos.undo_null_move();

@@ -810,7 +810,7 @@ namespace {
thisThread->nmpMinPly = ss->ply + 3 * (depth-R) / 4;
thisThread->nmpColor = us;

Value v = search<NonPV>(pos, ss, beta-1, beta, depth-R, false);
Value v = search<NonPV>(pos, ss, beta-1, beta, depth-R, false, false);

thisThread->nmpMinPly = 0;

@@ -848,7 +848,7 @@ namespace {

// If the qsearch held perform the regular search
if (value >= raisedBeta)
value = -search<NonPV>(pos, ss+1, -raisedBeta, -raisedBeta+1, depth - 4 * ONE_PLY, !cutNode);
value = -search<NonPV>(pos, ss+1, -raisedBeta, -raisedBeta+1, depth - 4 * ONE_PLY, !cutNode, false);

pos.undo_move(move);

@@ -861,7 +861,7 @@ namespace {
if ( depth >= 8 * ONE_PLY
&& !ttMove)
{
search<NT>(pos, ss, alpha, beta, depth - 7 * ONE_PLY, cutNode);
search<NT>(pos, ss, alpha, beta, depth - 7 * ONE_PLY, cutNode, false);

tte = TT.probe(posKey, ttHit);
ttValue = ttHit ? value_from_tt(tte->value(), ss->ply) : VALUE_NONE;
@@ -935,7 +935,7 @@ namespace {
{
Value singularBeta = std::max(ttValue - 2 * depth / ONE_PLY, -VALUE_MATE);
ss->excludedMove = move;
value = search<NonPV>(pos, ss, singularBeta - 1, singularBeta, depth / 2, cutNode);
value = search<NonPV>(pos, ss, singularBeta - 1, singularBeta, depth / 2, cutNode, false);
ss->excludedMove = MOVE_NONE;

if (value < singularBeta)
@@ -1071,7 +1071,7 @@ namespace {

Depth d = std::max(newDepth - std::max(r, DEPTH_ZERO), ONE_PLY);

value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true, false);

doFullDepthSearch = (value > alpha && d != newDepth);
}
@@ -1080,7 +1080,7 @@ namespace {

// Step 17. Full depth search when LMR is skipped or fails high
if (doFullDepthSearch)
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode);
value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, newDepth, !cutNode, (ttPv && value > alpha));

// For PV nodes only, do a full PV search on the first move or after a fail
// high (in the latter case search only if value < beta), otherwise let the
@@ -1090,7 +1090,7 @@ namespace {
(ss+1)->pv = pv;
(ss+1)->pv[0] = MOVE_NONE;

value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, false);
value = -search<PV>(pos, ss+1, -beta, -alpha, newDepth, false, true);
}

// Step 18. Undo move

0 comments on commit 3fc5b39

Please sign in to comment.