Beispiel #1
0
        public void BlackBishopTest()
        {
            //a - arange
            var board = new Board();
            var bishop = new FigureBishop(Side.BLACK);
            var knight = new FigureKnight(Side.WHITE);
            var rook = new FigureRook(Side.WHITE);
            var queen = new FigureQueen(Side.WHITE);
            var pawn = new FigurePawn(Side.WHITE);
            board["e5"] = bishop;
            board["c3"] = knight;
            board["c7"] = rook;
            board["g3"] = pawn;
            board["g7"] = queen;

            //a - act
            var map = new AttackMap(new List<Move>(), board);

            //a - assert
            var validCells = new List<string>
            {
                "f6","g7",
                "d4","c3",
                "d6","c7",
                "f4","g3"
            };
            for (var j = 1; j <= Board.BoardSize; j++)
            {
                for (var i = 'a'; i <= 'h'; i++)
                {
                    var cell = i.ToString(CultureInfo.InvariantCulture) + j;
                    if (validCells.Contains(cell))
                    {
                        Assert.IsTrue(map[cell].Contains(bishop));
                    }
                    else
                    {
                        Assert.IsFalse(map[cell].Contains(bishop));
                    }

                }
            }
        }
Beispiel #2
0
        public void SimpleBishopTest()
        {
            //a - arange
            var board = new Board();
            var bishop = new FigureBishop(Side.WHITE);
            board["e4"] = bishop;

            //a - act
            var map = new AttackMap(new List<Move>(), board);

            //a - assert
            for (var j = 1; j <= Board.BoardSize; j++)
            {
                for (var i = 'a'; i <= 'h'; i++)
                {
                    if (Math.Abs('e' - i) == Math.Abs(4 - j) && j != 4)
                    {
                        Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(bishop));
                    }
                    else
                    {
                        Assert.IsFalse(map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(bishop));
                    }
                }
            }
        }
Beispiel #3
0
        public void IsMateBlackTest()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.BLACK);
            board["e8"] = king;
            board["g8"] = new FigureQueen(Side.WHITE);
            board["c8"] = new FigureRook(Side.WHITE);
            board["b7"] = new FigureRook(Side.WHITE);
            board["e7"] = new FigureBishop(Side.WHITE);

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map.IsMateBlack);
        }
Beispiel #4
0
        public void IsMateWhiteTest()
        {
            //a - arange
            var board = new Board();
            board["a1"] = new FigureKing(Side.WHITE);
            board["a2"] = new FigurePawn(Side.WHITE);
            board["b1"] = new FigureRook(Side.WHITE);
            board["b2"] = new FigureBishop(Side.WHITE);
            board["c2"] = new FigureKnight(Side.BLACK);

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map.IsMateWhite);
        }
Beispiel #5
0
        public void BlackRookVsBlackTest()
        {
            //a - arange
            var board = new Board();
            var rook = new FigureRook(Side.BLACK);
            var knight = new FigureKnight(Side.BLACK);
            var queen = new FigureQueen(Side.BLACK);
            var bishop = new FigureBishop(Side.BLACK);
            var rook2 = new FigureRook(Side.BLACK);
            board["e4"] = rook;
            board["e2"] = rook2;
            board["e6"] = knight;
            board["f4"] = queen;
            board["b4"] = bishop;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert

            for (var j = 1; j <= Board.BoardSize; j++)
            {
                if (j != 4 && j < 6 && j > 2)
                    Assert.IsTrue(map["e" + j].Contains(rook));
                if (j >= 6 && j < 2)
                    Assert.IsTrue(!map["e" + j].Contains(rook));
            }
            for (var i = 'a'; i <= 'h'; i++)
            {
                if (i != 'e' && i < 'f' && i > 'b')
                    Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + 4].Contains(rook));
            }
        }
Beispiel #6
0
        public void BlackRookTest()
        {
            //a - arange
            var board = new Board();
            var rook = new FigureRook(Side.BLACK);
            var knight = new FigureKnight(Side.WHITE);
            var bishop = new FigureBishop(Side.WHITE);
            var pawn = new FigurePawn(Side.WHITE);
            var queen = new FigureQueen(Side.WHITE);
            board["e4"] = rook;
            board["e3"] = knight;
            board["e5"] = bishop;
            board["d4"] = pawn;
            board["f4"] = queen;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            for (var i = 'a'; i <= 'h'; i++)
            {
                for (var j = 1; j <= Board.BoardSize; j++)
                {
                    if (j == 4)
                    {
                        if (i == 'f' || i == 'd')
                            Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook));
                        if (i == 'e')
                            Assert.IsTrue(!map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook));
                    }
                    else if (j == 3 || j == 5)
                    {
                        if (i == 'e')
                            Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook));
                    }
                    else
                        Assert.IsTrue(!map[i.ToString(CultureInfo.InvariantCulture) + j].Contains(rook));
                }
            }
        }
