예제 #1
0
        private async Task <IPerftResult> ComputePerft(CancellationToken cancellationToken)
        {
            _result.Clear();

            var pp = _perft.Positions.Last();

            var baseFileName = SaveResults ? Path.Combine(System.Environment.CurrentDirectory, $"{FixFileName(pp.Fen)}[") : string.Empty;

            var errors = 0;

            var sw = new Stopwatch();

            _result.Fen = pp.Fen;
            _perft.SetGamePosition(pp);
            PrintBoard(_perft.GetBoard());
            _log.Information("Fen         : {0}", pp.Fen);
            _log.Information(Line);

            foreach (var(depth, expected) in pp.Value)
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    _log.Information("Cancel requested.");
                    break;
                }

                _log.Information("Depth       : {0}", depth);
                sw.Restart();
                var result = await _perft.DoPerftAsync(depth).ConfigureAwait(false);

                sw.Stop();

                var elapsedMs = sw.ElapsedMilliseconds;

                await ComputeResults(result, depth, expected, elapsedMs, _result);

                errors += await LogResults(_result);

                if (!string.IsNullOrEmpty(baseFileName))
                {
                    File.WriteAllText($"{baseFileName}{_result.Depth}].json", JsonConvert.SerializeObject(_result));
                }
            }

            _log.Information("{0} parsing complete. Encountered {1} errors.", _usingEpd ? "EPD" : "FEN", errors);

            _result.Errors = errors;

            return(_result);
        }