Exemple #1
0
        public void TestBishopAttack()
        {
            var board = new Board();

            board.AddPiece <Bishop>(SquareEFive, true);
            board.AddPiece <MockedPiece>(new Square(Files.g, Ranks.seven), false);

            var moves = board.Position[SquareEFive].AvailableMoves(board.Position);

            var toSquares = moves.Select(m => m.ToSquare).ToList();

            Assert.Equal(12, moves.Count);

            Assert.All(Enum.GetValues(typeof(Files)).Cast <int>()
                       .Where(i => i is not(int) Files.e&& i is not(int) Files.h)
                       .Select(i => new Square((Files)i, (Ranks)i)).ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(Enumerable.Range(-4, 8)
                       .Where(i => i != 0)
                       .Select(i => SquareEFive.Maneuver(Through.OppositeDiagonal, i))
                       .Where(s => s is not null)
                       .ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.Single(moves.Where(m => m.Type == MoveType.Capture).ToList());
            Assert.Equal(new Square(Files.g, Ranks.seven),
                         moves.Where(m => m.Type == MoveType.Capture).Select(m => m.ToSquare).ToList().First());

            Assert.All(moves, m => Assert.Equal(SquareEFive, m.FromSquare));
        }
Exemple #2
0
        public void TestBishopOnTheCenter()
        {
            var board = new Board();

            board.AddPiece <Bishop>(SquareEFive, true);

            var moves = board.Position[SquareEFive].AvailableMoves(board.Position);

            var toSquares = moves.Select(m => m.ToSquare).ToList();

            Assert.Equal(13, moves.Count);

            Assert.All(Enum.GetValues(typeof(Files)).Cast <int>()
                       .Where(i => i is not(int) Files.e)
                       .Select(i => new Square((Files)i, (Ranks)i)).ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(Enumerable.Range(-4, 8)
                       .Where(i => i != 0)
                       .Select(i => SquareEFive.Maneuver(Through.OppositeDiagonal, i))
                       .Where(s => s is not null)
                       .ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(moves, m => Assert.Equal(MoveType.Normal, m.Type));
            Assert.All(moves, m => Assert.Equal(SquareEFive, m.FromSquare));
        }
Exemple #3
0
        public void TestRoyaltyOnTheCenter()
        {
            var board = new Board();

            board.AddPiece <MockedRoyalPiece>(SquareEFive, true);

            var royal = (MockedRoyalPiece)board.Position[SquareEFive];

            var moves = royal.GetRoyalAttack(board.Position, 7);

            var toSquares = moves.Select(m => m.ToSquare).ToList();

            Assert.Equal(27, moves.Count);

            Assert.All(Enum.GetValues(typeof(Files)).Cast <Files>()
                       .Where(f => f is not Files.e)
                       .Select(f => new Square(f, Ranks.five)).ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(Enum.GetValues(typeof(Ranks)).Cast <Ranks>()
                       .Where(r => r is not Ranks.five)
                       .Select(r => new Square(Files.e, r)).ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(Enum.GetValues(typeof(Files)).Cast <int>()
                       .Where(i => i is not(int) Files.e)
                       .Select(i => new Square((Files)i, (Ranks)i)).ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(Enumerable.Range(-4, 8)
                       .Where(i => i != 0)
                       .Select(i => SquareEFive.Maneuver(Through.OppositeDiagonal, i))
                       .Where(s => s is not null)
                       .ToList(),
                       s => Assert.Contains(s, toSquares));

            Assert.All(moves, m => Assert.Equal(MoveType.Normal, m.Type));
            Assert.All(moves, m => Assert.Equal(SquareEFive, m.FromSquare));
        }