Skip to content

Commit

Permalink
Make contempt dependent on current score and reduce default contempt …
Browse files Browse the repository at this point in the history
…by 10%. Include suggestions from Marco Costalba, Aram Tumanian, Ronald de Man, Stephane Nicolet.

Bench: 5791090
  • Loading branch information
Stefano80 committed Feb 9, 2018
1 parent d71adc5 commit 2e4f1b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/evaluate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ namespace {

} // namespace

Score Eval::Contempt = SCORE_ZERO;
std::atomic<Score> Eval::Contempt;

/// evaluate() is the evaluator for the outer world. It returns a static evaluation
/// of the position from the point of view of the side to move.
Expand Down
3 changes: 2 additions & 1 deletion src/evaluate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#ifndef EVALUATE_H_INCLUDED
#define EVALUATE_H_INCLUDED

#include <atomic>
#include <string>

#include "types.h"
Expand All @@ -31,7 +32,7 @@ namespace Eval {

const Value Tempo = Value(20); // Must be visible to search

extern Score Contempt;
extern std::atomic<Score> Contempt;

std::string trace(const Position& pos);

Expand Down
20 changes: 15 additions & 5 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,6 @@ void MainThread::search() {
Time.init(Limits, us, rootPos.game_ply());
TT.new_search();

int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns

Eval::Contempt = (us == WHITE ? make_score(contempt, contempt / 2)
: -make_score(contempt, contempt / 2));

if (rootMoves.empty())
{
rootMoves.emplace_back(MOVE_NONE);
Expand Down Expand Up @@ -306,6 +301,10 @@ void Thread::search() {

multiPV = std::min(multiPV, rootMoves.size());

int contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
Eval::Contempt = (rootPos.side_to_move() == WHITE ? make_score(contempt, contempt / 2)
: -make_score(contempt, contempt / 2));

// Iterative deepening loop until requested to stop or the target depth is reached
while ( (rootDepth += ONE_PLY) < DEPTH_MAX
&& !Threads.stop
Expand Down Expand Up @@ -340,6 +339,17 @@ void Thread::search() {
delta = Value(18);
alpha = std::max(rootMoves[PVIdx].previousScore - delta,-VALUE_INFINITE);
beta = std::min(rootMoves[PVIdx].previousScore + delta, VALUE_INFINITE);

// Adjust contempt based on current situation

contempt = Options["Contempt"] * PawnValueEg / 100; // From centipawns
contempt += bestValue > 2 * PawnValueEg ? PawnValueEg / 5: // Dynamic contempt
bestValue < -2 * PawnValueEg ? -PawnValueEg / 5:
bestValue/10;

Eval::Contempt = (rootPos.side_to_move() == WHITE ? make_score(contempt, contempt / 2)
: -make_score(contempt, contempt / 2));

}

// Start with a small aspiration window and, in the case of a fail
Expand Down
2 changes: 1 addition & 1 deletion src/ucioption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void init(OptionsMap& o) {
const int MaxHashMB = Is64Bit ? 131072 : 2048;

o["Debug Log File"] << Option("", on_logger);
o["Contempt"] << Option(20, -100, 100);
o["Contempt"] << Option(18, -100, 100);
o["Threads"] << Option(1, 1, 512, on_threads);
o["Hash"] << Option(16, 1, MaxHashMB, on_hash_size);
o["Clear Hash"] << Option(on_clear_hash);
Expand Down

0 comments on commit 2e4f1b3

Please sign in to comment.