Beispiel #1
0
 public void MarkCellAsCleaned(Location location)
 {
     if (!_cleanedCells.Contains(location))
     {
         _cleanedCells.Add(location);
     }
 }
Beispiel #2
0
 public Robot(CommandSet commandSet, IReport reporter, Location bottomLeftBound, Location topRightBound)
 {
     _commandSet = commandSet;
     _reporter = reporter;
     _bottomLeftBound = bottomLeftBound;
     _topRightBound = topRightBound;
     Position = _commandSet.StartPosition;
 }
Beispiel #3
0
        private void MoveRobot(MovementCommand move)
        {
            switch (move.MoveDirection)
            {
                case Direction.North:
                    Position = new Location(Position.X, Position.Y + 1);
                    break;
                case Direction.East:
                    Position = new Location(Position.X + 1, Position.Y);
                    break;
                case Direction.South:
                    Position = new Location(Position.X, Position.Y - 1);
                    break;
                case Direction.West:
                    Position = new Location(Position.X - 1, Position.Y);
                    break;
            }

            Position.Validate(_bottomLeftBound, _topRightBound);

            if (_reporter != null) _reporter.RegisterNewPosition(Position);
        }
 /// <summary>
 /// Executes single robot command.
 /// </summary>
 /// <param name="command">Robot command for execution</param>
 public void ExecuteCommand(RobotCommand command)
 {
     var startLocation = new Location(LastLocation.X, LastLocation.Y);
     for (int steps = 1; steps <= command.Distance; steps++)
     {
         switch (command.Direction)
         {
             case Direction.West:
                 CleanLocation(new Location(startLocation.X - steps, startLocation.Y));
                 break;
             case Direction.East:
                 CleanLocation(new Location(startLocation.X + steps, startLocation.Y));
                 break;
             case Direction.North:
                 CleanLocation(new Location(startLocation.X, startLocation.Y + steps));
                 break;
             case Direction.South:
                 CleanLocation(new Location(startLocation.X, startLocation.Y - steps));
                 break;
             default:
                 throw new ArgumentOutOfRangeException();
         }
     }
 }
 /// <summary>
 /// Cleans single location and records last robot position.
 /// </summary>
 /// <param name="location">Location for cleaning</param>
 private void CleanLocation(Location location)
 {
     _cleanedLocations.Add(location);
     LastLocation = location;
 }
 /// <summary>
 /// Constructor. Initializes robot cleaner.
 /// </summary>
 /// <param name="startLocation">Robot start location</param>
 public RobotCleaner(Location startLocation)
 {
     LastLocation = startLocation;
     _cleanedLocations = new HashSet<Location> {startLocation};
 }
 public void RegisterNewPosition(Location position)
 {
     _cleanedLocationStrings.Add(position);
 }
 public CleaningProgram(Location initialPosition, IList<MovementInstruction> moveInstructions)
 {
     InitialPosition = initialPosition;
     MoveInstructions = new List<MovementInstruction>(moveInstructions);
 }
 /// <summary>
 /// Parses robot location. First expected parameters is point on horizontal axis of Cartesian coordinate system,
 /// and second expected parameter is point on vertical axis of Cartesian coordinate system.
 /// Points should be divided by single space.
 /// </summary>
 /// <param name="position">Robot location in sting format</param>
 /// <returns>Parsed robot location</returns>
 public static Location ParseRobotLocation(string position)
 {
     var splitted = position.Split(' ');
     var location = new Location(Int32.Parse(splitted[0]), Int32.Parse(splitted[1]));
     return location;
 }
Beispiel #10
0
 protected bool Equals(Location other)
 {
     return X == other.X && Y == other.Y;
 }