Пример #1
0
 public void _10_making_an_illegal_move_by_placing_the_white_pawn_on_X_equals_6_and_Y_eqauls_1_and_moving_to_X_equals_7_and_Y_eqauls_2_should_not_move_the_pawn()
 {
     _chessBoard.Add(_pawn, 6, 1);
     _pawn.Move(7, 2);
     Assert.That(_pawn.XCoordinate, Is.EqualTo(6));
     Assert.That(_pawn.YCoordinate, Is.EqualTo(1));
 }
Пример #2
0
 public void _31_black_pawn_capture_white_pawn()
 {
     _chessBoard.Add(_pawn, 3, 6);
     _chessBoard.Add(_opponent, 4, 1);
     Assert.That(_chessBoard.PiecesOnBoard(), Is.EqualTo(2));
     _pawn.Move(3, 5);
     _pawn.Move(3, 4);
     Assert.That(_pawn.XCoordinate, Is.EqualTo(3));
     Assert.That(_pawn.YCoordinate, Is.EqualTo(4));
     _opponent.Move(4, 3);
     Assert.That(_opponent.XCoordinate, Is.EqualTo(4));
     Assert.That(_opponent.YCoordinate, Is.EqualTo(3));
     ((Pawn)_pawn).Capture(4, 3);
     Assert.That(_pawn.XCoordinate, Is.EqualTo(4));
     Assert.That(_pawn.YCoordinate, Is.EqualTo(3));
     Assert.That(_chessBoard.PiecesOnBoard(), Is.EqualTo(1));
 }
Пример #3
0
        public void ChessPiece_Move_Sets_Y_Coordinate_For_Valid_Move()
        {
            IChessPiece piece = CreatePiece(PieceType.Pawn, PieceColor.Black);

            _chessBoard.Add(Arg.Any <IChessPiece>(),
                            Arg.Do <int>(x => piece.XCoordinate = x),
                            Arg.Do <int>(y => piece.YCoordinate = y),
                            piece.Color).Returns(true).AndDoes(x => piece.SetBoard(_chessBoard));
            _chessBoard.IsMoveValid(Arg.Any <Move>()).Returns(true);

            _chessBoard.Add(piece, 3, 6, piece.Color);
            piece.Move(MovementType.Move, 3, 4);
            Assert.That(piece.YCoordinate, Is.EqualTo(4));
        }
Пример #4
0
        public bool MoveAPiece(string startingPositionString, string finalPositionString)
        {
            if (!IsWithinBoundaries(startingPositionString) || !IsWithinBoundaries(finalPositionString))
            {
                return(false);
            }
            Position    finalPosition   = new Position(finalPositionString);
            IChessPiece chessPieceMoved = GetAPieceFromPosition(startingPositionString);
            bool        wasPieceMoved   = chessPieceMoved.Move(finalPosition.ColumnPosition, finalPosition.RowPosition, ChessPiecesOnBoard);

            if (wasPieceMoved)
            {
                ChessPiecesOnBoard.RemoveAll(cp => cp.Position.ColumnPosition == finalPosition.ColumnPosition &&
                                             cp.Position.RowPosition == finalPosition.RowPosition &&
                                             cp != chessPieceMoved);
                return(true);
            }
            return(false);
        }