Beispiel #1
0
        public void SimpleIsPromotionWhiteTest()
        {
            //a - arange
            var board = new Board();
            board["d7"] = new FigurePawn(Side.WHITE);

            //a - act
            AttackMap map = new AttackMap(new List<Move>(), board);
            board.DoMove("d7", "d8", FigureQueen.SYMBOL.ToString(CultureInfo.InvariantCulture));

            //a - assert
            Assert.AreEqual(typeof(FigureQueen), board["d8"].GetType());
        }
Beispiel #2
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 #3
0
        public void AfterIsCheckTest()
        {
            //a - arange
            var board = new Board();
            var pawn = new FigurePawn(Side.WHITE);
            var king = new FigureKing(Side.WHITE);
            board["h3"] = king;
            board["g2"] = pawn;
            board["f3"] = new FigureQueen(Side.BLACK);

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map.IsCheck);
            Assert.IsTrue(map["f3"].Contains(pawn));
            Assert.IsTrue(map["g3"].Contains(pawn));
            Assert.IsFalse(map["g4"].Contains(pawn));
            Assert.IsFalse(map["g3"].Contains(king));
            Assert.IsFalse(map["g4"].Contains(king));
            Assert.IsTrue(map["h2"].Contains(king));
            Assert.IsTrue(map["h4"].Contains(king));
        }
Beispiel #4
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));
        }
Beispiel #5
0
        public void IsStalemateWhiteTest()
        {
            //a - arange
            var board = new Board();
            var pawn = new FigurePawn(Side.WHITE);
            var pawn2 = new FigurePawn(Side.BLACK);
            var king = new FigureKing(Side.WHITE);
            board["h8"] = king;
            board["f7"] = new FigureQueen(Side.BLACK);
            board["b4"] = pawn;
            board["b5"] = pawn2;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map.IsStalemateWhite);
        }
Beispiel #6
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 #7
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 #8
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));
                    }
                }
            }
        }
Beispiel #9
0
        public void BlackPawnSimpleTest()
        {
            //a - arange
            var board = new Board();
            var pawn = new FigurePawn(Side.BLACK);
            board["e7"] = pawn;

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

            //a - assert
            var validCells = new List<string>
            {
                "e6","e5"
            };
            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(pawn));
                    }
                    else
                    {
                        Assert.IsFalse(map[cell].Contains(pawn));
                    }

                }
            }
        }
Beispiel #10
0
        public void BlackPassedPawnTest2()
        {
            //a - arange
            var board = new Board();
            var pawnWhite = new FigurePawn(Side.WHITE);
            var pawnBlack = new FigurePawn(Side.BLACK);
            board["f5"] = pawnWhite;
            board["g5"] = pawnBlack;

            var moves = new List<Move>{
                new Move { From = "g7", To = "g6" },
                new Move { From = "g6", To = "g5" }};
            //a - act
            var map = new AttackMap(moves, board);
            //a - assert
            Assert.IsFalse(map["g6"].Contains(pawnWhite));
        }
Beispiel #11
0
        public void WhitePassedPawnTest2()
        {
            //a - arange
            var board = new Board();
            var pawnBlack = new FigurePawn(Side.BLACK);
            //board["c4"] = pawnWhite;
            //board["b4"] = pawnBlack;
            //board["d4"] = rookBlack;

            var moves = new List<Move>{
                new Move { From = "c2", To = "c4" },
                new Move { From = "f6", To = "d4" },
                new Move { From = "b5", To = "b4" }};
            //a - act
            var map = new AttackMap(moves, new Board());
            //a - assert
            Assert.IsTrue(!map["c3"].Contains(pawnBlack));
        }
Beispiel #12
0
        public void WhitePassedPawnTest()
        {
            //a - arange
            var board = new Board();
            var pawnWhite = new FigurePawn(Side.WHITE);
            var pawnBlack = new FigurePawn(Side.BLACK);
            board["c4"] = pawnWhite;
            board["b4"] = pawnBlack;

            var moves = new List<Move>{
                new Move { From = "c2", To = "c4" }};
            //a - act
            var map = new AttackMap(moves, board);
            //a - assert
            Assert.IsTrue(map["c3"].Contains(pawnBlack));
        }
Beispiel #13
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 #14
0
        public void WhitePassedPawnTest()
        {
            //a - arange
            var board = new Board();
            var pawnWhite = new FigurePawn(Side.WHITE);
            var pawnBlack = new FigurePawn(Side.BLACK);
            board["f5"] = pawnWhite;
            board["g5"] = pawnBlack;

            var moves = new List<Move>{
                new Move { From = "g7", To = "g5" }};
            //a - act
            var map = new AttackMap(moves, board);
            board.DoMove("f5", "g6");
            //a - assert
            //Assert.AreEqual(pawnWhite.GetType(), board["g6"].GetType());
            Assert.AreEqual(typeof(FigureNone), board["g5"].GetType());
        }
Beispiel #15
0
        public void OneWhitePawnTest()
        {
            //a - arange
            var board = new Board();
            var pawn = new FigurePawn(Side.WHITE);
            board["e2"] = pawn;

            //a - act
            var map = new AttackMap(new List<Move>(), board);
            //a - assert
            Assert.IsTrue(map["e3"].Contains(pawn));
            Assert.IsTrue(map["e4"].Contains(pawn));
        }
Beispiel #16
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));
        }
Beispiel #17
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);
        }