Esempio n. 1
0
        public void TestFENEnPassantBlank()
        {
            var str = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq -";
            var b2  = Notation.ReadFEN(str);

            Assert.AreEqual(0, b2.EnPassantTile);
        }
Esempio n. 2
0
        public void TestZobristCastle()
        {
            var b   = Notation.ReadFEN("rnbqk2r/pppp1ppp/5n2/2b1p3/2B1P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 0 1");
            var zob = Zobrist.Calculate(b);

            b.Move(4, 6);
            var zob2 = Zobrist.Calculate(b);

            ulong expected = zob;

            expected = expected ^ Zobrist.Key.Piece(Color.White, Piece.King, 4);
            expected = expected ^ Zobrist.Key.Piece(Color.White, Piece.King, 6);
            expected = expected ^ Zobrist.Key.Piece(Color.White, Piece.Rook, 7);
            expected = expected ^ Zobrist.Key.Piece(Color.White, Piece.Rook, 5);

            expected = expected ^ Zobrist.Key.PlayerTurn(Color.White);
            expected = expected ^ Zobrist.Key.PlayerTurn(Color.Black);

            expected = expected ^ Zobrist.Key.Castling(new HashSet <Castling>()
            {
                Castling.KingsideWhite, Castling.QueensideWhite, Castling.KingsideBlack, Castling.QueensideBlack
            });
            expected = expected ^ Zobrist.Key.Castling(new HashSet <Castling>()
            {
                Castling.KingsideBlack, Castling.QueensideBlack
            });

            Assert.AreEqual(expected, zob2);
        }
