Ejemplo n.º 1
0
    public void End(Type parent, string key)
    {
        if (!Log)
        {
            return;
        }
        if (!data.ContainsKey(parent) || !data[parent].Watches.ContainsKey(key))
        {
            CustomLogger.Instance.Error("Start should be called first");
            return;
        }
        DiagnosticsData diagnostics = data[parent];
        WatchContainer  container   = diagnostics.Watches[key];

        container.Watch.Stop();
        if (Verbose)
        {
            CustomLogger.Instance.Debug(string.Format("{0} -> {1} in {2}ms", parent.ToString(), container.Message, container.Watch.ElapsedMilliseconds));
        }

        if (!diagnostics.History.ContainsKey(key))
        {
            diagnostics.History.Add(key, new List <long>()
            {
                container.Watch.ElapsedMilliseconds
            });
        }
        else
        {
            diagnostics.History[key].Add(container.Watch.ElapsedMilliseconds);
            while (diagnostics.History.Count >= MAX_HISTORY)
            {
                diagnostics.History[key].RemoveAt(diagnostics.History.Count - 1);
            }
        }
        if (!diagnostics.Peak.ContainsKey(key))
        {
            diagnostics.Peak.Add(key, container.Watch.ElapsedMilliseconds);
        }
        else if (container.Watch.ElapsedMilliseconds > diagnostics.Peak[key])
        {
            diagnostics.Peak[key] = container.Watch.ElapsedMilliseconds;
        }
        if (!diagnostics.Total.ContainsKey(key))
        {
            diagnostics.Total.Add(key, container.Watch.ElapsedMilliseconds);
        }
        else
        {
            diagnostics.Total[key] += container.Watch.ElapsedMilliseconds;
        }

        diagnostics.Watches.Remove(key);
    }
Ejemplo n.º 2
0
        public void RuyLopez_SearchDepth5_Black()
        {
            // 8R BQ|KBNR
            // 7PPPP| PPP
            // 6  N |
            // 5 B  |P
            // 4    |P
            // 3    | N
            // 2PPPP| PPP
            // 1RNBQ|K  R
            //  ABCD EFGH


            var board = new Board();

            board.InitializeEmptyBoard();

            // 1.e4 e5 2.Nf3 Nc6 3.Bb5
            board.ExecuteMove(new SingleMove("e2", "e4"));
            board.ExecuteMove(new SingleMove("e7", "e5"));
            board.ExecuteMove(new SingleMove("g1", "f3"));
            board.ExecuteMove(new SingleMove("b8", "c6"));
            board.ExecuteMove(new SingleMove("f1", "b5"));

            var data = new DiagnosticsData()
            {
                OverrideSearchDepth = 5
            };

            var player = new Logic(false);

            player.PreviousData = data;

            //var previousMove = new Move()
            //{
            //    StartPosition = "f1",
            //    EndPosition = "b5"
            //};
            //player.LatestOpponentMove = previousMove;
            //player.GameHistory.Add(previousMove);
            player.Board = new Board(board);

            var playerMove  = player.CreateMove();
            var diagnostics = playerMove.Diagnostics;

            Logger.LogMessage($"Test: {nameof(RuyLopez_SearchDepth5_Black)}. Move: {playerMove.Move.StartPosition} to {playerMove.Move.EndPosition}. {diagnostics.ToString()}");

            // 24.10. depth 4
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to b8. Board evaluations: 2025886. Check evaluations: 1023. Time elapsed: 31392 ms. Available moves found: 31.

            // 24.10. depth 5
            // Test: RuyLopez_SearchDepth5_Black. Board evaluations: 19889371. Check evaluations: 1022. Time elapsed: 318569 ms. Available moves found: 31.

            // 24.10. depth 4. Strategy - class
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to b8. Board evaluations: 2025886. Check evaluations: 1023. Time elapsed: 28803,7124 ms. Available moves found: 31.


            // ------- Order prioritizing
            // 24.10. Depth 4 with order prioritize. Edit Board.Moves() - order capture to be first. Seems like really boosts with alpha-beta pruning
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to b8. Board evaluations: 305303. Check evaluations: 1023. Time elapsed: 5451 ms. Available moves found: 31.

            // 24.10. Depth 5 with order prioritize
            // Test: RuyLopez_SearchDepth5_Black. Move: f7 to f6. Board evaluations: 1532427. Check evaluations: 1022. Time elapsed: 26794 ms. Available moves found: 31.


            // ------- Main allMoves-loop parallelized
            // 25.10. Depth 4. All counter methods commented
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to b8. Board evaluations: 305303. Check evaluations: 1023. Time elapsed: 1387 ms. Available moves found: 31.

            // 25.10. Depth 5. All counter methods commented
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to d4. Board evaluations: 1532427. Check evaluations: 1030. Time elapsed: 7002 ms. Available moves found: 31.


            // -------
            // 29.10. depth 4
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to b8. Board evaluations: 191032982. Check evaluations: 1023. Time elapsed: 676506 ms. Available moves found: 31.

            // negate
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to a5. Board evaluations: 13251801. Check evaluations: 1024. Time elapsed: 54043 ms. Available moves found: 31.

            // Skip ordering in check checks
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to a5. Board evaluations: 13250777. Check evaluations: 1024. Time elapsed: 25777 ms. Available moves found: 31.

            // Only reorder moves by evaluation at start depth
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to a5. Board evaluations: 2025917. Check evaluations: 1024. Time elapsed: 10514 ms. Available moves found: 31.


            // Only reorder moves by evaluation at start depth. Otherwise prioritize by capture.
            // Depth 4
            // Test: RuyLopez_SearchDepth5_Black. Move: d8 to f6. Board evaluations: 305334. Check evaluations: 1033. Time elapsed: 1568 ms. Available moves found: 31.
            // Depth 5
            // Test: RuyLopez_SearchDepth5_Black. Move: c6 to d4. Board evaluations: 1532458. Check evaluations: 1030. Time elapsed: 7147 ms. Available moves found: 31.
            //
        }
