public void Bishop_CanMove_Diagonally()
        {
            var board  = new Board();
            var bishop = new Bishop(Player.White);

            board.AddPiece(Square.At(4, 4), bishop);

            var moves = bishop.GetAvailableMoves(board);

            var expectedMoves = new List <Square>();

            //Checking the backwards diagonal, i.e. 0,0 1,1, 2,2
            for (var i = 0; i < 8; i++)
            {
                expectedMoves.Add(Square.At(i, i));
            }

            //Checking the forwards diagonal i.e. 5,3 6,2 7,1
            for (var i = 1; i < 8; i++)
            {
                expectedMoves.Add(Square.At(i, 8 - i));
            }

            //Get rid of our starting location.
            expectedMoves.RemoveAll(s => s == Square.At(4, 4));

            moves.ShouldAllBeEquivalentTo(expectedMoves);
        }
Beispiel #2
0
        public void Bishop_CannnotPassThrough_FriendlyPieces()
        {
            var board = new Board();
            var bishop = new Bishop(Player.White);
            board.AddPiece(Square.At(4, 4), bishop);
            var friendlyPiece = new Pawn(Player.White);
            board.AddPiece(Square.At(6, 6), friendlyPiece);

            var moves = bishop.GetAvailableMoves(board);
            moves.Should().NotContain(Square.At(7, 7));
        }
Beispiel #3
0
        public void Bishop_CannnotPassThrough_OpposingPieces()
        {
            var board = new Board();
            var bishop = new Bishop(Player.White);
            board.AddPiece(Square.At(4, 4), bishop);
            var pieceToTake = new Pawn(Player.Black);
            board.AddPiece(Square.At(6, 6), pieceToTake);

            var moves = bishop.GetAvailableMoves(board);
            moves.Should().NotContain(Square.At(7, 7));
        }
Beispiel #4
0
        public void Bishop_AvailableMoves_For_4x5_AreCorrect()
        {
            List <FigurePosition> availableMovesFromPosition = new List <FigurePosition>
            {
                new FigurePosition(1, 2),
                new FigurePosition(2, 3),
                new FigurePosition(3, 4),
                new FigurePosition(3, 6),
                new FigurePosition(2, 7),
                new FigurePosition(1, 8),
                new FigurePosition(5, 4),
                new FigurePosition(6, 3),
                new FigurePosition(7, 2),
                new FigurePosition(8, 1),
                new FigurePosition(5, 6),
                new FigurePosition(6, 7),
                new FigurePosition(7, 8)
            };

            Bishop bishop = new Bishop(4, 5);

            Assert.That(availableMovesFromPosition, Is.EquivalentTo(bishop.GetAvailableMoves().ToList()));
        }