예제 #1
0
파일: Direction.cs 프로젝트: odw1/Katas
 static Direction()
 {
     North = new Direction(() => West, () => East);
     East = new Direction(() => North, () => South);
     South = new Direction(() => East, () => West);
     West = new Direction(() => South, () => North);
 }
예제 #2
0
파일: Grid.cs 프로젝트: dom97/MarsRoverKata
        private Coordinate GetSpaceBehindCandidate(Coordinate coordinate, Direction direction)
        {
            if (direction == Direction.North)
            {
                if (coordinate.Y == 0)
                    return new Coordinate(coordinate.X, Rows - 1);

                return new Coordinate(coordinate.X, coordinate.Y - 1);
            }
            else if (direction == Direction.East)
            {
                if (coordinate.X == 0)
                    return new Coordinate(Columns - 1, coordinate.Y);

                return new Coordinate(coordinate.X - 1, coordinate.Y);
            }
            else if (direction == Direction.South)
            {
                if (coordinate.Y == Rows - 1)
                    return new Coordinate(coordinate.X, 0);

                return new Coordinate(coordinate.X, coordinate.Y + 1);
            }
            else if (coordinate.X == Columns - 1)
                return new Coordinate(0, coordinate.Y);
            else
                return new Coordinate(coordinate.X + 1, coordinate.Y);
        }
예제 #3
0
파일: Rover.cs 프로젝트: stimms/MarsRover
 public Rover(Direction direction, Point location, IGrid grid, IMoveSupplier moveSupplier)
 {
     this.Direction = direction;
     this.Location = location;
     this.grid = grid;
     this.moveSupplier = moveSupplier;
 }
예제 #4
0
        public Coordinate GetSpaceInFront(Coordinate space, Direction direction)
        {
            if (direction == Direction.North)
            {
                if (space.Y + 1 >= numOfRows)
                    return new Coordinate(space.X, 0);

                return new Coordinate(space.X, space.Y + 1);
            }
            else if (direction == Direction.East)
            {
                if (space.X + 1 >= numOfCols)
                    return new Coordinate(0, space.Y);

                return new Coordinate(space.X + 1, space.Y);
            }
            else if (direction == Direction.West)
            {
                if (space.X - 1 < 0)
                    return new Coordinate(numOfCols - 1, space.Y);

                return new Coordinate(space.X - 1, space.Y);
            }
            else
            {
                if (space.Y - 1 < 0)
                    return new Coordinate(space.X, numOfRows - 1);

                return new Coordinate(space.X, space.Y - 1);
            }
        }
예제 #5
0
파일: Grid.cs 프로젝트: dom97/MarsRoverKata
        public Coordinate GetNextSpaceBehind(Coordinate coordinate, Direction direction)
        {
            var nextSpaceCandidate = GetSpaceBehindCandidate(coordinate, direction);

            if (obstacles.Contains(nextSpaceCandidate))
                return coordinate;

            return nextSpaceCandidate;
        }
예제 #6
0
파일: Rover.cs 프로젝트: Rudithus/MarsRover
 public void Turn(Direction direction)
 {
     //Turning left is anticlockwise, right is clockwise
     if (Orientation == OrientationEnum.W && direction == Direction.Right)
         Orientation = OrientationEnum.N;
     else if (Orientation == OrientationEnum.N && direction == Direction.Left)
         Orientation = OrientationEnum.W;
     else
         Orientation += direction == Direction.Left ? -1 : 1;
 }
예제 #7
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="point">Defines position</param>
        /// <param name="direction">Default Value is North</param>
        public Location(Point point, Direction direction = MarsRover.Direction.N)
        {
            // Location must have a definite coordinate
            if (point == null)
                throw new ArgumentNullException("point");

            // Negative coordinates are not allowed.
            if (point.X < 0 || point.Y < 0)
                throw new Exception("Coordinates (X,Y) can not be negative");

            _point = point;
            _direction = direction;
        }