Ejemplo n.º 3
0
        public void BishopEnding()
        {
            // https://en.wikipedia.org/wiki/Chess_endgame
            // Bishop and pawn endings
            //

            // The adjacent diagram, from Molnar–Nagy, Hungary 1966, illustrates the concepts of good bishop versus bad bishop,
            // opposition, zugzwang, and outside passed pawn.
            // White wins with 1. e6! (vacating e5 for his king)
            // 1... Bxe6 2. Bc2! (threatening Bxg6)
            // 2... Bf7 3. Be4! (threatening Bxc6)
            // 3... Be8 4. Ke5! (seizing the opposition [i.e. the kings are two orthogonal squares apart, with the other player on move]
            // and placing Black in zugzwang—he must either move his king, allowing White's king to penetrate, or his bishop, allowing a
            // decisive incursion by White's bishop)
            // 4... Bd7 5. Bxg6!

            var player   = new Logic(true);
            var opponent = new Logic(false);

            var data = new DiagnosticsData()
            {
                OverrideSearchDepth = 8,
                OverrideGamePhase   = GamePhase.EndGame
            };

            player.PreviousData   = data;
            opponent.PreviousData = data;

            var board  = new Board();
            var pieces = new List <PieceBase>
            {
                new Pawn(true, "b4"),
                new Pawn(true, "c5"),
                new Pawn(true, "e5"),
                new Pawn(true, "g5"),
                new Pawn(true, "h6"),
                new Pawn(false, "b5"),
                new Pawn(false, "c6"),
                new Pawn(false, "g6"),
                new Pawn(false, "h7"),

                new Bishop(true, "b3"),
                new Bishop(false, "f7")
            };

            board.AddNew(pieces);
            //
            var blackKing = new King(false, "e7");

            board.AddNew(blackKing);

            var whiteKing = new King(true, "f4");

            board.AddNew(whiteKing);

            board.Kings = (whiteKing, blackKing);

            player.Board   = new Board(board);
            opponent.Board = new Board(board);

            var playerMove = player.CreateMove();

            playerMove.Move.EndPosition.ShouldBe("e6");
        }