Skip to content

Commit

Permalink
🐛 Check maxDepth when btime wtime or MoveTime go commands are pro…
Browse files Browse the repository at this point in the history
…vided (#361)

We were not stopping IDDFS search when target depth > max depth, since there wasn't really a max depth, so it was totally up to NegaMax to cut long depths.
NMP extends ply, and hence the error
  • Loading branch information
eduherminio authored Aug 19, 2023
1 parent e96b682 commit d9a27ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Lynx/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public async Task<SearchResult> BestMove(GoCommand? goCommand)
millisecondsIncrement = goCommand.BlackIncrement;
}

maxDepth = Configuration.EngineSettings.MaxDepth;

if (millisecondsLeft > 0)
{
// Inspired by Alexandria: time overhead to avoid timing out in the engine-gui communication process
Expand Down
39 changes: 26 additions & 13 deletions tests/Lynx.Test/BestMove/RegressionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,35 @@ public async Task PonderingCrash()
Assert.NotZero(searchResult.BestMove);
}

[Test]
public async Task DepthOverflow()
[TestCase("position fen r1bq1rk1/pp1nppbp/2p2np1/8/2QPP3/2N2N2/PP2BPPP/R1B1K2R w KQ - 0 1" +
" moves c1f4 d7b6 c4b4 c8e6 e1g1 a7a5 b4c5 b6d7 c5a3 d8b6 e4e5 f6d5 c3d5 e6d5 f1d1 a8d8 f4d2 d8a8" +
" a3e7 f8d8 d2c3 a5a4 d1d2 g7h6 d2c2 h6g7 c2c1 c6c5 c1d1 a8c8 e7d6 d5c6 d4c5 d7c5 d6e7 d8e8 e7h4" +
" c6f3 e2f3 g7e5 c3e5 e8e5 h4d4 b6f6 d4b4 g8g7 d1d2 c8e8 a1f1 b7b6 d2d1 h7h6 b4c4 e5e7 b2b4 a4b3" +
" a2b3 c5e4 b3b4 e4c3 d1d3 c3e4 b4b5 f6b2 c4d4 b2d4 d3d4 e7e5 f3e4 e5e4 d4e4 e8e4 f1b1 g7f6 f2f3" +
" e4e5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4 f3e3 c4c3 e3f4 c3c4 f4f3 c4c3 f3e2 c3c2 e2e1 f6e6 e1f1 e6f6 f1g2 f6e6 b7a7" +
" e6f6 g2f3 c2b2 a7c7 b2a2 f3e3 a2a3 e3d4 a3a2 c7c6 f6g7 d4e3 a2a3 e3f4 a3a4 f4f3 g7f7 h4h5 g6h5" +
" c6h6 a4a2 h6h5 f7f6 f3e3 a2b2 h5h7 f6e6 e3f3 e6d5 h7e7 d5d6 e7e8 b2a2 f3e3 a2b2 f2f4 b2c2 e8e5" +
" c2c5 e5c5 d6c5 e3f3 c5d6 g3g4 f5g4 f3g4 d6c6 f4f5 c6d7 g4g5 d7e7 g5g6 e7f8 g6f6 f8e8 f6g7 e8d7" +
" f5f6 d7e6 f6f7 e6f5 f7f8q f5g5 f8c5 g5g4 g7f7 g4f4 c5b4 f4e3 b4c3 e3e4 c3b4 e4e3 f7f6 e3f3 b4d2" +
" f3g4 f6f7 g4f3 d2d3 f3f2 f7f8 f2g1 d3e3 g1g2 e3e2 g2g3 f8e7 g3h3 e7d7 h3h4 e2g2 h4h5 d7e6 h5h6 e6d7",
Description = "FEN 8/3K4/7k/8/8/8/6Q1/8 b - - 0 1")]
public async Task DepthOverflow(string positionCommand)
{
var engine = GetEngine();

// 8/8/2k5/8/K7/4q3/8/8 w - - 0 1 but
engine.AdjustPosition("position fen r1bq1rk1/pp1nppbp/2p2np1/8/2QPP3/2N2N2/PP2BPPP/R1B1K2R w KQ - 0 1" +
" moves c1f4 d7b6 c4b4 c8e6 e1g1 a7a5 b4c5 b6d7 c5a3 d8b6 e4e5 f6d5 c3d5 e6d5 f1d1 a8d8 f4d2 d8a8" +
" a3e7 f8d8 d2c3 a5a4 d1d2 g7h6 d2c2 h6g7 c2c1 c6c5 c1d1 a8c8 e7d6 d5c6 d4c5 d7c5 d6e7 d8e8 e7h4" +
" c6f3 e2f3 g7e5 c3e5 e8e5 h4d4 b6f6 d4b4 g8g7 d1d2 c8e8 a1f1 b7b6 d2d1 h7h6 b4c4 e5e7 b2b4 a4b3" +
" a2b3 c5e4 b3b4 e4c3 d1d3 c3e4 b4b5 f6b2 c4d4 b2d4 d3d4 e7e5 f3e4 e5e4 d4e4 e8e4 f1b1 g7f6 f2f3" +
" e4e5 g1f2 h6h5 b1b4 f6f5 h2h4 e5d5 f2e3 d5e5 e3f2 f7f6 g2g4 f5e6 f3f4 e5c5 f4f5 e6f7 f5g6 f7g6" +
" g4h5 g6h5 f2e3 f6f5 e3d3 c5d5 d3e3 h5g6 b4b2 g6f6 b2b4 f6e5 e3e2 f5f4 h4h5 e5f5 h5h6 d5d6 b4c4" +
" d6h6 c4c6 h6c6 b5c6 f5e6 e2d3 b6b5 d3e4 b5b4 c6c7 e6d7 c7c8q d7c8 e4f4 b4b3 f4e4 b3b2 e4f3" +
" b2b1q f3f2 c8c7 f2e2 b1a2 e2d1 a2f2 d1c1 f2e2 c1b1 e2d3 b1a2 d3d2 a2b3 c7c6 b3c4 d2e3 c4b4 e3d3" +
" b4a4 d3e3");
engine.AdjustPosition(positionCommand);

var result = await engine.BestMove(new("go wtime 3600000 btime 3600000"));
Assert.Less(result.DepthReached, Configuration.EngineSettings.MaxDepth);
Expand Down

0 comments on commit d9a27ca

Please sign in to comment.