Skip to content

Commit 8c3267c

Browse files
authored
3.1.9: implement cutnode (#263)
http://chess.grantnet.us/test/29597/ ELO | 7.67 +- 4.46 (95%) SPRT | 10.0+0.10s Threads=1 Hash=8MB LLR | 2.95 (-2.94, 2.94) [0.00, 3.00] GAMES | N: 12504 W: 3492 L: 3216 D: 5796 http://chess.grantnet.us/test/29598/ ELO | 7.87 +- 4.45 (95%) SPRT | 60.0+0.60s Threads=1 Hash=64MB LLR | 2.95 (-2.94, 2.94) [0.00, 3.00] GAMES | N: 11744 W: 3088 L: 2822 D: 5834 BENCH: 3570544
1 parent 999b7ec commit 8c3267c

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

src/search.cpp

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ bool Search::isDraw()
127127
return false;
128128
}
129129

130-
EVAL Search::abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bool rootNode, Move skipMove/*= 0*/)
130+
EVAL Search::abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bool rootNode, bool cutNode, Move skipMove/*= 0*/)
131131
{
132132
//
133133
// qsearch
@@ -296,7 +296,7 @@ EVAL Search::abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bo
296296
int R = 5 + depth / 6 + std::min(3, (bestScore - beta) / 100);
297297

298298
m_position.MakeNullMove();
299-
EVAL nullScore = -abSearch(-beta, -beta + 1, depth - R, ply + 1, true, false);
299+
EVAL nullScore = -abSearch(-beta, -beta + 1, depth - R, ply + 1, true, false, !cutNode);
300300
m_position.UnmakeNullMove();
301301

302302
if (nullScore >= beta)
@@ -327,7 +327,7 @@ EVAL Search::abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bo
327327
auto score = -qSearch(-betaCut, -betaCut + 1, ply, 0);
328328

329329
if (score >= betaCut)
330-
score = -abSearch(-betaCut, -betaCut + 1, depth - 4, ply + 1, false, false);
330+
score = -abSearch(-betaCut, -betaCut + 1, depth - 4, ply + 1, false, false, !cutNode);
331331

332332
m_position.UnmakeMove();
333333

@@ -416,7 +416,7 @@ EVAL Search::abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bo
416416

417417
if (depth >= 8 && !skipMove && hashMove == mv && !rootNode && !isCheckMateScore(hEntry.m_data.score) && (hEntry.m_data.type == HASH_BETA || hEntry.m_data.type == HASH_EXACT) && hEntry.m_data.depth >= depth - 3) {
418418
auto betaCut = hEntry.m_data.score - depth;
419-
auto score = abSearch(betaCut - 1, betaCut, depth / 2, ply + 1, false, false, mv);
419+
auto score = abSearch(betaCut - 1, betaCut, depth / 2, ply + 1, false, false, cutNode, mv);
420420

421421
if (score < betaCut)
422422
extension = 1;
@@ -443,41 +443,44 @@ EVAL Search::abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bo
443443

444444
newDepth += extensionRequired(m_position.InCheck(), onPV, history.cmhistory, history.fmhistory) + extension;
445445

446-
EVAL e;
447-
if (legalMoves == 1)
448-
e = -abSearch(-beta, -alpha, newDepth, ply + 1, false, false);
449-
else
450-
{
451-
//
452-
// lmr
453-
//
446+
//
447+
// lmr
448+
//
454449

455-
int reduction = 0;
450+
int reduction = 0;
456451

457-
if (depth >= 3 && quietMove && legalMoves > 1 + 2 * rootNode) {
458-
reduction = m_logLMRTable[std::min(depth, 63)][std::min(legalMoves, 63)];
452+
if (depth >= 3 && quietMove && legalMoves > 1 + 2 * rootNode) {
453+
reduction = m_logLMRTable[std::min(depth, 63)][std::min(legalMoves, 63)];
459454

460-
if (onPV)
461-
reduction -= 2;
455+
reduction += cutNode;
462456

463-
reduction -= mv == m_killerMoves[ply][0]
464-
|| mv == m_killerMoves[ply][1];
457+
if (onPV)
458+
reduction -= 2;
465459

466-
reduction -= std::max(-2, std::min(2, (history.history + history.cmhistory + history.fmhistory) / 5000));
460+
reduction -= mv == m_killerMoves[ply][0]
461+
|| mv == m_killerMoves[ply][1];
467462

468-
if (reduction >= newDepth)
469-
reduction = newDepth - 1;
470-
else if (reduction < 0)
471-
reduction = 0;
472-
}
463+
reduction -= std::max(-2, std::min(2, (history.history + history.cmhistory + history.fmhistory) / 5000));
464+
465+
if (reduction >= newDepth)
466+
reduction = newDepth - 1;
467+
else if (reduction < 0)
468+
reduction = 0;
469+
}
473470

474-
e = -abSearch(-alpha - 1, -alpha, newDepth - reduction, ply + 1, false, false);
471+
EVAL e;
472+
473+
if (reduction) {
474+
e = -abSearch(-alpha - 1, -alpha, newDepth - reduction, ply + 1, false, false, true);
475475

476-
if (e > alpha && reduction > 0)
477-
e = -abSearch(-alpha - 1, -alpha, newDepth, ply + 1, false, false);
478-
if (e > alpha && e < beta)
479-
e = -abSearch(-beta, -alpha, newDepth, ply + 1, false, false);
476+
if (e > alpha)
477+
e = -abSearch(-alpha - 1, -alpha, newDepth, ply + 1, false, false, !cutNode);
480478
}
479+
else if (!onPV || legalMoves > 1)
480+
e = -abSearch(-alpha - 1, -alpha, newDepth, ply + 1, false, false, !cutNode);
481+
482+
if (onPV && (legalMoves == 1 || e > alpha))
483+
e = -abSearch(-beta, -alpha, newDepth, ply + 1, false, false, false);
481484

482485
m_position.UnmakeMove();
483486

@@ -1076,7 +1079,7 @@ uint64_t Search::startSearch(Time time, int depth, bool ponderSearch, bool bench
10761079
EVAL beta = std::min(m_score + aspiration, CHECKMATE_SCORE);
10771080

10781081
while (aspiration <= CHECKMATE_SCORE) {
1079-
auto score = abSearch(alpha, beta, m_depth, 0, false, true);
1082+
auto score = abSearch(alpha, beta, m_depth, 0, false, true, false);
10801083

10811084
if (m_flags & SEARCH_TERMINATED)
10821085
break;

src/search.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Search
9090
#if defined (SYZYGY_SUPPORT)
9191
Move tableBaseRootSearch();
9292
#endif
93-
EVAL abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bool rootNode, Move skipMove = 0);
93+
EVAL abSearch(EVAL alpha, EVAL beta, int depth, int ply, bool isNull, bool rootNode, bool cutNode, Move skipMove = 0);
9494
EVAL qSearch(EVAL alpha, EVAL beta, int ply, int depth, bool isNull = false);
9595
inline int extensionRequired(bool inCheck, bool onPV, int cmhistory, int fmhistory);
9696
bool ProbeHash(TEntry & hentry);

src/uci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <iostream>
3131
#include <sstream>
3232

33-
const std::string VERSION = "3.1.8";
33+
const std::string VERSION = "3.1.9";
3434

3535
#if defined(ENV64BIT)
3636
#if defined(_BTYPE)

0 commit comments

Comments
 (0)