Example #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="PerftResult"/> class.
        /// </summary>
        internal PerftResult(
            PerftFlags flags,
            int depth,
            TimeSpan elapsed,
            ulong nodeCount,
            ulong captureCount,
            ulong enPassantCaptureCount,
            IDictionary <GameMove, ulong> dividedMoves,
            ulong?checkCount,
            ulong?checkmateCount)
        {
            if (depth < 0)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(depth),
                          depth,
                          @"The value cannot be negative.");
            }

            if (elapsed < TimeSpan.Zero)
            {
                throw new ArgumentOutOfRangeException(
                          nameof(elapsed),
                          elapsed,
                          @"The value cannot be negative.");
            }

            if (dividedMoves is null)
            {
                throw new ArgumentNullException(nameof(dividedMoves));
            }

            Flags                 = flags;
            Depth                 = depth;
            Elapsed               = elapsed;
            NodeCount             = nodeCount;
            CaptureCount          = captureCount;
            EnPassantCaptureCount = enPassantCaptureCount;
            DividedMoves          = dividedMoves.AsReadOnly();
            CheckCount            = checkCount;
            CheckmateCount        = checkmateCount;

            var totalSeconds = elapsed.TotalSeconds;

            NodesPerSecond = checked ((ulong)(totalSeconds.IsZero() ? 0 : nodeCount / totalSeconds));
        }
        public void TestPerftSpecificCases(string fen, int startDepth, int endDepth)
        {
            for (var currentDepth = startDepth; currentDepth <= endDepth; currentDepth++)
            {
                var board = new GameBoard(fen, PerformInternalBoardValidation);
                const PerftFlags Flags = PerftFlags.EnableParallelism | PerftFlags.IncludeDivideMap;
                var perftResult        = board.Perft(currentDepth, Flags);

                string extraInfo = null;
                if (perftResult.Flags.HasFlag(PerftFlags.IncludeDivideMap))
                {
                    var divideResult = perftResult
                                       .DividedMoves
                                       .OrderBy(pair => pair.Key.ToString())
                                       .Select(pair => $@"  {pair.Key} -> {pair.Value}")
                                       .Join(Environment.NewLine);

                    extraInfo =
                        $@"{Environment.NewLine}Divide ({perftResult.DividedMoves.Count}):{Environment.NewLine}{
                            divideResult}";
                }

                Console.WriteLine(
                    $@"[{MethodBase.GetCurrentMethod().GetQualifiedName()}] ({ChessHelper.PlatformVersion
                        }) {{ {fen} }} ({perftResult.Flags}) : {perftResult}{extraInfo}");

                Console.WriteLine();
            }

            //// ReSharper disable CommentTypo

            /*
             *-------------------------------------------------------------*
             | Chess Platform UI for Desktop 0.1.0.312 (rev. ec3b5f331493) |
             *-------------------------------------------------------------*
             *
             * ------------------------------------------------------------------------------------------------------------------------
             * ChessPlatform.UI.Desktop.exe Information: 0 : [SmartEnoughPlayer.DoGetMove] Color: Black, max depth: 8 plies, max time: unlimited, multi CPU: True, FEN: "6rk/pp3p1p/3p2pb/3Pp3/2P3P1/1P1b1P2/P6P/R3R2K b - - 3 22".
             * ChessPlatform.UI.Desktop.exe Information: 0 : [SmartEnoughPlayer.DoGetMoveInternal] Number of available moves: 30.
             *
             * ChessPlatform.UI.Desktop.exe Information: 0 : [SmartEnoughPlayer.DoGetMoveInternal] Fixed depth: 8.
             * ChessPlatform.UI.Desktop.exe Warning: 0 : [SimpleTranspositionTable..ctor] The transposition table is DISABLED.
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #13/30] Bf5: -25, time: 0:00:24.5185544
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #01/30] Bxc4: -51, time: 0:00:55.8890279
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #21/30] Bf8: -49, time: 0:01:20.2642979
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #17/30] Rg7: 161, time: 0:01:22.6777899
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #02/30] Bf1: -134, time: 0:00:28.6191033
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #25/30] a5: 242, time: 0:01:33.8772758
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #14/30] e4: 107, time: 0:01:13.0023309
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #03/30] Be2: -141, time: 0:00:23.3566278
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #28/30] a6: 226, time: 0:01:56.0697976
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #09/30] g5: 193, time: 0:02:05.1629138
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #15/30] f5: 232, time: 0:00:35.4808219
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #05/30] Bd2: 154, time: 0:02:36.6748482
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #04/30] Bc1: -176, time: 0:00:55.4954289
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #10/30] Bb1: -137, time: 0:00:43.4778715
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #06/30] Be3: -404, time: 0:00:12.4505468
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #26/30] b6: 221, time: 0:01:48.0770289
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #18/30] Bg7: 25, time: 0:02:07.6889404
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #16/30] Kg7: 152, time: 0:01:31.2442893
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #22/30] Re8: 187, time: 0:02:26.9121297
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #29/30] Rb8: 182, time: 0:02:26.0801797
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #23/30] b5: 208, time: 0:00:47.184861
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #11/30] Bc2: 192, time: 0:01:49.5059476
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #12/30] Be4: -160, time: 0:00:18.8098226
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #19/30] f6: 221, time: 0:01:38.7527853
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #07/30] Bf4: 223, time: 0:02:26.0766087
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #30/30] Ra8: 175, time: 0:01:53.1468655
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #20/30] Rf8: 210, time: 0:01:22.7724898
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #27/30] Rc8: 194, time: 0:03:13.427106
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #24/30] Rd8: 201, time: 0:02:02.0335471
             * ChessPlatform.UI.Desktop.exe Information: 0 : [AnalyzeRootMoveInternal #08/30] Bg5: 223, time: 0:01:25.5120915
             * ChessPlatform.UI.Desktop.exe Information: 0 : [SmartEnoughPlayerMoveChooser.ComputeAlphaBetaRoot] Best move a5: 242.
             *
             * PVs ordered by score:
             * { 242 : a5, Rg1, Bf4, Rg2, e4, fxe4, Bxe4, Rg1 }
             * { 232 : f5, gxf5, gxf5, Rg1, Bg5, Rg2, Be3, Re1 }
             * { 226 : a6, Rad1, Bc2, Rc1, Bxc1, Rxc1, Bd3, h4 }
             * { 223 : Bf4, Rad1, Bc2, Rc1, Bd3, Rc3, Bd2, Rxd3 }
             * { 223 : Bg5, Rad1, Bc2, Rc1, Bd3, Rc3, Bd2, Rxd3 }
             * { 221 : b6, Rg1, Bf4, Rg2, e4, fxe4, Bxe4, Rg1 }
             * { 221 : f6, Rg1, Bf4, Rg2, e4, fxe4, Bxe4, Rg1 }
             * { 210 : Rf8, Rad1, Bc2, Rc1, Bd3, Rcd1, Bc2, b4 }
             * { 208 : b5, cxb5, Bxb5, Rad1, Bf4, Re4, f5, gxf5 }
             * { 201 : Rd8, Rad1, Bc2, Rc1, Bd3, Rcd1, Bc2, b4 }
             * { 194 : Rc8, Rad1, Bc2, Rc1, Bd3, Rc3, Bd2, Rxd3 }
             * { 193 : g5, Rad1, Bg6, c5, Bf8, Re3, Be7, Rg1 }
             * { 192 : Bc2, Rac1, Bxc1, Rxc1, Bd3, Rc3, e4, h4 }
             * { 187 : Re8, Rad1, Bc2, Rc1, Bxc1, Rxc1, Bd3, h4 }
             * { 182 : Rb8, Rad1, Bc2, Rc1, Bd3, Rcd1, Bc2, b4 }
             * { 175 : Ra8, Rad1, Bc2, Rc1, Bd3, Rcd1, Bc2, b4 }
             * { 161 : Rg7, c5, dxc5, Rxe5, Bf4, Re8+, Rg8, Rxg8+ }
             * { 154 : Bd2, Red1, Bc3, Rxd3, Bxa1, a4, f5, h4 }
             * { 152 : Kg7, c5, dxc5, Rxe5, Kh8, Re7, Bg7, Rg1 }
             * { 107 : e4, Rxe4, Bxe4, fxe4, Re8, Re1, f5, gxf5 }
             * { 25 : Bg7, Rad1, e4, fxe4, Bc2, Rd2, Bc3, Rxc2 }
             * { -25 : Bf5, gxf5, gxf5, Rg1, Bg5, Rg2, Rg6, Rag1 }
             * { -49 : Bf8, Rad1, Bc2, Rd2, Bf5, gxf5, Bh6, Rg2 }
             * { -51 : Bxc4, bxc4, Bd2, Re2, Bf4, Rb1, b6, Rg1 }
             * { -134 : Bf1, Rxf1, Bf4, Rf2, g5, Rg1, Rg6, Rg3 }
             * { -137 : Bb1, Raxb1, Bf4, Rb2, g5, Re4, Rg6, Rg2 }
             * { -141 : Be2, Rxe2, Bf4, Rg1, g5, Rg3, Bxg3, hxg3 }
             * { -160 : Be4, fxe4, Bf4, Rg1, g5, Rg2, Rg6, Rag1 }
             * { -176 : Bc1, Raxc1, f5, c5, fxg4, fxg4, dxc5, Rxe5 }
             * { -404 : Be3, Rxe3, Bc2, Rc1, Bf5, gxf5, gxf5, Rg1 }
             *
             * ChessPlatform.UI.Desktop.exe Information: 0 : [SmartEnoughPlayerMoveChooser.GetBestMove] Result: { 242 : a5, Rg1, Bf4, Rg2, e4, fxe4, Bxe4, Rg1 }, depth 8, time: 00:06:40.7191082, FEN "6rk/pp3p1p/3p2pb/3Pp3/2P3P1/1P1b1P2/P6P/R3R2K b - - 3 22".
             * ChessPlatform.UI.Desktop.exe Information: 0 : [SmartEnoughPlayer.DoGetMove] Result: { 242 : a5, Rg1, Bf4, Rg2, e4, fxe4, Bxe4, Rg1 }, depth 8, time: 0:06:40.7198951, 59101630 nodes (147489 NPS), FEN "6rk/pp3p1p/3p2pb/3Pp3/2P3P1/1P1b1P2/P6P/R3R2K b - - 3 22".
             * ------------------------------------------------------------------------------------------------------------------------
             *
             * Stockfish 6 64 POPCNT by Tord Romstad, Marco Costalba and Joona Kiiski
             *
             * position fen 6rk/pp3p1p/3p2pb/3Pp3/2P3P1/1P1b1P2/P6P/R3R2K b - - 3 22
             * go depth 8
             * info depth 1 seldepth 1 multipv 1 score cp 255 nodes 36 nps 7200 tbhits 0 time 5 pv h6d2
             * info depth 2 seldepth 2 multipv 1 score cp 336 nodes 77 nps 12833 tbhits 0 time 6 pv h6d2 a2a3 d2e1 a1e1
             * info depth 3 seldepth 3 multipv 1 score cp 336 nodes 121 nps 20166 tbhits 0 time 6 pv h6d2 a2a3 d2e1
             * info depth 4 seldepth 4 multipv 1 score cp 336 nodes 176 nps 25142 tbhits 0 time 7 pv h6d2 a2a3 d2e1 a1e1
             * info depth 5 seldepth 5 multipv 1 score cp 342 nodes 504 nps 63000 tbhits 0 time 8 pv h6d2 a1d1 d2e1 d1e1 f7f5
             * info depth 6 seldepth 7 multipv 1 score cp 208 nodes 3153 nps 286636 tbhits 0 time 11 pv h6f4 c4c5 d6c5 h1g2 f7f5 d5d6
             * info depth 7 seldepth 8 multipv 1 score cp 209 nodes 4542 nps 324428 tbhits 0 time 14 pv f7f5 h1g2 f5g4 f3g4 h6d2 e1d1 d3e4 g2h3
             * info depth 8 seldepth 12 multipv 1 score cp 262 nodes 8034 nps 446333 tbhits 0 time 18 pv h6d2 c4c5 d2e1 a1e1 d6c5 h1g2 f7f5 e1e5
             * bestmove h6d2 ponder c4c5
             *
             */

            //// ReSharper restore CommentTypo
        }