상속: Figure
예제 #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));
                    }

                }
            }
        }
예제 #2
0
        public void ShortCastlingWhiteTest2()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.WHITE);
            var rook = new FigureRook(Side.WHITE);
            var pawn = new FigurePawn(Side.WHITE);

            board["e1"] = king;
            board["h1"] = rook;
            board["f1"] = pawn;
            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsFalse(map["g1"].Contains(king));
        }
예제 #3
0
        public void ShortCastlingBlackTest()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.BLACK);
            var rook = new FigureRook(Side.BLACK);

            board["e8"] = king;
            board["h8"] = rook;
            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map["g8"].Contains(king));
        }
예제 #4
0
        public void LongCastlingWhiteTest()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.WHITE);
            var rook = new FigureRook(Side.WHITE);

            board["e1"] = king;
            board["a1"] = rook;
            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map["c1"].Contains(king));
        }
예제 #5
0
        public void LongCastlingBlackTest4()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.BLACK);
            var rook = new FigureRook(Side.BLACK);
            var knight = new FigureKnight(Side.WHITE);

            board["e8"] = king;
            board["a8"] = rook;
            board["d6"] = knight;
            //a - act
            var moves = new List<Move>{
                new Move { From = "c8", To = "d6" }};
            var map = new AttackMap(moves, board);

            //a - assert
            Assert.IsFalse(map["c8"].Contains(king));
        }
예제 #6
0
        public void LongCastlingBlackTest2()
        {
            //a - arange
            var board = new Board();
            var king = new FigureKing(Side.BLACK);
            var rook = new FigureRook(Side.BLACK);
            var pawn = new FigurePawn(Side.BLACK);

            board["e8"] = king;
            board["a8"] = rook;
            board["b8"] = pawn;
            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsFalse(map["c8"].Contains(king));
        }
예제 #7
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);
        }
예제 #8
0
        public void IsCheckTest()
        {
            //a - arange
            var board = new Board();
            var rook = new FigureRook(Side.BLACK);
            var king = new FigureKing(Side.WHITE);
            board["e3"] = king;
            board["h3"] = rook;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            Assert.IsTrue(map.IsCheck);
        }
예제 #9
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);
        }
예제 #10
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));
                }
            }
        }
예제 #11
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));
            }
        }
예제 #12
0
        public void BlackQueenVsWhiteTest()
        {
            //a - arange
            var board = new Board();
            var knight = new FigureKnight(Side.WHITE);
            var rook = new FigureRook(Side.WHITE);
            var queen2 = new FigureQueen(Side.WHITE);
            var pawn = new FigurePawn(Side.WHITE);
            var queen = new FigureQueen(Side.BLACK);
            board["d1"] = rook;
            board["d8"] = rook;
            board["h4"] = knight;
            board["a4"] = queen2;

            //Диагональ
            board["d4"] = queen;
            board["a1"] = knight;
            board["a7"] = rook;
            board["g1"] = pawn;
            board["h8"] = queen2;
            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert

            var validCells = new List<string>
            {
                "e3","f2",
                "g1","c5",
                "b6","a7",
                "c3","b2",
                "a1","e5",
                "f6","g7",
                "h8",
                "d3","d2","d1",
                "d5","d6","d7","d8",
                "e4","f4","g4","h4",
                "c4","b4","a4"
            };
            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(queen));
                    }
                    else
                    {
                        Assert.IsFalse(map[cell].Contains(queen));
                    }
                }
            }
        }
예제 #13
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));
        }
예제 #14
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));
        }
예제 #15
0
        public void SimpleRookTest()
        {
            //a - arange
            var board = new Board();
            var rook = new FigureRook(Side.WHITE);
            board["e4"] = rook;
            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            for (var j = 1; j <= Board.BoardSize; j++)
            {
                if (j != 4)
                    Assert.IsTrue(map["e" + j].Contains(rook));

            }
            for (var i = 'a'; i <= 'h'; i++)
            {
                if (i != 'e')
                    Assert.IsTrue(map[i.ToString(CultureInfo.InvariantCulture) + 4].Contains(rook));
            }
        }
예제 #16
0
파일: Board.cs 프로젝트: Beginner7/Command2
        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);
        }