예제 #8
0
파일: Grid.cs 프로젝트: dom97/MarsRoverKata
        private Coordinate GetSpaceInFrontCandidate(Coordinate coordinate, Direction direction)
        {
            if (direction == Direction.North)
                return new Coordinate(coordinate.X, (coordinate.Y + 1) % 10);
            else if (direction == Direction.East)
                return new Coordinate((coordinate.X + 1) % 10, coordinate.Y);
            else if (direction == Direction.South)
            {
                if (coordinate.Y == 0)
                    return new Coordinate(coordinate.X, Rows - 1);

                return new Coordinate(coordinate.X, (coordinate.Y - 1) % 10);
            }
            else if (coordinate.X == 0)
                return new Coordinate(Columns - 1, coordinate.Y);
            else
                return new Coordinate((coordinate.X - 1) % 10, coordinate.Y);
        }
        public static Orientation GetOrientation(Direction direction)
        {
            IMovementStratergy verticalMovement = new VerticalMovementStratergy ();
            IMovementStratergy horizontalMovement = new HorizantalMovementStratergy ();
            switch (direction) {
            case Direction.North:
                return new Orientation(Direction.West, Direction.East, verticalMovement );
            case Direction.East:
                return new Orientation (Direction.North, Direction.South,horizontalMovement);
            case Direction.South:
                return new Orientation (Direction.East, Direction.West,verticalMovement);
            case Direction.West:
                return new Orientation (Direction.South, Direction.North,horizontalMovement);
            default:
                return new Orientation (Direction.None, Direction.None,horizontalMovement);

            }
        }
예제 #10
0
파일: Move.cs 프로젝트: stimms/MarsRover
 public void ExecuteMove(ref Direction direction, ref Point location)
 {
     switch (direction)
     {
         case Direction.N:
             location = new Point(location.X, location.Y + 1);
             break;
         case Direction.S:
             location = new Point(location.X, location.Y - 1);
             break;
         case Direction.E:
             location = new Point(location.X + 1, location.Y);
             break;
         case Direction.W:
             location = new Point(location.X - 1, location.Y);
             break;
         default:
             throw new InvalidMoveException();
     }
 }
예제 #11
0
 public void ExecuteMove(ref Direction direction, ref Point location)
 {
     switch (direction)
     {
         case Direction.N:
             direction = Direction.E;
             break;
         case Direction.S:
             direction = Direction.W;
             break;
         case Direction.E:
             direction = Direction.S;
             break;
         case Direction.W:
             direction = Direction.N;
             break;
         default:
             throw new InvalidMoveException();
     }
 }
예제 #12
0
파일: Rover.cs 프로젝트: ploegert/ganshani
 /// <summary>
 /// Gets the new direction based on the current direction and the movement
 /// </summary>
 /// <param name="direction">Represents the current direction of the rover.</param>
 /// <param name="command">The movement command (L or R).</param>
 /// <returns>New direction the rover points to.</returns>
 private Direction GetNewDirection(Direction direction, char command)
 {
     if (direction == Direction.N && command == 'L' ||
         direction == Direction.S && command == 'R')
         return Direction.W;
     else if (direction == Direction.N && command == 'R' ||
         direction == Direction.S && command == 'L')
         return Direction.E;
     else if (direction == Direction.E && command == 'L' ||
         direction == Direction.W && command == 'R')
         return Direction.N;
     else if (direction == Direction.E && command == 'R' ||
         direction == Direction.W && command == 'L')
         return Direction.S;
     else
         throw new Exception(String.Format("Rover {0} : Unknown combination of movement found", Name));
 }
예제 #13
0
 public Rover(int x, int y, Direction direction)
 {
     this._x = x;
     this._y = y;
     this._direction = direction;
 }
예제 #14
0
 public void Reset()
 {
     this._x = 0;
     this._y = 0;
     this._direction = Direction.North;
 }
예제 #15
0
 private bool turnLeftOrRight(Command command)
 {
     if (command == Command.f || command == Command.b)
         return false;
     int increase = 1;
     if (command == Command.l)
         increase = -1;
     int direction = (int)this._direction + increase;
     if (direction == -1)
         direction = 3;
     if (direction == 4)
         direction = 0;
     this._direction = (Direction)direction;
     return true;
 }
예제 #16
0
 public Orientation(Direction left, Direction right, IMovementStratergy movementStratergy)
 {
     _left = left;
     _right = right;
     _movementStratergy = movementStratergy;
 }
예제 #17
0
 public void Turn(Direction direction)
 {
     Output = $"I turned to { direction}";
 }