Skip to content

Commit

Permalink
Less time on first move, -5%.
Browse files Browse the repository at this point in the history
Bench 2353057
  • Loading branch information
xoto10 committed May 12, 2024
1 parent c43425b commit c2fcf6f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ void Search::Worker::start_searching() {
return;
}

main_manager()->tm.init(limits, rootPos.side_to_move(), rootPos.game_ply(), options);
main_manager()->tm.init(limits, rootPos.side_to_move(), rootPos.game_ply(), options,
main_manager()->originalPly);
tt.new_search();

if (rootMoves.empty())
Expand Down
1 change: 1 addition & 0 deletions src/search.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class SearchManager: public ISearchManager {
Depth depth) const;

Stockfish::TimeManagement tm;
int originalPly;
int callsCnt;
std::atomic_bool ponder;

Expand Down
1 change: 1 addition & 0 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ void ThreadPool::clear() {
main_manager()->callsCnt = 0;
main_manager()->bestPreviousScore = VALUE_INFINITE;
main_manager()->bestPreviousAverageScore = VALUE_INFINITE;
main_manager()->originalPly = -1;
main_manager()->previousTimeReduction = 1.0;
main_manager()->tm.clear();
}
Expand Down
10 changes: 9 additions & 1 deletion src/timeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace Stockfish {

const static double plyExtra[] = { 0.95, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 };

TimePoint TimeManagement::optimum() const { return optimumTime; }
TimePoint TimeManagement::maximum() const { return maximumTime; }

Expand All @@ -47,7 +49,8 @@ void TimeManagement::advance_nodes_time(std::int64_t nodes) {
void TimeManagement::init(Search::LimitsType& limits,
Color us,
int ply,
const OptionsMap& options) {
const OptionsMap& options,
int& originalPly) {
TimePoint npmsec = TimePoint(options["nodestime"]);

// If we have no time, we don't need to fully initialize TM.
Expand All @@ -58,6 +61,9 @@ void TimeManagement::init(Search::LimitsType& limits,
if (limits.time[us] == 0)
return;

if (originalPly == -1)
originalPly = ply;

TimePoint moveOverhead = TimePoint(options["Move Overhead"]);

// optScale is a percentage of available time to use for the current move.
Expand Down Expand Up @@ -106,6 +112,8 @@ void TimeManagement::init(Search::LimitsType& limits,
{
// Use extra time with larger increments
double optExtra = scaledInc < 500 ? 1.0 : 1.13;
if (ply - originalPly < 20)
optExtra *= plyExtra[(ply - originalPly) / 2];

// Calculate time constants based on current time left.
double logTimeInSec = std::log10(scaledTime / 1000.0);
Expand Down
2 changes: 1 addition & 1 deletion src/timeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct LimitsType;
// the maximum available time, the game move number, and other parameters.
class TimeManagement {
public:
void init(Search::LimitsType& limits, Color us, int ply, const OptionsMap& options);
void init(Search::LimitsType& limits, Color us, int ply, const OptionsMap& options, int& originalPly);

TimePoint optimum() const;
TimePoint maximum() const;
Expand Down

0 comments on commit c2fcf6f

Please sign in to comment.