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

🐛 Don't search with fixed depth when cutechess provides 0s to move #654

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/Lynx/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,28 @@ public SearchResult BestMove(GoCommand goCommand)
millisecondsIncrement = goCommand.BlackIncrement;
}

if (millisecondsLeft != 0) // Cutechess sometimes sends negative wtime/btime
if (goCommand.WhiteTime != 0 || goCommand.BlackTime != 0) // Cutechess sometimes sends negative wtime/btime
{
const int minSearchTime = 50;

if (goCommand.MovesToGo == default)
{
// Inspired by Alexandria: time overhead to avoid timing out in the engine-gui communication process
millisecondsLeft -= 50;
millisecondsLeft = Math.Clamp(millisecondsLeft, 50, int.MaxValue); // Avoiding 0/negative values
const int engineGuiCommunicationTimeOverhead = 50;

millisecondsLeft -= engineGuiCommunicationTimeOverhead;
millisecondsLeft = Math.Clamp(millisecondsLeft, minSearchTime, int.MaxValue); // Avoiding 0/negative values

// 1/30, suggested by Serdra (EP discord)
decisionTime = Convert.ToInt32(Math.Min(0.5 * millisecondsLeft, (millisecondsLeft * 0.03333) + millisecondsIncrement));
}
else
{
millisecondsLeft -= 500;
millisecondsLeft = Math.Clamp(millisecondsLeft, 50, int.MaxValue); // Avoiding 0/negative values
// I prefer to leave some 'just in case' time apart to avoid losing in the last move before the control
const int movesToGoTimeOverhead = 500;

millisecondsLeft -= movesToGoTimeOverhead;
millisecondsLeft = Math.Clamp(millisecondsLeft, minSearchTime, int.MaxValue); // Avoiding 0/negative values

decisionTime = Convert.ToInt32((millisecondsLeft / goCommand.MovesToGo) + millisecondsIncrement);
}
Expand Down