Beispiel #1
0
        public void TestOppositeColor()
        {
            var b   = new Board();
            int pos = 4 * 8 + 4;

            b.State[pos] = Colors.Val(Piece.King, Color.White);

            b.State[pos + 7] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos + 8] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos + 9] = Colors.Val(Piece.Pawn, Color.Black);

            b.State[pos + 1] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 1] = Colors.Val(Piece.Pawn, Color.Black);

            b.State[pos - 7] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 8] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 9] = Colors.Val(Piece.Pawn, Color.Black);

            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(8, moves.Length);

            Assert.IsTrue(moves.Contains(pos + 7));
            Assert.IsTrue(moves.Contains(pos + 8));
            Assert.IsTrue(moves.Contains(pos + 9));

            Assert.IsTrue(moves.Contains(pos + 1));
            Assert.IsTrue(moves.Contains(pos - 1));

            Assert.IsTrue(moves.Contains(pos - 7));
            Assert.IsTrue(moves.Contains(pos - 8));
            Assert.IsTrue(moves.Contains(pos - 9));
        }
Beispiel #2
0
        public void TestFree()
        {
            // test free space
            var b   = new Board();
            int pos = 4 * 8 + 4;

            b.State[pos] = Colors.Val(Piece.Bishop, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(13, moves.Length);

            Assert.IsTrue(moves.Contains(pos + 9));
            Assert.IsTrue(moves.Contains(pos + 18));
            Assert.IsTrue(moves.Contains(pos + 27));
            Assert.IsTrue(moves.Contains(pos - 9));
            Assert.IsTrue(moves.Contains(pos - 18));
            Assert.IsTrue(moves.Contains(pos - 27));
            Assert.IsTrue(moves.Contains(pos - 36));

            Assert.IsTrue(moves.Contains(pos + 7));
            Assert.IsTrue(moves.Contains(pos + 14));
            Assert.IsTrue(moves.Contains(pos + 21));
            Assert.IsTrue(moves.Contains(pos - 7));
            Assert.IsTrue(moves.Contains(pos - 14));
            Assert.IsTrue(moves.Contains(pos - 21));
        }
Beispiel #3
0
        public void TestFree()
        {
            // test free space
            var b   = new Board();
            int pos = 4 * 8 + 4;

            b.State[pos] = Colors.Val(Piece.Rook, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(14, moves.Length);
            Assert.IsTrue(moves.Contains(pos + 1));
            Assert.IsTrue(moves.Contains(pos + 2));
            Assert.IsTrue(moves.Contains(pos + 3));
            Assert.IsTrue(moves.Contains(pos - 1));
            Assert.IsTrue(moves.Contains(pos - 2));
            Assert.IsTrue(moves.Contains(pos - 3));
            Assert.IsTrue(moves.Contains(pos - 4));

            Assert.IsTrue(moves.Contains(pos + 8));
            Assert.IsTrue(moves.Contains(pos + 16));
            Assert.IsTrue(moves.Contains(pos + 24));
            Assert.IsTrue(moves.Contains(pos - 8));
            Assert.IsTrue(moves.Contains(pos - 16));
            Assert.IsTrue(moves.Contains(pos - 24));
            Assert.IsTrue(moves.Contains(pos - 32));
        }
Beispiel #4
0
        public void TestCaptureSameColor()
        {
            var  b   = new Board();
            byte pos = 12;

            b.State[pos]     = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos + 7] = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos + 9] = Colors.Val(Piece.Pawn, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(2, moves.Length);
        }
Beispiel #5
0
        public void Test1()
        {
            // test free space
            var b = new Board();

            b.State[12] = Colors.Val(Piece.Pawn, Color.White);
            var moves = Attacks.GetAttacks(b, 12);

            Assert.AreEqual(2, moves.Length);
            Assert.IsTrue(moves.Contains(12 + 7));
            Assert.IsTrue(moves.Contains(12 + 9));
        }
Beispiel #6
0
        public void TestKnightCorner3()
        {
            // lower right
            var  b   = new Board();
            byte pos = 7;

            b.State[pos] = Colors.Val(Piece.Knight, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(2, moves.Length);
            Assert.IsTrue(moves.Contains((byte)(pos + 8 - 2)));
            Assert.IsTrue(moves.Contains((byte)(pos + 16 - 1)));
        }
Beispiel #7
0
        public void TestKnightCorner1()
        {
            // upper left
            var  b   = new Board();
            byte pos = 7 * 8;

            b.State[pos] = Colors.Val(Piece.Knight, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(2, moves.Length);
            Assert.IsTrue(moves.Contains((byte)(pos - 8 + 2)));
            Assert.IsTrue(moves.Contains((byte)(pos - 16 + 1)));
        }
Beispiel #8
0
        public void TestCaptureRight()
        {
            var  b   = new Board();
            byte pos = 12;

            b.State[pos]     = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos + 9] = Colors.Val(Piece.Pawn, Color.Black);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(2, moves.Length);
            Assert.IsTrue(moves.Contains(pos + 9));
            Assert.IsTrue(moves.Contains(pos + 7));
        }
Beispiel #9
0
        public void TestCaptureSameColor()
        {
            var b = new Board();

            b.PlayerTurn = Color.Black;
            int pos = 6 * 8 + 4;

            b.State[pos]     = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 7] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 9] = Colors.Val(Piece.Pawn, Color.Black);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(2, moves.Length);
        }