Esempio n. 3
0
        public void TestFromToFEN()
        {
            var strings = new List <string>();

            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq");
            strings.Add("rnbqkbnr/pp1ppppp/8/2p1P3/8/8/PPPP1PPP/RNBQKBNR b KQkq");
            strings.Add("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq -");
            strings.Add("rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3");
            strings.Add("rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6");
            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq");
            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Kq");
            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w -");
            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w Kq");
            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b Kq");
            strings.Add("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b Kq - 12 18");

            foreach (var str in strings)
            {
                var b   = Notation.ReadFEN(str);
                var fen = Notation.BoardToFEN(b);

                // use StartsWith because the BoardToFEN may add extra default data
                Assert.IsTrue(fen.StartsWith(str));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Counts all moves from the given position to the required ply count, and returns the actual number of move paths found
        /// </summary>
        /// <param name="pos"></param>
        /// <returns></returns>
        public static PerftTestResult TestPosition(Position pos)
        {
            ulong expectedCount = pos.ExpectedCount;

            var x = Notation.ReadFEN(pos.FEN);
            var b = Helpers.ManagedBoardToNative(x);

            var start   = DateTime.Now;
            var results = Perft.Search(b, pos.Depth);
            var seconds = (DateTime.Now - start).TotalSeconds;

            Console.WriteLine("Perft(" + pos.Depth + "): " + (results->Total) + ", Time: " + String.Format("{0:0.000}", seconds));
            Console.WriteLine("NPS: " + String.Format("{0:0} kNodes/sec", (results->Total / seconds / 1000)));
            Console.WriteLine("");

            if (EnableDebugOutput)
            {
                for (int i = 0; i < results->EntryCount; i++)
                {
                    int   from  = results->Entries[i].From;
                    int   to    = results->Entries[i].To;
                    ulong count = results->Entries[i].Count;

                    string sfrom = Chess.Base.Notation.TileToText(from);
                    string sto   = Chess.Base.Notation.TileToText(to);
                    Console.WriteLine(sfrom + " " + sto + " : " + count);
                }
            }

            Board.Delete(b);
            return(new PerftTestResult {
                Count = results->Total, TimeMillis = seconds * 1000.0
            });
        }
Esempio n. 5
0
        public static void RunBasePerft()
        {
            Console.WriteLine("\n\n================= Chess.Base Perft Tests =================\n\n");

            var b       = Notation.ReadFEN("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
            var results = Chess.Base.Perft.RunPerft(b, 4);

            if (197281 != results.Total)
            {
                Console.WriteLine("Chess.Base Perft Test #1: UNEXPECTED RESULT");
            }
            else
            {
                Console.WriteLine("Chess.Base Perft Test #1 OK");
            }

            b       = Notation.ReadFEN("r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq -");
            results = Chess.Base.Perft.RunPerft(b, 3);
            if (97862 != results.Total)
            {
                Console.WriteLine("Chess.Base Perft Test #2: UNEXPECTED RESULT");
            }
            else
            {
                Console.WriteLine("Chess.Base Perft Test #2 OK");
            }

            b       = Notation.ReadFEN("8/2p5/3p4/KP5r/1R3p1k/8/4P1P1/8 w - -");
            results = Chess.Base.Perft.RunPerft(b, 5);
            if (674624 != results.Total)
            {
                Console.WriteLine("Chess.Base Perft Test #3: UNEXPECTED RESULT");
            }
            else
            {
                Console.WriteLine("Chess.Base Perft Test #3 OK");
            }

            b       = Notation.ReadFEN("r3k2r/Pppp1ppp/1b3nbN/nP6/BBP1P3/q4N2/Pp1P2PP/R2Q1RK1 w kq - 0 1");
            results = Chess.Base.Perft.RunPerft(b, 4);
            if (422333 != results.Total)
            {
                Console.WriteLine("Chess.Base Perft Test #4: UNEXPECTED RESULT");
            }
            else
            {
                Console.WriteLine("Chess.Base Perft Test #4 OK");
            }

            b       = Notation.ReadFEN("rnbqkb1r/pp1p1ppp/2p5/4P3/2B5/8/PPP1NnPP/RNBQK2R w KQkq - 0 6");
            results = Chess.Base.Perft.RunPerft(b, 3);
            if (53392 != results.Total)
            {
                Console.WriteLine("Chess.Base Perft Test #5: UNEXPECTED RESULT");
            }
            else
            {
                Console.WriteLine("Chess.Base Perft Test #5 OK");
            }
        }
Esempio n. 6
0
        public static unsafe ulong Calculate(string fenString)
        {
            var bx   = Notation.ReadFEN(fenString);
            var b    = Helpers.ManagedBoardToNative(bx);
            var hash = Calculate(b);

            return(hash);
        }
Esempio n. 7
0
        //[Test]
        public void TestSearch6()
        {
            var bx = Notation.ReadFEN("4k3/8/2r5/8/4N3/3P1Q2/7K/8 w - - 0 1");            //new Chess.Board(true);
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 8);
            var stats    = Search.GetSearchStats();
        }
Esempio n. 8
0
        public void TestFENTurnBlack()
        {
            var b1 = new Board(true);

            var str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b Kq";
            var b2  = Notation.ReadFEN(str);

            Assert.AreEqual(Color.Black, b2.PlayerTurn);
        }
Esempio n. 9
0
        public void TestFENHalfmovesAndRound()
        {
            var b1 = new Board(true);

            var str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b Kq - 12 18";
            var b2  = Notation.ReadFEN(str);

            Assert.AreEqual(12, b2.FiftyMoveRulePlies);
            Assert.AreEqual(18, b2.MoveCount);
        }
Esempio n. 10
0
        public void TestFEN1()
        {
            var b1 = new Board(true);

            var str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq";
            var b2  = Notation.ReadFEN(str);

            bool equal = b1.State.SequenceEqual(b2.State);

            Assert.IsTrue(equal);
        }
Esempio n. 11
0
        public void TestSearchDeeper()
        {
            var bx = Notation.ReadFEN("4k3/8/2r5/8/4N3/3P1Q2/7K/8 w - - 0 1");
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 4);

            Assert.AreEqual(28, bestMove.From);
            Assert.AreEqual(45, bestMove.To);

            var stats = Search.GetSearchStats();
        }
Esempio n. 12
0
        public void TestSearchCapture5()
        {
            var bx = Notation.ReadFEN("4k3/8/2r5/8/4N3/3P1Q2/7K/8 w - - 0 1");
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 4);             // should be the same result as TestSearchCapture4

            Assert.AreEqual(28, bestMove.From);
            Assert.AreEqual(45, bestMove.To);

            var stats = Search.GetSearchStats();
        }
Esempio n. 13
0
        public void TestSearchCapture3()
        {
            var bx = Notation.ReadFEN("4k3/8/2r2N2/8/8/3P1Q2/7K/8 b - - 0 1");
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 2);

            Assert.AreEqual(42, bestMove.From);
            Assert.AreEqual(45, bestMove.To);

            var stats = Search.GetSearchStats();
        }
Esempio n. 14
0
        public void TestPromotion()
        {
            var bx = Notation.ReadFEN("k7/pp5P/8/8/8/8/8/7K w - - 0 1");
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 1);

            Assert.AreEqual(55, bestMove.From);
            Assert.AreEqual(63, bestMove.To);
            Assert.AreEqual(6, bestMove.Promotion);
            var stats = Search.GetSearchStats();
        }
