Ejemplo n.º 1
0
 /// <summary>
 /// Rover constructor
 /// </summary>
 /// <param name="x">x co-ordinate</param>
 /// <param name="y">y co-ordinate</param>
 /// <param name="compassDirection">Can have one of these values 'N','S','W','E'. N -> North, S -> South, W -> West, E -> East</param>
 public RoverCuriosity(int x, int y, char compassDirection, Plateau plateau)
 {
     _x = x;
     _y = y;
     _compassDirection = Direction.CreateDirection(compassDirection);
     Plateau           = plateau;
 }
Ejemplo n.º 2
0
        public virtual List <Rover> ReadFile()
        {
            var rovers = new List <Rover>();

            string[] allText = fileSystem.File.ReadAllLines(@"C:\Temp\AmbushTest.txt");

            if (allText.Any())
            {
                var     plateauSize = GetPlateauSize(allText[0]);
                Plateau plateau     = new Plateau(plateauSize);

                for (int i = 1; i < allText.Length - 1; i += 2)
                {
                    string[] firstLine = allText[i].Split(' ');

                    Point roverPosition = new Point(Convert.ToDouble(firstLine[0]), Convert.ToDouble(firstLine[1]));

                    IDirection roverDirection = GetDirection(firstLine[2]);

                    List <ICommand> commands = GetCommands(allText[i + 1]);

                    rovers.Add(new Rover(roverPosition, roverDirection, plateau, commands));
                }
            }

            return(rovers);
        }
Ejemplo n.º 3
0
        public virtual void translate(Distance dist, IDirection dir)
        {
            double distMeters = dist.Meters;
            double dTheta = -DirectionMath.toRad(dir.bearing.Value);  // radians; theta is positive to left, bearing - positive to right

            this.translate(distMeters * Math.Cos(dTheta), distMeters * Math.Sin(dTheta));
        }
Ejemplo n.º 4
0
        public void OnFullHDAndSmaller_LeavesDefault_Correctly()
        {
            // Arrange
            this.underTest = Direction.Is.OnFullHDAndSmaller(DirectionOption.Column);

            // Act
            var underTestClass = underTest.Class;

            // Assert
            underTestClass.Should().NotBeNullOrWhiteSpace();

            underTestClass.Split(' ').Should()
            .HaveCount(5)
            .And
            .OnlyHaveUniqueItems()
            .And
            .HaveElementAt(0, "flex-column")
            .And
            .HaveElementAt(1, "flex-sm-column")
            .And
            .HaveElementAt(2, "flex-md-column")
            .And
            .HaveElementAt(3, "flex-lg-column")
            .And
            .HaveElementAt(4, "flex-xl-column");
        }
Ejemplo n.º 5
0
        public static List <Object> RoverMovement(string instruction)
        {
            List <Object> list      = new List <Object>();
            string        returning = "";

            char[] stepByStepInstruction = instruction.ToCharArray();
            foreach (char fetchOneByOne in stepByStepInstruction)
            {
                if (fetchOneByOne == 'L')
                {
                    currentFacingDirection = currentFacingDirection.TurnLeft();
                }
                else if (fetchOneByOne == 'R')
                {
                    currentFacingDirection = currentFacingDirection.TurnRight();
                }
                else
                {
                    coordinate = currentFacingDirection.MoveForward(coordinate, map);
                }
            }
            list.Add(coordinate.X);
            list.Add(coordinate.Y);
            list.Add(currentFacingDirection.CharacterTellerOfDirectionOfEachClass());
            //returning = returning + coordinate.X + " " + coordinate.Y + " " + currentFacingDirection;
            return(list);
        }
Ejemplo n.º 6
0
        public static int Mapping(this IFace view, IDirection direction)
        { 
            switch (view.Axis)
            {
                case Axis.Z:
                    
                    if (view.Orientation == Orientation.Back && direction.Alignment == Alignment.Rows)
                    {
                        return -1;
                    }

                    return +1;
                case Axis.X:

                    if (view.Orientation == Orientation.Front && direction.Alignment == Alignment.Rows && direction.Delta == Delta.Decrease)
                    {
                        return -1;
                    }
                    
                    if (view.Orientation == Orientation.Back && direction.Alignment == Alignment.Rows && direction.Delta == Delta.Increase)
                    {
                        return -1;
                    }

                    return +1;
                case Axis.Y:

                    return (view.Orientation == Orientation.Front ? +1 : -1) * (direction.Alignment == Alignment.Rows ? +1 : -1) * direction.Delta.Quantity();
                default:
                    throw new ArgumentException();
            }
        }
