예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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)));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }