From 8159133f90d21b4aa2ab4d6eefc3a683bf417d1d Mon Sep 17 00:00:00 2001 From: IIvec Date: Fri, 13 Aug 2021 13:49:06 +0200 Subject: [PATCH 1/2] CorChess 2 Engine developed to be weaker in blitz, but better for long analysis. --- src/Makefile | 4 ++-- src/evaluate.cpp | 23 +++++------------------ src/misc.cpp | 2 +- src/nnue/evaluate_nnue.cpp | 18 ++++++++++++++---- src/search.cpp | 38 +++++++++++++++++++++++--------------- 5 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/Makefile b/src/Makefile index b021ba1214d..f1f1394faf7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -21,9 +21,9 @@ ### Executable name ifeq ($(COMP),mingw) -EXE = stockfish.exe +EXE = corchess.exe else -EXE = stockfish +EXE = corchess endif ### Installation dir definitions diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 64f9172574a..399147559b9 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -189,9 +189,7 @@ using namespace Trace; namespace { - // Threshold for lazy and space evaluation - constexpr Value LazyThreshold1 = Value(3130); - constexpr Value LazyThreshold2 = Value(2204); + // Threshold for space evaluation constexpr Value SpaceThreshold = Value(11551); // KingAttackWeights[PieceType] contains king attack weights by piece type @@ -984,13 +982,7 @@ namespace { pe = Pawns::probe(pos); score += pe->pawn_score(WHITE) - pe->pawn_score(BLACK); - // Early exit if score is high - auto lazy_skip = [&](Value lazyThreshold) { - return abs(mg_value(score) + eg_value(score)) > lazyThreshold + pos.non_pawn_material() / 32; - }; - - if (lazy_skip(LazyThreshold1)) - goto make_v; + Value v; // Main evaluation begins here initialize(); @@ -1007,17 +999,12 @@ namespace { // More complex interactions that require fully populated attack bitboards score += king< WHITE>() - king< BLACK>() - + passed< WHITE>() - passed< BLACK>(); - - if (lazy_skip(LazyThreshold2)) - goto make_v; - - score += threats() - threats() + + passed< WHITE>() - passed< BLACK>() + + threats() - threats() + space< WHITE>() - space< BLACK>(); -make_v: // Derive single value from mg and eg parts of score - Value v = winnable(score); + v = winnable(score); // In case of tracing add all remaining individual evaluation terms if constexpr (T) diff --git a/src/misc.cpp b/src/misc.cpp index 3b071ccb108..ea097a4c0c9 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -146,7 +146,7 @@ string engine_info(bool to_uci) { string month, day, year; stringstream ss, date(__DATE__); // From compiler, format is "Sep 21 2008" - ss << "Stockfish " << Version << setfill('0'); + ss << "CorChess 2 " << Version << setfill('0'); if (Version.empty()) { diff --git a/src/nnue/evaluate_nnue.cpp b/src/nnue/evaluate_nnue.cpp index 891f8faad02..a0a01f4aa4b 100644 --- a/src/nnue/evaluate_nnue.cpp +++ b/src/nnue/evaluate_nnue.cpp @@ -164,11 +164,21 @@ namespace Stockfish::Eval::NNUE { const auto psqt = featureTransformer->transform(pos, transformedFeatures, bucket); const auto output = network[bucket]->propagate(transformedFeatures, buffer); - int materialist = psqt; - int positional = output[0]; + int materialist = psqt; + int positional = output[0]; + int entertainment = 0; - int delta_npm = abs(pos.non_pawn_material(WHITE) - pos.non_pawn_material(BLACK)); - int entertainment = (adjusted && delta_npm <= BishopValueMg - KnightValueMg ? 7 : 0); + if (adjusted) + { + Color stm = pos.side_to_move(); + int delta_npm = pos.non_pawn_material(stm) - pos.non_pawn_material(~stm); + + entertainment = (abs(delta_npm) <= BishopValueMg - KnightValueMg ? 7 : 0); + + if (abs(positional) > 5000) + entertainment += positional < 0 && materialist > 0 ? 10 + : positional > 0 && delta_npm > -KnightValueMg ? 10 : 0; + } int A = 128 - entertainment; int B = 128 + entertainment; diff --git a/src/search.cpp b/src/search.cpp index c48b74bcc76..55514e4675c 100644 --- a/src/search.cpp +++ b/src/search.cpp @@ -70,10 +70,11 @@ namespace { } // Reductions lookup table, initialized at startup - int Reductions[MAX_MOVES]; // [depth or moveNumber] + int DReductions[MAX_MOVES]; // [depth] + int MReductions[MAX_MOVES]; // [moveNumber] Depth reduction(bool i, Depth d, int mn) { - int r = Reductions[d] * Reductions[mn]; + int r = DReductions[d] * MReductions[mn]; return (r + 534) / 1024 + (!i && r > 904); } @@ -83,7 +84,7 @@ namespace { // History and stats update bonus, based on depth int stat_bonus(Depth d) { - return d > 14 ? 73 : 6 * d * d + 229 * d - 215; + return d > 32 ? 73 : d * d + 100 * d - 81; } // Add a small random component to draw evaluations to avoid 3-fold blindness @@ -151,8 +152,12 @@ namespace { void Search::init() { + double r = 16.0; for (int i = 1; i < MAX_MOVES; ++i) - Reductions[i] = int(21.9 * std::log(i)); + { + DReductions[i] = int(r * 0.4 * i * (1.0 - exp(-8.0 / i))); + MReductions[i] = int(r * log(i + 0.25 * log(i))); + } } @@ -256,7 +261,7 @@ void Thread::search() { // The latter is needed for statScore and killer initialization. Stack stack[MAX_PLY+10], *ss = stack+7; Move pv[MAX_PLY+1]; - Value bestValue, alpha, beta, delta; + Value bestValue, alpha, beta, delta1, delta2; Move lastBestMove = MOVE_NONE; Depth lastBestMoveDepth = 0; MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr); @@ -273,7 +278,7 @@ void Thread::search() { ss->pv = pv; - bestValue = delta = alpha = -VALUE_INFINITE; + bestValue = delta1 = delta2 = alpha = -VALUE_INFINITE; beta = VALUE_INFINITE; if (mainThread) @@ -354,9 +359,10 @@ void Thread::search() { if (rootDepth >= 4) { Value prev = rootMoves[pvIdx].previousScore; - delta = Value(17); - alpha = std::max(prev - delta,-VALUE_INFINITE); - beta = std::min(prev + delta, VALUE_INFINITE); + delta1 = (prev < 0) ? Value(8 + abs(prev) / 20) : Value(8); + delta2 = (prev > 0) ? Value(8 + abs(prev) / 20) : Value(8); + alpha = std::max(prev - delta1,-VALUE_INFINITE); + beta = std::min(prev + delta2, VALUE_INFINITE); // Adjust trend based on root move's previousScore (dynamic contempt) int tr = 113 * prev / (abs(prev) + 147); @@ -401,7 +407,7 @@ void Thread::search() { if (bestValue <= alpha) { beta = (alpha + beta) / 2; - alpha = std::max(bestValue - delta, -VALUE_INFINITE); + alpha = std::max(bestValue - delta1, -VALUE_INFINITE); failedHighCnt = 0; if (mainThread) @@ -409,13 +415,14 @@ void Thread::search() { } else if (bestValue >= beta) { - beta = std::min(bestValue + delta, VALUE_INFINITE); + beta = std::min(bestValue + delta2, VALUE_INFINITE); ++failedHighCnt; } else break; - delta += delta / 4 + 5; + delta1 += delta1 / 2; + delta2 += delta2 / 2; assert(alpha >= -VALUE_INFINITE && beta <= VALUE_INFINITE); } @@ -795,13 +802,14 @@ namespace { && eval >= ss->staticEval && ss->staticEval >= beta - 20 * depth - 22 * improving + 168 * ss->ttPv + 159 && !excludedMove - && pos.non_pawn_material(us) + && thisThread->selDepth + 5 > thisThread->rootDepth + && pos.non_pawn_material(us) > BishopValueMg && (ss->ply >= thisThread->nmpMinPly || us != thisThread->nmpColor)) { assert(eval - beta >= 0); // Null move dynamic reduction based on depth and value - Depth R = (1090 + 81 * depth) / 256 + std::min(int(eval - beta) / 205, 3); + Depth R = std::max(1, int(2.6 * log(depth)) + std::min(int(eval - beta) / 205, 3)); ss->currentMove = MOVE_NULL; ss->continuationHistory = &thisThread->continuationHistory[0][0][NO_PIECE][0]; @@ -1049,7 +1057,7 @@ namespace { /* && ttValue != VALUE_NONE Already implicit in the next condition */ && abs(ttValue) < VALUE_KNOWN_WIN && (tte->bound() & BOUND_LOWER) - && tte->depth() >= depth - 3) + && tte->depth() >= depth - 4) { Value singularBeta = ttValue - 2 * depth; Depth singularDepth = (depth - 1) / 2; From 54fe8af85e10db41a2bb863ce26836d20116eb2e Mon Sep 17 00:00:00 2001 From: IIvec Date: Tue, 17 Aug 2021 11:24:13 +0200 Subject: [PATCH 2/2] Authors clarification --- src/misc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc.cpp b/src/misc.cpp index ea097a4c0c9..483992a11c1 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -155,7 +155,7 @@ string engine_info(bool to_uci) { } ss << (to_uci ? "\nid author ": " by ") - << "the Stockfish developers (see AUTHORS file)"; + << "I. Ivec, the Stockfish developers (see AUTHORS file)"; return ss.str(); }