Ejemplo n.º 7
0
        public virtual void translate(Distance dist, IDirection dir)
        {
            double distMeters = dist.Meters;
            double dTheta     = -DirectionMath.toRad(dir.bearing.Value); // radians; theta is positive to left, bearing - positive to right

            this.translate(distMeters * Math.Cos(dTheta), distMeters * Math.Sin(dTheta));
        }
Ejemplo n.º 8
0
 public Rover(Point _position, IDirection _direction, Plateau _plateau, List <ICommand> _commands)
 {
     Position   = _position;
     Direction  = _direction;
     MarsPlateu = _plateau;
     Commands   = _commands;
 }
Ejemplo n.º 9
0
 public Axis2DConfiguration(IDirection horizontal, IDirection vertical)
 {
     Left  = new TwoWayDirectionWrapper(horizontal, true);
     Right = new TwoWayDirectionWrapper(horizontal, false);
     Up    = new TwoWayDirectionWrapper(vertical, true);
     Down  = new TwoWayDirectionWrapper(vertical, false);
 }
Ejemplo n.º 10
0
        public static IDirection CreateDirection(char _direction)
        {
            IDirection roverDirection = null;

            switch (_direction)
            {
            case 'N':
                roverDirection = new NorthDirection();
                break;

            case 'W':
                roverDirection = new WestDirection();
                break;

            case 'S':
                roverDirection = new SouthDirection();
                break;

            case 'E':
                roverDirection = new EastDirection();
                break;

            default: break;
            }

            return(roverDirection);
        }
Ejemplo n.º 11
0
        public int GetPart2ManhattanDistance()
        {
            var shipCoordinates = new Point(0, 0);
            var waypoint        = new Point(10, 1);

            foreach (IInstruction instruction in Instructions)
            {
                if (instruction is IDirection)
                {
                    IDirection direction        = instruction as IDirection;
                    Point      waypointMovement = direction.Execute();

                    waypoint.X += waypointMovement.X;
                    waypoint.Y += waypointMovement.Y;
                }

                if (instruction is IMovement)
                {
                    IMovement movement     = instruction as IMovement;
                    Point     shipMovement = movement.Part2Execute(waypoint);

                    shipCoordinates.X += shipMovement.X;
                    shipCoordinates.Y += shipMovement.Y;
                }

                if (instruction is IRotation)
                {
                    IRotation rotation = instruction as IRotation;
                    waypoint = rotation.Part2Execute(waypoint);
                }
            }

            return(Math.Abs(shipCoordinates.X) + Math.Abs(shipCoordinates.Y));
        }
Ejemplo n.º 12
0
 public Direction directionToWp(IGeoPosition myPos, IDirection myDir)
 {
     return(new Direction()
     {
         heading = myDir.heading, bearing = myPos.bearingTo(this.geoPosition)
     });
 }
Ejemplo n.º 13
0
        public int GetPart1ManhattanDistance()
        {
            var shipCoordinates  = new Point(0, 0);
            var currentDirection = ShipDirection.Direction.East;

            foreach (IInstruction instruction in Instructions)
            {
                if (instruction is IDirection)
                {
                    IDirection direction     = instruction as IDirection;
                    Point      newCoordinate = direction.Execute();
                    shipCoordinates.X += newCoordinate.X;
                    shipCoordinates.Y += newCoordinate.Y;
                }

                if (instruction is IMovement)
                {
                    IMovement movement      = instruction as IMovement;
                    Point     newCoordinate = movement.Part1Execute(currentDirection);
                    shipCoordinates.X += newCoordinate.X;
                    shipCoordinates.Y += newCoordinate.Y;
                }

                if (instruction is IRotation)
                {
                    IRotation rotation = instruction as IRotation;
                    currentDirection = rotation.Part1Execute(currentDirection);
                }
            }

            return(Math.Abs(shipCoordinates.X) + Math.Abs(shipCoordinates.Y));
        }
