public void TestPerft(PerftPosition perftPosition, bool enableParallelism, ExpectedPerftResult expectedResult) { var fen = PerftPositionToFenMap[perftPosition]; var gameBoard = new GameBoard(fen, PerformInternalBoardValidation); var flags = PerftFlags.IncludeDivideMap; if (enableParallelism) { flags |= PerftFlags.EnableParallelism; } var includeExtraCountTypes = expectedResult.CheckCount.HasValue || expectedResult.CheckmateCount.HasValue; if (includeExtraCountTypes) { flags |= PerftFlags.IncludeExtraCountTypes; } #region For Finding Bugs in Move Generator var extraMoves = new GameMove[] { }; gameBoard = extraMoves.Aggregate(gameBoard, (current, extraMove) => current.MakeMove(extraMove)); #endregion var actualResult = gameBoard.Perft(expectedResult.Depth - extraMoves.Length, flags); string extraInfo = null; if (actualResult.Flags.HasFlag(PerftFlags.IncludeDivideMap)) { var divideResult = actualResult .DividedMoves .OrderBy(pair => pair.Key.ToString()) .Select(pair => $@" {pair.Key} -> {pair.Value}") .Join(Environment.NewLine); extraInfo = $@"{Environment.NewLine}Divide ({actualResult.DividedMoves.Count}):{Environment.NewLine}{ divideResult}"; } Console.WriteLine( @"[{0}] ({1}) {2} {{ {3} }} ({4}) : {5}{6}", MethodBase.GetCurrentMethod().GetQualifiedName(), ChessHelper.PlatformVersion, perftPosition.GetName(), fen, actualResult.Flags, actualResult, extraInfo); Console.WriteLine(); AssertPerftResult(actualResult, expectedResult); }
internal TestPerftCaseData( PerftPosition position, [NotNull] ExpectedPerftResult expectedResult, bool enableParallelism = true) : base(position, enableParallelism, expectedResult) { Assert.That(expectedResult, Is.Not.Null); Position = position; ExpectedResult = expectedResult; EnableParallelism = enableParallelism; }
private static void AssertPerftResult(PerftResult actualResult, ExpectedPerftResult expectedResult) { Assert.That(actualResult, Is.Not.Null); Assert.That(expectedResult, Is.Not.Null); Assert.That(actualResult.Depth, Is.EqualTo(expectedResult.Depth), "Depth mismatch."); Assert.That(actualResult.NodeCount, Is.EqualTo(expectedResult.NodeCount), "Node count mismatch."); if (expectedResult.CaptureCount.HasValue) { Assert.That( actualResult.CaptureCount, Is.EqualTo(expectedResult.CaptureCount), "Capture count mismatch."); } if (expectedResult.EnPassantCaptureCount.HasValue) { Assert.That( actualResult.EnPassantCaptureCount, Is.EqualTo(expectedResult.EnPassantCaptureCount), "En passant capture count mismatch."); } if (expectedResult.CheckCount.HasValue) { Assert.That( actualResult.CheckCount, Is.EqualTo(expectedResult.CheckCount.Value), "Check count mismatch."); } if (expectedResult.CheckmateCount.HasValue) { Assert.That( actualResult.CheckmateCount, Is.EqualTo(expectedResult.CheckmateCount.Value), "Checkmate count mismatch."); } }