Beispiel #10
0
        public void TestCaptureRight()
        {
            var b = new Board();

            b.PlayerTurn = Color.Black;
            int pos = 6 * 8 + 4;

            b.State[pos]     = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 7] = Colors.Val(Piece.Pawn, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(2, moves.Length);
            Assert.IsTrue(moves.Contains(pos - 7));
            Assert.IsTrue(moves.Contains(pos - 9));
        }
Beispiel #11
0
        public void TestKnightCorner2()
        {
            // 7 + 1
            var  b   = new Board();
            byte pos = 6 * 8 + 1;

            b.State[pos] = Colors.Val(Piece.Knight, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(4, moves.Length);
            Assert.IsTrue(moves.Contains((byte)(pos - 8 + 2)));
            Assert.IsTrue(moves.Contains((byte)(pos - 16 + 1)));
            Assert.IsTrue(moves.Contains((byte)(pos + 10)));
            Assert.IsTrue(moves.Contains((byte)(pos - 17)));
        }
Beispiel #12
0
        public void TestKnightKillAll()
        {
            var  b   = new Board();
            byte pos = 4 * 8 + 4;

            b.State[pos]          = Colors.Val(Piece.Knight, Color.White);
            b.State[pos + 16 - 1] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos + 16 + 1] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos + 8 - 2]  = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos + 8 + 2]  = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 8 - 2]  = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 8 + 2]  = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 16 - 1] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[pos - 16 + 1] = Colors.Val(Piece.Pawn, Color.Black);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(8, moves.Length);
        }
