Beispiel #1
0
        private async Task <PerftResult> ComputePerft(CancellationToken cancellationToken)
        {
            var result = _resultPool.Get();

            result.Clear();

            var pp = _perft.Positions.Last();

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

            var errors = 0;

            var sw = new Stopwatch();

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

            foreach (var(depth, expected) in pp.Value)
            {
                cancellationToken.ThrowIfCancellationRequested();

                _log.Information("Depth       : {0}", depth);
                sw.Restart();

                var perftResult = await _perft.DoPerftAsync(depth).ConfigureAwait(false);

                sw.Stop();

                var elapsedMs = sw.ElapsedMilliseconds;

                ComputeResultsAsync(perftResult, depth, expected, elapsedMs, result);

                errors += await LogResults(result).ConfigureAwait(false);

                if (baseFileName.IsNullOrEmpty())
                {
                    continue;
                }

                await WriteOutput(result, baseFileName, cancellationToken);
            }

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

            result.Errors = errors;

            return(result);
        }
Beispiel #2
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);
        }