Beispiel #7
0
        public void WhiteKnightTest()
        {
            //a - arange
            var board = new Board();
            var knight = new FigureKnight(Side.WHITE);
            var rook = new FigureRook(Side.BLACK);
            var bishop = new FigureBishop(Side.BLACK);
            var queen = new FigureQueen(Side.BLACK);
            var queen1 = new FigureQueen(Side.WHITE);
            var bishop1 = new FigureBishop(Side.BLACK);
            board["e4"] = knight;
            board["f6"] = queen1;
            board["g5"] = bishop1;
            board["g3"] = bishop;
            board["f3"] = rook;
            board["d2"] = queen;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(!map["f6"].Contains(knight));
            Assert.IsTrue(map["g5"].Contains(knight));
            Assert.IsTrue(map["g3"].Contains(knight));
            Assert.IsTrue(map["f2"].Contains(knight));
            Assert.IsTrue(map["d2"].Contains(knight));
            Assert.IsTrue(map["c3"].Contains(knight));
            Assert.IsTrue(map["c5"].Contains(knight));
            Assert.IsTrue(map["d6"].Contains(knight));
            Assert.IsTrue(!map["h6"].Contains(knight));
        }
Beispiel #8
0
        public void WhiteKingTest()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.WHITE);
            var pawn = new FigurePawn(Side.WHITE);
            var rook = new FigureRook(Side.BLACK);
            var pawn1 = new FigurePawn(Side.BLACK);
            var bishop = new FigureBishop(Side.BLACK);
            var queen = new FigureQueen(Side.BLACK);
            board["e4"] = king;
            board["f5"] = pawn;
            board["f4"] = pawn1;
            board["f3"] = bishop;
            board["e3"] = rook;
            board["d3"] = queen;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsFalse(map["e5"].Contains(king));
            Assert.IsFalse(map["f5"].Contains(king));
            Assert.IsTrue(map["f4"].Contains(king));
            Assert.IsFalse(map["f3"].Contains(king));
            Assert.IsFalse(map["e3"].Contains(king));
            Assert.IsFalse(map["d3"].Contains(king));
            Assert.IsFalse(map["d4"].Contains(king));
            Assert.IsFalse(map["d5"].Contains(king));
            Assert.IsFalse(map["g4"].Contains(king));
        }
Beispiel #9
0
        public void InitialPosition()
        {
            Cells[0, 0] = new FigureRook(Side.WHITE);
            Cells[1, 0] = new FigureKnight(Side.WHITE);
            Cells[2, 0] = new FigureBishop(Side.WHITE);
            Cells[3, 0] = new FigureQueen(Side.WHITE);
            Cells[4, 0] = new FigureKing(Side.WHITE);
            Cells[5, 0] = new FigureBishop(Side.WHITE);
            Cells[6, 0] = new FigureKnight(Side.WHITE);
            Cells[7, 0] = new FigureRook(Side.WHITE);

            for (int i = 0; i < BoardSize; i++)
            {
                Cells[i, 1] = new FigurePawn(Side.WHITE);
            }

            //FillEmptyCells(0, BoardSize, 2, BoardSize - 2);

            for (int i = 0; i < BoardSize; i++)
            {
                Cells[i, 6] = new FigurePawn(Side.BLACK);
            }

            Cells[0, 7] = new FigureRook(Side.BLACK);
            Cells[1, 7] = new FigureKnight(Side.BLACK);
            Cells[2, 7] = new FigureBishop(Side.BLACK);
            Cells[3, 7] = new FigureQueen(Side.BLACK);
            Cells[4, 7] = new FigureKing(Side.BLACK);
            Cells[5, 7] = new FigureBishop(Side.BLACK);
            Cells[6, 7] = new FigureKnight(Side.BLACK);
            Cells[7, 7] = new FigureRook(Side.BLACK);
        }