Esempio n. 15
0
        public void TestSearchSimple()
        {
            var bx = Notation.ReadFEN("3k4/8/8/8/2q5/3P4/7K/7Q w - - 0 1");
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 1);

            Assert.AreEqual(19, bestMove.From);
            Assert.AreEqual(26, bestMove.To);

            var stats = Search.GetSearchStats();
        }
Esempio n. 16
0
        public void TestFENCastleNone()
        {
            var b1 = new Board(true);

            var str = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w -";
            var b2  = Notation.ReadFEN(str);

            Assert.IsFalse(b2.CanCastleQWhite);
            Assert.IsFalse(b2.CanCastleKWhite);

            Assert.IsFalse(b2.CanCastleQBlack);
            Assert.IsFalse(b2.CanCastleKBlack);
        }
Esempio n. 17
0
        private void buttonLoadFEN_Click(object sender, EventArgs e)
        {
            try
            {
                var newBoard = Notation.ReadFEN(textBoxFEN.Text);
                boardControl1.State        = newBoard.State;
                checkBoxCastlingBK.Checked = newBoard.CanCastleKBlack;
                checkBoxCastlingBQ.Checked = newBoard.CanCastleQBlack;
                checkBoxCastlingWK.Checked = newBoard.CanCastleKWhite;
                checkBoxCastlingWQ.Checked = newBoard.CanCastleQBlack;

                RefreshBoard();
            }
            catch (Exception) { }
        }
Esempio n. 18
0
        public void TestFEN2()
        {
            var b1 = new Board(true);

            b1.Move(12, 12 + 16);
            b1.Move(50, 50 - 16);
            b1.Move(12 + 16, 12 + 16 + 8);

            var str = "rnbqkbnr/pp1ppppp/8/2p1P3/8/8/PPPP1PPP/RNBQKBNR b KQkq";
            var b2  = Notation.ReadFEN(str);

            bool equal = b1.State.SequenceEqual(b2.State);

            Assert.IsTrue(equal);
        }
Esempio n. 19
0
        public void TestFENEnPassantWhite()
        {
            var str = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3";
            var b2  = Notation.ReadFEN(str);

            Assert.AreEqual(Notation.TextToTile("e3"), b2.EnPassantTile);

            // compare state
            var b1 = new Board(true);

            b1.Move(Notation.TextToTile("e2"), Notation.TextToTile("e4"));
            bool equal = b1.State.SequenceEqual(b2.State);

            Assert.IsTrue(equal);
        }
Esempio n. 20
0
        public void TestABNFullgame1_1()
        {
            // test almost an entire game (excl. promotion)
            var    board = new Board(true);
            string data  = "1.e4 c5 2.Nf3 g6 3.c3 Bg7 4.d4 cxd4 5.cxd4 d5 6.exd5 Nf6 7.Bb5+ Nbd7 8.d6 exd6 9.Qe2+ Qe7 10.Bf4 Qxe2+ 11.Kxe2 d5 12.Rc1 O-O 13.Nbd2 a6 14.Bd3 Re8+ 15.Kf1 Nf8 16.Be5 Ne6 17.g3 Bd7 18.Nb3 Ne4 19.Bxg7 Kxg7 20.Nc5 N4xc5 21.dxc5 a5 22.Rc2 Rec8 23.Rac1 Rc7 24.Ne5 Be8 25.c6 b6 26.Nd7 Bxd7 27.cxd7 Rxd7 28.Bb5 Rd6 29.Rc8 Rxc8 30.Rxc8 Kf6 31.h4 h5 32.Ke1 Nc5 33.Ke2 Re6+ 34.Kf3 Ke5 35.Rc7 Rf6+ 36.Ke2 Ne4 37.f4+ Kd4 38.Kf3 Nd6 39.Bd7 Nc4 40.b3 Nd2+ 41.Ke2 Ne4 42.Kf3 Nc5 43.Be8 Kc3 44.Rxf7 Re6 45.Rf8 d4 46.f5 gxf5 47.Bxh5 Re3+ 48.Kg2 Re5 49.Bf3 d3 50.h5 Re6 51.Rxf5 d2 52.Rd5 Nd3 53.Bg4 Re4 54.h6 Rxg4";
            var    game  = new PGNParser().ParseGame(data);
            var    moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
            }

            var board2 = Notation.ReadFEN("8/8/1p5P/p2R4/6r1/1Pkn2P1/P2p2K1/8 w - - 0 55");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
        }
Esempio n. 21
0
        public void TestFENEnPassantMissingPieceBlack()
        {
            var str = "rnbqkbnr/pp1ppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6";

            bool ex = false;

            try
            {
                var b2 = Notation.ReadFEN(str);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.Contains("expected black pawn"));
                ex = true;
            }

            Assert.IsTrue(ex);
        }
Esempio n. 22
0
        public void TestABN4()
        {
            // Tests castling both kingside
            var    board = new Board(true);
            string data  = "1.e4 e5 2.Bd3 Bd6 3.Nf3 Nf6 4.O-O O-O ";
            var    game  = new PGNParser().ParseGame(data);
            var    moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
            }

            var board2 = Notation.ReadFEN("rnbq1rk1/pppp1ppp/3b1n2/4p3/4P3/3B1N2/PPPP1PPP/RNBQ1RK1 w -");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
            Assert.AreEqual(Color.White, board.PlayerTurn);
        }
Esempio n. 23
0
        public void TestABN2()
        {
            // Tests knights and bishops moving
            var    board = new Board(true);
            string data  = "1.e4 Nf6 2.Nc3 c6 3.Bc4 d5 ";
            var    game  = new PGNParser().ParseGame(data);
            var    moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
            }

            var board2 = Notation.ReadFEN("rnbqkb1r/pp2pppp/2p2n2/3p4/2B1P3/2N5/PPPP1PPP/R1BQK1NR w KQkq");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
            Assert.AreEqual(Color.White, board.PlayerTurn);
        }
Esempio n. 24
0
        public void TestFENEnPassantWrongTurnBlack()
        {
            var str = "rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR b KQkq c6";

            bool ex = false;

            try
            {
                var b2 = Notation.ReadFEN(str);
            }
            catch (Exception e)
            {
                Assert.IsTrue(e.Message.Contains("black moved last"));
                ex = true;
            }

            Assert.IsTrue(ex);
        }
Esempio n. 25
0
        public static void GenericSearchTest(string fen, int depth)
        {
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("Position: " + fen);
            Console.WriteLine("");

            var bx = Notation.ReadFEN(fen);
            var b  = Helpers.ManagedBoardToNative(bx);

            DateTime start    = DateTime.Now;
            var      bestMove = Search.SearchPos(b, depth);
            var      time     = (DateTime.Now - start).TotalSeconds;

            Console.WriteLine(String.Format("Time: {0:0.00} seconds", time));
            var stats = Search.GetSearchStats();

            var table     = TTable.GetTable();
            var tableSize = TTable.GetTableSize();
            int used      = 0;

            for (int i = 0; i < tableSize; i++)
            {
                if (table[i].Hash != 0)
                {
                    used++;
                }
            }

            var fill = used / (double)tableSize;

            double first  = stats->CutMoveIndex[0] / (double)stats->CutNodeCount * 100;
            double first3 = (stats->CutMoveIndex[0] + stats->CutMoveIndex[1] + stats->CutMoveIndex[2]) / (double)stats->CutNodeCount * 100;

            double qNodeCount = stats->QuiescentNodeCount / (double)stats->TotalNodeCount * 100;

            Console.WriteLine("1. Move Cuts: " + first);
            Console.WriteLine("3. Move Cuts: " + first3);
            Console.WriteLine("Quiesce nodes: " + stats->QuiescentNodeCount);
            Console.WriteLine("Quiesce Ratio: " + qNodeCount);
            Console.WriteLine("Total Eval: " + stats->EvalTotal);

            Board.Delete(b);
        }
Esempio n. 26
0
        public void TestABN5()
        {
            // Tests castling both queenside
            var    board = new Board(true);
            string data  = "1.e4 c5 2.Nf3 d6 3.d4 Nf6 4.dxc5 Qa5 5.c3 Qxc5 6.Bd3 g6 7.Be3 Qc7 8.Na3 Be6 9.Qd2 Nc6 10.O-O-O O-O-O ";
            var    game  = new PGNParser().ParseGame(data);
            var    moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
            }

            var board2 = Notation.ReadFEN("2kr1b1r/ppq1pp1p/2npbnp1/8/4P3/N1PBBN2/PP1Q1PPP/2KR3R w -");

            Assert.IsTrue(moves[6].Capture);
            Assert.IsTrue(moves[9].Capture);
            Assert.IsTrue(board2.State.SequenceEqual(board.State));
            Assert.AreEqual(Color.White, board.PlayerTurn);
        }
