Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 Ponder: stop modifying GoCommand.Ponder #1262

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lynx/Bench.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public partial class Engine
var goCommand = new GoCommand($"go depth {depth}");
var searchConstraints = TimeManager.CalculateTimeManagement(Game, goCommand);

var result = BestMove(goCommand, in searchConstraints);
var result = BestMove(in searchConstraints);

var elapsedSeconds = Utils.CalculateElapsedSeconds(_stopWatch);
totalSeconds += elapsedSeconds;
Expand Down
15 changes: 6 additions & 9 deletions src/Lynx/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void WarmupEngine()
AdjustPosition(Constants.SuperLongPositionCommand);

var searchConstrains = TimeManager.CalculateTimeManagement(Game, command);
BestMove(command, in searchConstrains);
BestMove(in searchConstrains);

Bench(2);

Expand Down Expand Up @@ -152,10 +152,10 @@ public SearchResult BestMove(GoCommand goCommand)
{
var searchConstraints = TimeManager.CalculateTimeManagement(Game, goCommand);

return BestMove(goCommand, in searchConstraints);
return BestMove(in searchConstraints);
}

public SearchResult BestMove(GoCommand goCommand, in SearchConstraints searchConstrains)
public SearchResult BestMove(in SearchConstraints searchConstrains)
{
_searchConstraints = searchConstrains;

Expand All @@ -171,7 +171,7 @@ public SearchResult BestMove(GoCommand goCommand, in SearchConstraints searchCon
//SearchResult resultToReturn = await SearchBestMove(maxDepth, decisionTime);

Game.ResetCurrentPositionToBeforeSearchState();
if (!goCommand.Ponder
if (!_isPondering
&& resultToReturn.BestMove != default
&& !_absoluteSearchCancellationTokenSource.IsCancellationRequested)
{
Expand Down Expand Up @@ -241,12 +241,10 @@ private async ValueTask<SearchResult> SearchBestMove()
try
{
_isPondering = goCommand.Ponder;
var searchResult = BestMove(goCommand, in searchConstraints);
var searchResult = BestMove(in searchConstraints);

if (_isPondering)
{
// Using either field or local copy for the rest of the method, since goCommand.Ponder could change

// Avoiding the scenario where search finishes early (i.e. mate detected, max depth reached) and results comes
// before a potential ponderhit command
// _absoluteSearchCancellationTokenSource.IsCancellationRequested isn't reliable because
Expand All @@ -257,9 +255,8 @@ private async ValueTask<SearchResult> SearchBestMove()
{
_isPonderHit = false;
_isPondering = false;
goCommand.DisablePonder();

searchResult = BestMove(goCommand, in searchConstraints);
searchResult = BestMove(in searchConstraints);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/Lynx/UCI/Commands/GUI/GoCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public sealed class GoCommand : IGUIBaseCommand
public int Depth { get; }
public int MoveTime { get; }
public bool Infinite { get; }
public bool Ponder { get; private set; }
public bool Ponder { get; }

public static int Nodes => throw new NotImplementedException();
public static int Mate => throw new NotImplementedException();
Expand Down Expand Up @@ -179,6 +179,4 @@ public GoCommand(string command)
}

public static string Init() => Id;

public void DisablePonder() => Ponder = false;
}
Loading