Skip to content

Commit

Permalink
Merge branch 'corchess' into master-1
Browse files Browse the repository at this point in the history
  • Loading branch information
IIvec committed Oct 6, 2021
2 parents 54a9899 + 3e2d3e4 commit 2983757
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Expand Up @@ -21,9 +21,9 @@

### Executable name
ifeq ($(COMP),mingw)
EXE = stockfish.exe
EXE = corchess.exe
else
EXE = stockfish
EXE = corchess
endif

### Installation dir definitions
Expand Down
23 changes: 5 additions & 18 deletions src/evaluate.cpp
Expand Up @@ -191,9 +191,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
Expand Down Expand Up @@ -986,13 +984,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<WHITE>();
Expand All @@ -1009,17 +1001,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<WHITE>() - threats<BLACK>()
+ passed< WHITE>() - passed< BLACK>()
+ threats<WHITE>() - threats<BLACK>()
+ 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)
Expand Down
4 changes: 2 additions & 2 deletions src/misc.cpp
Expand Up @@ -147,7 +147,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())
{
Expand All @@ -156,7 +156,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();
}
Expand Down
18 changes: 14 additions & 4 deletions src/nnue/evaluate_nnue.cpp
Expand Up @@ -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 <= RookValueMg - BishopValueMg ? 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) <= RookValueMg - BishopValueMg ? 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;
Expand Down
38 changes: 23 additions & 15 deletions src/search.cpp
Expand Up @@ -67,10 +67,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, bool rangeReduction) {
int r = Reductions[d] * Reductions[mn];
int r = DReductions[d] * MReductions[mn];
return (r + 534) / 1024 + (!i && r > 904) + rangeReduction;
}

Expand All @@ -80,7 +81,7 @@ namespace {

// History and stats update bonus, based on depth
int stat_bonus(Depth d) {
return std::min((6 * d + 229) * d - 215 , 2000);
return std::min((d + 100) * d - 81 , 2000);
}

// Add a small random component to draw evaluations to avoid 3-fold blindness
Expand Down Expand Up @@ -172,8 +173,12 @@ namespace {

void Search::init() {

double r = 16.0 + std::log(Threads.size()) / 2;
for (int i = 1; i < MAX_MOVES; ++i)
Reductions[i] = int((21.9 + std::log(Threads.size()) / 2) * 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)));
}
}


Expand Down Expand Up @@ -277,7 +282,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);
Expand All @@ -294,7 +299,7 @@ void Thread::search() {

ss->pv = pv;

bestValue = delta = alpha = -VALUE_INFINITE;
bestValue = delta1 = delta2 = alpha = -VALUE_INFINITE;
beta = VALUE_INFINITE;

if (mainThread)
Expand Down Expand Up @@ -381,9 +386,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);
Expand Down Expand Up @@ -428,21 +434,22 @@ 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)
mainThread->stopOnPonderhit = false;
}
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);
}
Expand Down Expand Up @@ -832,13 +839,14 @@ namespace {
&& eval >= ss->staticEval
&& ss->staticEval >= beta - 20 * depth - 22 * improving + 168 * ss->ttPv + 177
&& !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 = std::min(int(eval - beta) / 205, 3) + depth / 3 + 4;
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];
Expand Down Expand Up @@ -1092,7 +1100,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 - 3 * depth;
Depth singularDepth = (depth - 1) / 2;
Expand Down

0 comments on commit 2983757

Please sign in to comment.