Esempio n. 27
0
        public void TestABNFullgame2()
        {
            // end results
            var    board = new Board(true);
            string data  = "1.e4 e5 2.Nf3 Nf6 3.Nxe5 d6 4.Nf3 Nxe4 5.d4 d5 6.Bd3 Nc6 7.O-O Be7 8.c4 Nb4 9.Be2 O-O 10.Nc3 Bf5 11.a3 Nxc3 12.bxc3 Nc6 13.Re1 Re8 14.Bf4 dxc4 15.Bxc4 Bd6 16.Rxe8+ Qxe8 17.Ng5 Bg6 18.Bxd6 cxd6 19.h4 Qe7 20.Qg4 h6 21.Nf3 Qe4 22.Qg3 Rd8 23.Re1 Qf5 24.Ba2 Qf6 25.Nh2 Qf5 26.Ng4 Kf8 27.Bb1 Qh5 28.Qf4 Bxb1 29.Rxb1 Rd7 30.Ne3 Ne7 31.g3 Nd5 32.Nxd5 Qxd5 33.Re1 Re7 34.Rxe7 Kxe7 35.Qe3+ Qe6 1/2";

            var game  = new PGNParser().ParseGame(data);
            var moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
                if (move.Promotion != 0)
                {
                    bool promoted = board.Promote(move.To, move.Promotion);
                    Assert.IsTrue(promoted);
                }
            }

            var board2 = Notation.ReadFEN("8/pp2kpp1/3pq2p/8/3P3P/P1P1Q1P1/5P2/6K1 w - - 0 36");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
        }
Esempio n. 28
0
        public void TestABNFullgame1_3()
        {
            // end results
            var    board = new Board(true);
            string data  = "1.e4 c5 2.Nf3 g6 3.c3 Bg7 4.d4 cxd4 5.cxd4 d5 6.exd5 Nf6 7.Bb5+ Nbd7 8.d6 exd6 9.Qe2+ Qe7 10.Bf4 Qxe2+ 11.Kxe2 d5 12.Rc1 O-O 13.Nbd2 a6 14.Bd3 Re8+ 15.Kf1 Nf8 16.Be5 Ne6 17.g3 Bd7 18.Nb3 Ne4 19.Bxg7 Kxg7 20.Nc5 N4xc5 21.dxc5 a5 22.Rc2 Rec8 23.Rac1 Rc7 24.Ne5 Be8 25.c6 b6 26.Nd7 Bxd7 27.cxd7 Rxd7 28.Bb5 Rd6 29.Rc8 Rxc8 30.Rxc8 Kf6 31.h4 h5 32.Ke1 Nc5 33.Ke2 Re6+ 34.Kf3 Ke5 35.Rc7 Rf6+ 36.Ke2 Ne4 37.f4+ Kd4 38.Kf3 Nd6 39.Bd7 Nc4 40.b3 Nd2+ 41.Ke2 Ne4 42.Kf3 Nc5 43.Be8 Kc3 44.Rxf7 Re6 45.Rf8 d4 46.f5 gxf5 47.Bxh5 Re3+ 48.Kg2 Re5 49.Bf3 d3 50.h5 Re6 51.Rxf5 d2 52.Rd5 Nd3 53.Bg4 Re4 54.h6 Rxg4";

            data += " 55.h7 d1Q 56.h8Q+ Kc2 57.Qc8+ Kd2 58.Qf8 Qe2+ 59.Kh3 Re4 60.Qf6 Qg4+ 0-1";
            var game  = new PGNParser().ParseGame(data);
            var moves = game.GetMainVariation();

            foreach (var move in moves)
            {
                board.Move(move.From, move.To, true);
                if (move.Promotion != 0)
                {
                    bool promoted = board.Promote(move.To, move.Promotion);
                    Assert.IsTrue(promoted);
                }
            }

            var board2 = Notation.ReadFEN("8/8/1p3Q2/p2R4/4r1q1/1P1n2PK/P2k4/8 w - - 0 61");

            Assert.IsTrue(board2.State.SequenceEqual(board.State));
        }
Esempio n. 29
0
        public void TestForStalemate()
        {
            // This position caused a stalemate as the engine did not choose the mate in one
            // instead it moved the king and blundered a win
            // Edit: It was actually a bug in the UCI interface. Still, a good test

            var bx = Notation.ReadFEN("7K/8/1k5b/6n1/6P1/8/p7/8 b - - 3 61 ");
            var b  = Helpers.ManagedBoardToNative(bx);

            var bestMove = Search.SearchPos(b, 8);

            Board.Make(b, bestMove.From, bestMove.To);
            Board.Promote(b, bestMove.To, Board.PIECE_QUEEN);
            Board.Make(b, 63, 62);

            bestMove = Search.SearchPos(b, 8);

            // assert that we move the queen, not the king!
            Assert.AreEqual(0, bestMove.From);

            Board.Make(b, bestMove.From, bestMove.To);
            // assert check
            Assert.AreEqual(1, Board.IsChecked(b, Board.COLOR_WHITE));
        }