Skip to content

Commit b7942c1

Browse files
committed
upgraded wac to use the revised wac with 300 positions from https://arasanchess.org/tests.zip
the CompareBestMove test is now made with a time budget instead of a depth limit
1 parent 7dc749e commit b7942c1

File tree

2 files changed

+124
-15
lines changed

2 files changed

+124
-15
lines changed

MinimalChessBoard/Program.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,10 @@ static void Main()
7676
Console.WriteLine($"{board.SideToMove} >> {move}");
7777
board.Play(move);
7878
}
79-
else if (command == "?" && tokens.Length > 2)
79+
else if (command == "?" && tokens.Length == 3)
8080
{
81-
int depth = int.Parse(tokens[1]);
82-
int num = (tokens.Length > 3) ? int.Parse(tokens[3]) : int.MaxValue;
83-
CompareBestMove(depth, tokens[2], num);
81+
int timeBudgetMs = int.Parse(tokens[2]);
82+
CompareBestMove(tokens[1], timeBudgetMs);
8483
}
8584
else if (command == "?")
8685
{
@@ -209,14 +208,14 @@ private static long Perft(Board board, int depth)
209208
return 1;
210209

211210
//probe hash-tree
212-
if (PerftTable.Retrieve(board.ZobristHash, depth, out long childCount))
213-
return childCount;
211+
//if (PerftTable.Retrieve(board.ZobristHash, depth, out long childCount))
212+
// return childCount;
214213

215214
long sum = 0;
216215
foreach (var move in new LegalMoves(board))
217216
sum += Perft(new Board(board, move), depth - 1);
218217

219-
PerftTable.Store(board.ZobristHash, depth, sum);
218+
//PerftTable.Store(board.ZobristHash, depth, sum);
220219
return sum;
221220
}
222221

@@ -287,7 +286,7 @@ private static void ComparePerft(int depth, string filePath)
287286
}
288287

289288

290-
private static void CompareBestMove(int depth, string filePath, int maxCount)
289+
private static void CompareBestMove(string filePath, int timeBudgetMs)
291290
{
292291
var file = File.OpenText(filePath);
293292
double freq = Stopwatch.Frequency;
@@ -296,26 +295,36 @@ private static void CompareBestMove(int depth, string filePath, int maxCount)
296295
int count = 0;
297296
int foundBest = 0;
298297
List<Move> bestMoves = new List<Move>();
299-
while (!file.EndOfStream && count < maxCount)
298+
while (!file.EndOfStream)
300299
{
301300
ParseEpd(file.ReadLine(), out Board board, ref bestMoves);
302301
Transpositions.Clear();
302+
IterativeSearch search = new IterativeSearch(board);
303+
Move pvMove = default;
303304
long t0 = Stopwatch.GetTimestamp();
304-
IterativeSearch search = new IterativeSearch(depth, board);
305+
long tStop = t0 + (timeBudgetMs * Stopwatch.Frequency) / 1000;
306+
//search until running out of time
307+
while (true)
308+
{
309+
search.SearchDeeper(() => Stopwatch.GetTimestamp() > tStop);
310+
if (search.Aborted)
311+
break;
312+
pvMove = search.PrincipalVariation[0];
313+
}
305314
long t1 = Stopwatch.GetTimestamp();
306315
long dt = t1 - t0;
307316
totalTime += dt;
308317
totalNodes += search.NodesVisited;
309318
count++;
310319
string pvString = string.Join(' ', search.PrincipalVariation);
311-
bool foundBestMove = bestMoves.Contains(search.PrincipalVariation[0]);
320+
bool foundBestMove = bestMoves.Contains(pvMove);
312321
if (foundBestMove)
313322
foundBest++;
314323
Console.WriteLine($"{count,4}. {(foundBestMove ? "[X]" : "[ ]")} {pvString} = {search.Score:+0.00;-0.00}, {search.NodesVisited / 1000}K nodes, { 1000 * dt / freq}ms");
315324
Console.WriteLine($"{totalNodes,14} nodes, { (int)(totalTime / freq)} seconds, {foundBest} solved.");
316325
}
317326
Console.WriteLine();
318-
Console.WriteLine($"Searched {count} positions to depth {depth}. {totalNodes/1000}K nodes visited. Took {totalTime/freq:0.###} seconds!");
327+
Console.WriteLine($"Searched {count} positions for {timeBudgetMs}ms each. {totalNodes/1000}K nodes visited. Took {totalTime/freq:0.###} seconds!");
319328
Console.WriteLine($"Best move found in {foundBest} / {count} positions!");
320329
}
321330

0 commit comments

Comments
 (0)