Beispiel #1
0
        public void Whether_Bishop_CantMoveToIncorrectSquare_On_CanMoveTo()
        {
            var board = new Board();
            var bishop = new Bishop(new Square(4, 4), board, PieceColor.White);

            Assert.That(bishop.CanMoveTo(new Square(6, 5)), Is.False);
        }
Beispiel #2
0
        public void Whether_King_CantEscapeFromBishopOnTheSameDiagonal_OnCanMoveTo()
        {
            var board = new Board();
            var king = new King(new Square(4, 4), board, PieceColor.White);
            var bishop = new Bishop(new Square(5, 5), board, PieceColor.Black);

            Assert.That(king.CanMoveTo(new Square(3, 3)), Is.False);
        }
Beispiel #3
0
        public void Whether_Bishop_CantMoveToOccupiedSquare_On_CanMoveTo()
        {
            var board = new Board();
            var bishop = new Bishop(new Square(4, 4), board, PieceColor.White);
            var anotherKnight = new Knight(new Square(6, 6), board, PieceColor.White);

            Assert.That(bishop.CanMoveTo(new Square(6, 6)), Is.False);
        }
Beispiel #4
0
        public void Whether_Bishop_CantMoveOutsideTheBoard_On_CanMoveTo()
        {
            var board = new Board();
            var bishop = new Bishop(new Square(1, 1), board, PieceColor.White);

            Assert.That(bishop.PossibleMoves().Count() == 7);
            Assert.That(bishop.CanMoveTo(new Square(-1, -1)), Is.False);
        }
Beispiel #5
0
        public void Whether_Bishop_CantJumpOverAnotherPiece_On_CanMoveTo(PieceColor pieceColor)
        {
            var board = new Board();
            var bishop = new Bishop(new Square(4, 4), board, PieceColor.White);
            var knight = new Knight(new Square(5, 5), board, pieceColor);

            Assert.That(bishop.CanMoveTo(new Square(6, 6)), Is.False);
        }
Beispiel #6
0
        public void Whether_Bishop_CanMoveToPossibleSquare_On_CanMoveTo(int offsetX, int offsetY)
        {
            var board = new Board();
            var bishop = new Bishop(new Square(4, 4), board, PieceColor.White);

            Assert.That(bishop.CanMoveTo(
                new Square(bishop.Position.XPosition + offsetX,
                           bishop.Position.YPosition + offsetY)));
        }
Beispiel #7
0
        public void Whether_Bishop_ReturnsCorrectMoves_On_PossibleMoves()
        {
            var board = new Board();
            var bishop = new Bishop(new Square(4, 4), board, PieceColor.White);

            var possibleMoves = bishop.PossibleMoves();

            Assert.That(possibleMoves != null);
            Assert.That(possibleMoves.Count() == 13);
        }
Beispiel #8
0
        public void Whether_Board_AddsPieces_On_PutPiece()
        {
            var board = new Board();
            var originalPosition = new Square(5, 4);
            var newPosition = new Square(4, 3);

            var bishop = new Bishop(originalPosition, board, PieceColor.White);
            var knight = new Bishop(newPosition, board, PieceColor.Black);

            Assert.That(board.Pieces != null);
            Assert.That(board.Pieces.Count() == 2);
        }
Beispiel #9
0
        public void Whether_Board_InvokesOnPieceMoved_On_PieceMoveTo()
        {
            var board = new Board();
            var pieceMoved = false;
            board.PieceMoved += (b, m) => pieceMoved = true;
            var originalPosition = new Square(5, 4);
            var newPosition = new Square(4, 3);

            var bishop = new Bishop(originalPosition, board, PieceColor.White);
            bishop.MoveTo(newPosition);

            Assert.That(pieceMoved);
        }
Beispiel #10
0
        public void Whether_Board_InvokesPieceTaken_On_Caprute()
        {
            var board = new Board();
            var pieceTaken = false;
            var originalPosition = new Square(5, 4);
            var newPosition = new Square(4, 3);
            var bishop = new Bishop(originalPosition, board, PieceColor.White);
            var knight = new Bishop(newPosition, board, PieceColor.Black);
            knight.PieceTaken += (s) => pieceTaken = true;

            var possibleMoves = bishop.MoveTo(newPosition);

            Assert.That(board.Squares[originalPosition] == null);
            Assert.That(board.Squares[newPosition] == bishop);
            Assert.That(pieceTaken);
        }
Beispiel #11
0
        public void Whether_Board_DoesntInvokePieceMoved_On_MakeMove()
        {
            var board = new Board();
            var pieceMoved = false;
            board.PieceMoved += (b, m) => pieceMoved = true;
            var originalPosition = new Square(5, 4);
            var newPosition = new Square(4, 3);

            var bishop = new Bishop(originalPosition, board, PieceColor.White);
            board.MakeMove(new Move()
            {
                Color = PieceColor.White,
                OriginalSquare = originalPosition,
                TargetSquare = newPosition,
                Piece = bishop.Type
            });

            Assert.That(pieceMoved, Is.False);
        }
Beispiel #12
0
        public void Whether_King_CantMoveToBeatenSquare_On_CanMoveTo()
        {
            var board = new Board();
            var king = new King(new Square(4, 4), board, PieceColor.White);
            var bishop = new Bishop(new Square(4, 6), board, PieceColor.Black);

            Assert.That(king.CanMoveTo(new Square(5, 5)), Is.False);
        }
Beispiel #13
0
        public void Whether_Board_UpdatesPositionOnBoard_On_MoveTo()
        {
            var board = new Board();
            var originalPosition = new Square(5, 4);
            var newPosition = new Square(4, 3);
            var bishop = new Bishop(originalPosition, board, PieceColor.White);

            var possibleMoves = bishop.MoveTo(newPosition);

            Assert.That(board.Squares[originalPosition] == null);
            Assert.That(board.Squares[newPosition] == bishop);
        }