Skip to content

Commit

Permalink
Use less time on recaptures, credit to peregrine in Discord for the i…
Browse files Browse the repository at this point in the history
…dea.

Bench 1836777
  • Loading branch information
xoto10 committed Apr 28, 2024
1 parent 49ef4c9 commit 3d1a768
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
12 changes: 10 additions & 2 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Engine::Engine(std::string path) :
NN::NetworkBig({EvalFileDefaultNameBig, "None", ""}, NN::EmbeddedNNUEType::BIG),
NN::NetworkSmall({EvalFileDefaultNameSmall, "None", ""}, NN::EmbeddedNNUEType::SMALL))) {
pos.set(StartFEN, false, &states->back());
capSq = SQ_NONE;
}

std::uint64_t Engine::perft(const std::string& fen, Depth depth, bool isChess960) {
Expand All @@ -61,9 +62,10 @@ std::uint64_t Engine::perft(const std::string& fen, Depth depth, bool isChess960
return Benchmark::perft(fen, depth, isChess960);
}

void Engine::go(const Search::LimitsType& limits) {
void Engine::go(Search::LimitsType& limits) {
assert(limits.perft == 0);
verify_networks();
limits.capSq = capSq;

threads.start_thinking(options, pos, states, limits);
}
Expand Down Expand Up @@ -102,6 +104,7 @@ void Engine::set_position(const std::string& fen, const std::vector<std::string>
states = StateListPtr(new std::deque<StateInfo>(1));
pos.set(fen, options["UCI_Chess960"], &states->back());

capSq = SQ_NONE;
for (const auto& move : moves)
{
auto m = UCIEngine::to_move(pos, move);
Expand All @@ -111,6 +114,11 @@ void Engine::set_position(const std::string& fen, const std::vector<std::string>

states->emplace_back();
pos.do_move(m, states->back());

capSq = SQ_NONE;
DirtyPiece& dp = states->back().dirtyPiece;
if (dp.dirty_num > 1 && dp.to[1] == SQ_NONE)
capSq = m.to_sq();
}
}

Expand Down Expand Up @@ -172,4 +180,4 @@ std::string Engine::visualize() const {
return ss.str();
}

}
}
6 changes: 4 additions & 2 deletions src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "search.h"
#include "thread.h"
#include "tt.h"
#include "types.h"
#include "ucioption.h"
#include "syzygy/tbprobe.h" // for Stockfish::Depth

Expand All @@ -50,7 +51,7 @@ class Engine {
std::uint64_t perft(const std::string& fen, Depth depth, bool isChess960);

// non blocking call to start searching
void go(const Search::LimitsType&);
void go(Search::LimitsType&);
// non blocking call to stop searching
void stop();

Expand Down Expand Up @@ -92,6 +93,7 @@ class Engine {

Position pos;
StateListPtr states;
Square capSq;

OptionsMap options;
ThreadPool threads;
Expand All @@ -104,4 +106,4 @@ class Engine {
} // namespace Stockfish


#endif // #ifndef ENGINE_H_INCLUDED
#endif // #ifndef ENGINE_H_INCLUDED
7 changes: 4 additions & 3 deletions src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ using namespace Search;

namespace {

static constexpr double EvalLevel[10] = {1.043, 1.017, 0.952, 1.009, 0.971,
1.002, 0.992, 0.947, 1.046, 1.001};
static constexpr double EvalLevel[10] = {0.981, 0.956, 0.895, 0.949, 0.913,
0.942, 0.933, 0.890, 0.984, 0.941};

// Futility margin
Value futility_margin(Depth d, bool noTtCutNode, bool improving, bool oppWorsening) {
Expand Down Expand Up @@ -446,9 +446,10 @@ void Search::Worker::iterative_deepening() {
double reduction = (1.48 + mainThread->previousTimeReduction) / (2.17 * timeReduction);
double bestMoveInstability = 1 + 1.88 * totBestMoveChanges / threads.size();
int el = std::clamp((bestValue + 750) / 150, 0, 9);
double recapture = limits.capSq == rootMoves[0].pv[0].to_sq() ? 0.955 : 1.005;

double totalTime = mainThread->tm.optimum() * fallingEval * reduction
* bestMoveInstability * EvalLevel[el];
* bestMoveInstability * EvalLevel[el] * recapture;

// Cap used time in case of a single legal move for a better viewer experience
if (rootMoves.size() == 1)
Expand Down
4 changes: 2 additions & 2 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ struct RootMove {
using RootMoves = std::vector<RootMove>;


// LimitsType struct stores information sent by GUI about available time to
// search the current move, maximum depth/time, or if we are in analysis mode.
// LimitsType struct stores information sent by the caller about the analysis required.
struct LimitsType {

// Init explicitly due to broken value-initialization of non POD in MSVC
Expand All @@ -128,6 +127,7 @@ struct LimitsType {
int movestogo, depth, mate, perft, infinite;
uint64_t nodes;
bool ponderMode;
Square capSq;
};


Expand Down

0 comments on commit 3d1a768

Please sign in to comment.