Ejemplo n.º 14
0
    /// <summary>
    /// Awake
    /// </summary>
    private void Awake()
    {
        if (this.direction != null)
        {
            return;
        }

        this.anchorVecInt.x = (int)this.anchor % 3; //012,012,012
        this.anchorVecInt.y = (int)this.anchor / 3; //000,111,222
        this.anchorVec.x    = this.anchorVecInt.x * 0.5f;
        this.anchorVec.y    = (2 - this.anchorVecInt.y) * 0.5f;

        if (this.isVertical)
        {
            this.direction          = new VerticalDirection();
            this.layoutGroupType    = typeof(HorizontalLayoutGroup);
            this.alignmentDirection = -1;
            this.pivotValue         = this.anchorVec.y;
        }
        else
        {
            this.direction          = new HorizontalDirection();
            this.layoutGroupType    = typeof(VerticalLayoutGroup);
            this.alignmentDirection = 1;
            this.pivotValue         = this.anchorVec.x;
        }
    }
Ejemplo n.º 15
0
        private bool TryReverseDirection(IDirection direction, IUnit player, IMazeNodeData nodeData, IMazeViewData mazeView)
        {
            IDirection reverseDirection = player.CurrentMovementDirection.ReverseDirection;
            ILocation  futureLocation   = player.CurrentLocation.GetCopy().Add(mazeView.MovementCube[reverseDirection.Value]);

            return(Validator.IsFutureLocationValid(player.CurrentLocation, futureLocation, nodeData));
        }
Ejemplo n.º 16
0
        private void AssignNewDirection(IDirection direction, IUnit player, IMazeViewData mazeView)
        {
            player.CurrentMovementDirection = direction;
            ILocation futureLocation = player.CurrentLocation.GetCopy().Add(mazeView.MovementCube[direction.Value]);

            player.AssignLocation(futureLocation);
        }
Ejemplo n.º 17
0
        public static int[,] CreateMatrix(int rows, int columns, IDirection direction)
        {
            if (direction == null)
            {
                throw new ArgumentNullException("Direction cannot be null!");
            }

            if (rows < 0 || columns < 0)
            {
                throw new ArgumentOutOfRangeException("Size values cannot be negative!");
            }

            int[,] matrix = new int[rows, columns];

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    matrix[i, j] = 0;
                }
            }

            matrix = FillMatrix(matrix, direction);
            return(matrix);
        }
Ejemplo n.º 18
0
        // works only for small distances, within miles. For rare cases when we have both heading and bearing, but want to move in the "heading" direction.
        public void translateToDirection(IDirection dir, IDistance by)
        {
            double range = by.Meters;
            double angle = (double)dir.heading; // degrees

            m_X += toDegreesX(range * Math.Sin(angle * Math.PI / 180.0d));
            m_Y += toDegreesY(range * Math.Cos(angle * Math.PI / 180.0d));
        }
Ejemplo n.º 19
0
        public Rover(IDirection direction, Coordinate coordinate, Terrain terrain)
        {
            ValidateRoverInitialization(direction, coordinate, terrain);

            Direction = direction;
            _coordinate = coordinate;
            _terrain = terrain;
        }
Ejemplo n.º 20
0
        public string GetOutput(Cordinate <T> cordinate, IDirection <T, U> direction)
        {
            string name          = direction.GetType().Name;
            int    index         = name.IndexOf('`');
            var    directionName = index == -1 ? name : name.Substring(0, index);

            return($"{cordinate.X},{cordinate.Y},{directionName.ToUpper()}");
        }
Ejemplo n.º 21
0
 protected override void SetUp()
 {
     _direction = Substitute.For <Direction>();
     _plateau   = Substitute.For <Plateau>();
     _location  = new Location(_plateau);
     _rover     = new Rover(_location, _direction);
     base.SetUp();
 }
Ejemplo n.º 22
0
        public ICmdResult TurnLeft()
        {
            var cmdResult = Mef.Instance.GetCmdResult();

            direction = direction.TurnLeft();

            return(cmdResult);
        }