Beispiel #13
0
        public void TestFree()
        {
            // test free space
            var b   = new Board();
            int pos = 4 * 8 + 4;

            b.State[pos] = Colors.Val(Piece.Queen, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(13 + 14, moves.Length);

            // bishop moves
            Assert.IsTrue(moves.Contains(pos + 9));
            Assert.IsTrue(moves.Contains(pos + 18));
            Assert.IsTrue(moves.Contains(pos + 27));
            Assert.IsTrue(moves.Contains(pos - 9));
            Assert.IsTrue(moves.Contains(pos - 18));
            Assert.IsTrue(moves.Contains(pos - 27));
            Assert.IsTrue(moves.Contains(pos - 36));

            Assert.IsTrue(moves.Contains(pos + 7));
            Assert.IsTrue(moves.Contains(pos + 14));
            Assert.IsTrue(moves.Contains(pos + 21));
            Assert.IsTrue(moves.Contains(pos - 7));
            Assert.IsTrue(moves.Contains(pos - 14));
            Assert.IsTrue(moves.Contains(pos - 21));

            // rook moves
            Assert.IsTrue(moves.Contains(pos + 1));
            Assert.IsTrue(moves.Contains(pos + 2));
            Assert.IsTrue(moves.Contains(pos + 3));
            Assert.IsTrue(moves.Contains(pos - 1));
            Assert.IsTrue(moves.Contains(pos - 2));
            Assert.IsTrue(moves.Contains(pos - 3));
            Assert.IsTrue(moves.Contains(pos - 4));

            Assert.IsTrue(moves.Contains(pos + 8));
            Assert.IsTrue(moves.Contains(pos + 16));
            Assert.IsTrue(moves.Contains(pos + 24));
            Assert.IsTrue(moves.Contains(pos - 8));
            Assert.IsTrue(moves.Contains(pos - 16));
            Assert.IsTrue(moves.Contains(pos - 24));
            Assert.IsTrue(moves.Contains(pos - 32));
        }
Beispiel #14
0
        public void TestEnPassantRight()
        {
            var b = new Board();

            b.PlayerTurn = Color.White;

            int posBlack = Notation.TextToTile("e4");
            int posWhite = Notation.TextToTile("f2");

            b.State[posBlack] = Colors.Val(Piece.Pawn, Color.Black);
            b.State[posWhite] = Colors.Val(Piece.Pawn, Color.White);

            b.Move(posWhite, posWhite + 16);

            var moves = Attacks.GetAttacks(b, posBlack);

            Assert.AreEqual(3, moves.Length);
            Assert.IsTrue(moves.Contains(Notation.TextToTile("f4")));
        }
Beispiel #15
0
        public void TestKnightCaptureSameColor()
        {
            var  b   = new Board();
            byte pos = 4 * 8 + 4;

            b.State[pos]          = Colors.Val(Piece.Knight, Color.White);
            b.State[pos - 16 + 1] = Colors.Val(Piece.Pawn, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(8, moves.Length);
            Assert.IsTrue(moves.Contains((byte)(pos + 16 - 1)));
            Assert.IsTrue(moves.Contains((byte)(pos + 16 + 1)));
            Assert.IsTrue(moves.Contains((byte)(pos + 8 - 2)));
            Assert.IsTrue(moves.Contains((byte)(pos + 8 + 2)));
            Assert.IsTrue(moves.Contains((byte)(pos - 8 - 2)));
            Assert.IsTrue(moves.Contains((byte)(pos - 8 + 2)));
            Assert.IsTrue(moves.Contains((byte)(pos - 16 - 1)));
            Assert.IsTrue(moves.Contains((byte)(pos - 16 + 1)));
        }
Beispiel #16
0
        public void Test2()
        {
            // Test left edge of board
            var  b   = new Board();
            byte pos = 3 * 8;

            b.State[pos] = Colors.Val(Piece.Pawn, Color.White);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(pos + 9));

            // Test right edge of board
            b            = new Board();
            pos          = 3 * 8 + 7;
            b.State[pos] = Colors.Val(Piece.Pawn, Color.White);
            moves        = Attacks.GetAttacks(b, pos);
            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(pos + 7));
        }
Beispiel #17
0
        public void TestSameColor()
        {
            var b   = new Board();
            int pos = 4 * 8 + 4;

            b.State[pos]      = Colors.Val(Piece.Queen, Color.White);
            b.State[pos + 14] = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos + 16] = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos + 18] = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos + 2]  = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos - 2]  = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos - 14] = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos - 16] = Colors.Val(Piece.Pawn, Color.White);
            b.State[pos - 18] = Colors.Val(Piece.Pawn, Color.White);

            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(16, moves.Length);

            Assert.IsTrue(moves.Contains(pos + 14));
            Assert.IsTrue(moves.Contains(pos + 16));
            Assert.IsTrue(moves.Contains(pos + 18));

            Assert.IsTrue(moves.Contains(pos + 7));
            Assert.IsTrue(moves.Contains(pos + 8));
            Assert.IsTrue(moves.Contains(pos + 9));

            Assert.IsTrue(moves.Contains(pos + 2));
            Assert.IsTrue(moves.Contains(pos - 2));

            Assert.IsTrue(moves.Contains(pos + 1));
            Assert.IsTrue(moves.Contains(pos - 1));

            Assert.IsTrue(moves.Contains(pos - 7));
            Assert.IsTrue(moves.Contains(pos - 8));
            Assert.IsTrue(moves.Contains(pos - 9));

            Assert.IsTrue(moves.Contains(pos - 14));
            Assert.IsTrue(moves.Contains(pos - 16));
            Assert.IsTrue(moves.Contains(pos - 18));
        }
Beispiel #18
0
        public void Test2()
        {
            // Test left edge of board
            var b = new Board();

            b.PlayerTurn = Color.Black;
            int pos = 24;

            b.State[pos] = Colors.Val(Piece.Pawn, Color.Black);
            var moves = Attacks.GetAttacks(b, pos);

            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(pos - 7));

            // test right edge of board
            b            = new Board();
            b.PlayerTurn = Color.Black;
            pos          = 24 + 7;
            b.State[pos] = Colors.Val(Piece.Pawn, Color.Black);
            moves        = Attacks.GetAttacks(b, pos);
            Assert.AreEqual(1, moves.Length);
            Assert.IsTrue(moves.Contains(pos - 9));
        }