示例#1
0
        public void Test_Enpassant()
        {
            Board b = new Board(new string[]
            {
                "e2e4", // Advance
                "a7a6", // anything
                "e4e5", // Advance further
                "f7f5", // longjump
            }.Select(x => UCINotation.DeserializeMove(x)));

            Assert.IsTrue(b.PlayerOptions[b.CurrentPlayerId()].CheckEnpassantOnCol(5));

            var enpassantTakes = UCINotation.DeserializeMove("e5xf6");
            var moves          = b.GetLegalMoves();

            CollectionAssert.Contains(moves, enpassantTakes);

            // make another move and lose the option to enpassant
            b.Mutate(UCINotation.DeserializeMove("a2a3"));
            Assert.IsFalse(b.PlayerOptions[b.OtherPlayerId()].CheckEnpassantOnCol(5));

            // which cannot be made next move either
            b.Mutate(UCINotation.DeserializeMove("a5a4"));
            moves = b.GetLegalMoves();
            CollectionAssert.DoesNotContain(moves, enpassantTakes);
        }
示例#2
0
        public void TestValueSemantics()
        {
            Board original = new Board(Enumerable.Empty <Move>());
            Board copy     = original;

            Assert.AreSame(original, copy);

            // make a value copy
            copy = (Board)original.Clone();

            // make sure a copy was made
            Assert.AreNotSame(original, copy);
            Assert.AreNotSame(original.Fields[0], copy.Fields[0]);
            Assert.AreNotSame(original.PlayerOptions[0], copy.PlayerOptions[0]);

            // assert value semantics
            Assert.AreEqual(original, copy);
            Assert.AreEqual(original.Fields[0], copy.Fields[0]);
            Assert.AreEqual(original.PlayerOptions[0], copy.PlayerOptions[0]);

            // mutate the copy and check that nothing changed on the original
            var originalFieldBefore = original.Fields[UCINotation.UCIToIndex("a2")];

            copy.Mutate(new Move(UCINotation.UCIToIndex("a2"), UCINotation.UCIToIndex("a3"), TypeOfMove.Move));
            var originalFieldAfter = original.Fields[UCINotation.UCIToIndex("a2")];

            //Assert.AreSame(originalFieldBefore, originalFieldAfter);
            Assert.IsTrue(originalFieldBefore.GetType().IsValueType);
            Assert.AreEqual(originalFieldBefore, originalFieldAfter);
        }
示例#3
0
        public void TestBestMove2()
        {
            Engine eng = new Engine(isWhite: true);
            // most likely it's best to take!
            Move reaction = eng.ReactToMove(new string[] { "b1a3", "d7d5", "a1a2", "b7b5" }.Select(x => UCINotation.DeserializeMove(x)));

            Assert.AreEqual(reaction, UCINotation.DeserializeMove("a3xb5"));
        }
示例#4
0
        public void TestBestMove()
        {
            Engine eng = new Engine(isWhite: true);
            // most likely it's best to take!
            Move reaction = eng.ReactToMove(new string[] { "d2d4", "e7e5" }.Select(x => UCINotation.DeserializeMove(x)));

            Assert.AreEqual(reaction, UCINotation.DeserializeMove("d4xe5"));
        }
示例#5
0
        public void ToStringTest()
        {
            // GetUIC
            Assert.AreEqual(new UCINotation(new Move(0, 8, TypeOfMove.Move)).ToString(), "a1a2");
            Assert.AreEqual(new UCINotation(new Move(8 * 8 - 1, 7 * 8 - 1, TypeOfMove.Move)).ToString(), "h8h7");
            Assert.AreEqual(new UCINotation(new Move(0, 8, TypeOfMove.Take)).ToString(), "a1a2");
            Assert.AreEqual(new UCINotation(new Move(8 * 8 - 1, 7 * 8 - 1, TypeOfMove.Take)).ToString(), "h8h7");

            // GetIndex
            Assert.AreEqual(UCINotation.DeserializeMove("a1a2"), new Move(0, 8, TypeOfMove.Move));
            Assert.AreEqual(UCINotation.DeserializeMove("a1xb2"), new Move(0, 9, TypeOfMove.Take));
        }
示例#6
0
        public void Test_PinnedPawn()
        {
            Board b = new Board(new string[]
            {
                "e2e4", // Expand white king pawn
                "d7d5", // offer black queen pawn
                "d1e2", // queen oposite black king
                "e7e6", // expand king pawn
                "e4d5", // take queen pawn, pin black king pawn
            }.Select(x => UCINotation.DeserializeMove(x)));

            // the pawn on d6 cannot take
            Move illegalMove = UCINotation.DeserializeMove("e6xd5");

            CollectionAssert.Contains(b.GetMoves_IgnoreCheckRules().ToList(), illegalMove);
            CollectionAssert.DoesNotContain(b.GetLegalMoves(), illegalMove);
        }
示例#7
0
        public void Test_Castling()
        {
            Board b = new Board(new string[]
            {
                "e2e3", // open up bishop diagnal
                "a7a6", // anything
                "f1e2", // move bishop
                "a6a5", // anything
                "g1f3", // move knight
                "a5a4", // anything
            }.Select(x => UCINotation.DeserializeMove(x)));

            // castle kingside
            var castleKingside = UCINotation.DeserializeMove("e1g1");
            var moves          = b.GetLegalMoves();

            CollectionAssert.Contains(moves, castleKingside);
        }
示例#8
0
        public void Test_StartInCheck()
        {
            Board b = new Board(new string[]
            {
                "f2f4", // open up king diagnonal
                "e7e5", // open up queen diag
                "f4d5", // does not really matter
                "d8h4", // queen check white king
            }.Select(x => UCINotation.DeserializeMove(x)));

            // many king ignoring moves
            Assert.IsTrue(b.GetMoves_IgnoreCheckRules().Count() > 1);

            // Only legal move!
            var moves = b.GetLegalMoves();

            Assert.IsTrue(moves.Count == 1);
            Assert.AreEqual(moves.First(), UCINotation.DeserializeMove("g2g3"));
        }
示例#9
0
 /// <summary>
 /// Triggers the engine to consider
 /// You may call this function even if there are no new moves!
 /// </summary>
 /// <param name="moves">Moves space separated</param>
 public void OnNewMove(string moves)
 {
     if (IsWhite == GetWhiteToMove(moves))
     {
         IEnumerable <Move> movesParsed = moves.Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(x => UCINotation.DeserializeMove(x));
         Move bestMove = Engine.ReactToMove(movesParsed);
         ReportAction($"Depth={InterlockedEngineStats.Statistics.MaxDepth}, Nodes={InterlockedEngineStats.Statistics.NodesVisited}, Evaluation={InterlockedEngineStats.Statistics.Evaluation}");
         MoveAction(bestMove);
     }
 }
示例#10
0
 public void Move(string gameId, UCINotation move) => HttpPost($"https://lichess.org/api/bot/game/{gameId}/move/{move}");