Ejemplo n.º 23
0
 public OfferController(IOffer iOffer, ITypeOfOffer iTypeOfOffer, IProblem iProblem, IStatus iStatus, IDirection iDirection, IAspNetUser users)
 {
     db            = iOffer;
     _iTypeOfOffer = iTypeOfOffer;
     _iProblem     = iProblem;
     _iStatus      = iStatus;
     _iDirection   = iDirection;
     _users        = users;
 }
Ejemplo n.º 24
0
 public Lane(string name, Direction direction, int inFlow, int outFlow, int initialTraffic)
 {
     _direction      = direction;
     _laneName       = name;
     _inFlow         = inFlow;
     _outFlow        = outFlow;
     _initialTraffic = initialTraffic;
     _sim            = new Simulator(_initialTraffic, _inFlow, _outFlow);
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Roate right by 90 degree
        /// </summary>
        public IDirection RotateRight()
        {
            // cycle through direction name array
            _direction = _direction.Rotate(1);

            // update destination
            _destination = new Coordinate(_position.X + _direction.X, _position.Y + _direction.Y);

            return(_direction);
        }
Ejemplo n.º 26
0
 public Axis2DConfiguration(IDirection left,
                            IDirection right,
                            IDirection up,
                            IDirection down)
 {
     Left  = left;
     Right = right;
     Up    = up;
     Down  = down;
 }
Ejemplo n.º 27
0
        /// <summary>
        /// This gives posible movements of horse.
        ///Horse can move across the board only in 2.5 steps (2 vertical steps and 1 horizontal step)
        /// </summary>
        /// <param name="initialPosition"></param>
        /// <returns></returns>
        public override List <Position> GetPossiblePositions(IDirection direction)
        {
            var possibleOutcomes    = new List <Position>();
            var horizontalMovements = GetHorizontalTwoAndHalfMovements(direction);
            var verticalMovements   = GetVerticalTwoAndHalfMovements(direction);

            possibleOutcomes.AddRange(horizontalMovements);
            possibleOutcomes.AddRange(verticalMovements);
            return(possibleOutcomes);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Bishop can move across the board only diagonally
        /// </summary>
        /// <param name="initialPosition"></param>
        /// <returns></returns>
        public override List <Position> GetPossiblePositions(IDirection direction)
        {
            var possibleOutcomes = new List <Position>();

            possibleOutcomes.AddRange(direction.GetNorthEastPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            possibleOutcomes.AddRange(direction.GetNorthWestPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            possibleOutcomes.AddRange(direction.GetSouthEastPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            possibleOutcomes.AddRange(direction.GetSouthWestPositions(CurrentPosition, Constants.ChessBoardUpperLimit));
            return(possibleOutcomes);
        }
Ejemplo n.º 29
0
        public static IEnumerable <T> GetAllDirections <T>(this IDirection <T> self)
        {
            yield return(self.Left);

            yield return(self.Top);

            yield return(self.Right);

            yield return(self.Bottom);
        }
Ejemplo n.º 30
0
        public Rover(IGrid grid, IGridCell origin, IDirection direction)
        {
            _cell      = origin;
            _direction = direction;
            _grid      = grid;

            _turn.Add('L', _direction.Left);
            _turn.Add('R', _direction.Right);
            _move.Add('F', Forward);
            _move.Add('B', Backward);
        }
Ejemplo n.º 31
0
		protected virtual void Awake()
		{
			_direction = GetComponent<IDirection>();
			if (_direction == null)
			{
				Debug.Log("Not find " + typeof(IDirection) + " component. Disable.");
				enabled = false;
			}

			_timeLastShoot = -ShotDelay;
		}
Ejemplo n.º 32
0
 public Rover(string name, IInputService inputService, IOutputService outputService, IDirection direction)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException("Set Rover name!");
     }
     Name = name;
     this.inputService  = inputService ?? throw new ArgumentNullException();
     this.outputService = outputService ?? throw new ArgumentNullException();
     this.direction     = direction;
 }
Ejemplo n.º 33
0
 public IEnumerable<ISquare> GetCellsByDirection(ISquare square, IDirection direction, int distance)
 {
     ISquare newSquare = AddDirection(square, direction);
     int n = 0;
     while (IsLegal(newSquare) && (n < distance || distance == 0))
     {
         yield return newSquare;
         newSquare = AddDirection(newSquare, direction);
         n++;
     }
 }
        public void Given_SouthDirection_When_TurnRight_Then_DirectionShouldBeWest()
        {
            // Arrange
            SouthDirection southDirection = new SouthDirection();

            // Act
            IDirection newDirection = southDirection.TurnRight();

            // Assert
            newDirection.Should().BeOfType <WestDirection>();
        }
Ejemplo n.º 35
0
        private void ValidateRoverInitialization(IDirection direction, Coordinate coordinate, Terrain terrain)
        {
            if (direction == null)
            {
                throw new RoverNullDirectionException(Messages.RoverArgumentNullExceptionMessage);
            }

            if (terrain == null)
            {
                throw new RoverNullTerrainException(Messages.RoverNullTerrainExceptionMessage);
            }

            if (coordinate.X < terrain.LowerBoundary.X || coordinate.Y < terrain.LowerBoundary.Y)
            {
                throw new RoverInvalidPositionException(Messages.RoverNegativePositionExceptionMessage);
            }
        }
Ejemplo n.º 36
0
 public Direction directionToWp(IGeoPosition myPos, IDirection myDir) { return new Direction() { heading = myDir.heading, bearing = myPos.bearingTo(this.geoPosition) }; }
Ejemplo n.º 37
0
 public void TurnRight()
 {
     _direction = _direction.TurnRight();
 }
Ejemplo n.º 38
0
 public void TurnLeft()
 {
     _direction = _direction.TurnLeft();
 }
Ejemplo n.º 39
0
 public Rover(IPlanetSurface planetSurface)
 {
     _planetSurface = planetSurface;
     _direction = new North(_planetSurface);
 }
Ejemplo n.º 40
0
        // works only for small distances, within miles. For general case - when bearing is missing, or when we need to move towards bearing.
        public void translate(IDirection dir, IDistance by)
		{
            double range = by.Meters;
            double angle = (double)dir.heading; // degrees

            if (dir.bearing.HasValue)
            {
                // if both heading and bearing are supplied, then heading represents robot direction, and bearing - absolute direction to the object.
                // we are interested in translating in the "bearing" direction in this case, it is done to the objects relative to the robot.
                angle = (double)dir.bearing;
            }

            m_X += toDegreesX(new Distance(range * Math.Sin(angle * Math.PI / 180.0d)));
            m_Y += toDegreesY(new Distance(range * Math.Cos(angle * Math.PI / 180.0d)));
		}
Ejemplo n.º 41
0
        // works only for small distances, within miles. For rare cases when we have both heading and bearing, but want to move in the "heading" direction.
        public void translateToDirection(IDirection dir, IDistance by)
		{
            double range = by.Meters;
            double angle = (double)dir.heading; // degrees

            m_X += toDegreesX(new Distance(range * Math.Sin(angle * Math.PI / 180.0d)));
            m_Y += toDegreesY(new Distance(range * Math.Cos(angle * Math.PI / 180.0d)));
		}
Ejemplo n.º 42
0
        private IEnumerable<TakeMove> AddTakeMoves(FindTakeMovesParameter takeMoveInfo, Cell cell, IDirection direction)
        {
            int distance = cell.Type == PieceType.King ? 0 : 2;
            var squares = _boardGeometry.GetCellsByDirection(cell, direction, distance);
            bool isTaken = false;

            var result = new List<TakeMove>();

            ISquare cellTaken = null;
            foreach (var square in squares)
            {
                if (isTaken)
                {
                    if (!_position.SquareIsEmpty(square) && !square.IsEqualTo(takeMoveInfo.StartCell)) break;
                    result.Add(new TakeMove {SquareTaken = cellTaken, SquareToMove = square});
                }
                else
                {
                    if (_position.SquareIsColor(square, takeMoveInfo.StartCell.Color.GetOppositeColor()))
                    {
                        if (takeMoveInfo.IsAlreadyTaken(square)) break;
                        isTaken = true;
                        cellTaken = square;
                    }
                }
            }
            return result;
        }
Ejemplo n.º 43
0
 private ISquare AddDirection(ISquare square, IDirection direction)
 {
     return new Square(square.X + direction.DirectionX, square.Y + direction.DirectionY);
 }