private void Visit(IHardwareRobot robot)
 {
     _path.Add(new Point(robot.X, robot.Y));
     if (!_visited.ContainsKey(robot.X))
         _visited.Add(robot.X, new Dictionary<int, bool>());
     _visited[robot.X].Add(robot.Y, true);
 }
 private bool TryWalk(IHardwareRobot robot)
 {
     if (!IsValidDestination(robot)) return false;
     robot.Walk();
     Visit(robot);
     return true;
 }
        public List<Point> Execute(IHardwareRobot robot)
        {
            // quickest way back to the origin is, since the robot cannot travel diagonally,
            // to go all the way west, then all the way north (or vice-versa)

            // initialise the path by adding the current location
            var path = new List<Point> {new Point(robot.X, robot.Y)};

            //face west and return to X == 0
            if (robot.FaceTo == 3)
                robot.TurnLeft();
            else
            {
                while (robot.FaceTo != 2)
                    robot.TurnRight();
            }

            while (robot.X > 0)
            {
                robot.Walk();
                path.Add(new Point(robot.X, robot.Y));
            }

            //face north and return to Y == 0
            robot.TurnRight();
            while (robot.Y > 0)
            {
                robot.Walk();
                path.Add(new Point(robot.X, robot.Y));
            }

            return path;
        }
예제 #4
0
 public Robot(IHardwareRobot hardwareRobot, int width, int length)
 {
     this.hardwareRobot = hardwareRobot;
     room     = new Room(width, length, new DirectionMapper());
     cleaning = new Cleaning(hardwareRobot, room);
     @return  = new Return(hardwareRobot);
 }
        public List<Point> Execute(IHardwareRobot robot)
        {
            _path = new List<Point>();
            _visited = new Dictionary<int, Dictionary<int, bool>>();

            //mark starting square as visited
            Visit(robot);

            var isRoomClean = false;
            while (!isRoomClean)
            {
                robot.TurnLeft();
                if (TryWalk(robot)) continue;

                robot.TurnRight();
                if (TryWalk(robot)) continue;

                robot.TurnRight();
                if (TryWalk(robot)) continue;

                isRoomClean = true;
            }
            return _path;
        }
예제 #6
0
 public override Position GetPositionFacing(IHardwareRobot hardwareRobot)
 {
     return(NewPosition(hardwareRobot.X - 1, hardwareRobot.Y));
 }
예제 #7
0
 public Cleaning(IHardwareRobot hardwareRobot, Room room)
 {
     this.hardwareRobot = hardwareRobot;
     this.room          = room;
 }
예제 #8
0
 public abstract Position GetPositionFacing(IHardwareRobot hardwareRobot);
예제 #9
0
 public bool MapsToHardwareDirectionFor(IHardwareRobot hardwareRobot)
 {
     return(hardwareRobot.FaceTo.Equals(HardwareDirection));
 }
예제 #10
0
 public bool IsCurrentPositionFor(IHardwareRobot hardwareRobot)
 {
     return(Position.IsPositionFor(hardwareRobot));
 }
예제 #11
0
 public Position GetPositionFacingRobot(IHardwareRobot hardwareRobot)
 {
     return
         (Directions.Single(direction => direction.MapsToHardwareDirectionFor(hardwareRobot)).GetPositionFacing(
              hardwareRobot));
 }
예제 #12
0
        public virtual bool IsCleanInFront(IHardwareRobot hardwareRobot)
        {
            var positionInFrontOfRobot = directionMapper.GetPositionFacingRobot(hardwareRobot);

            return(cells.Single(cell => cell.IsAtPosition(positionInFrontOfRobot)).IsClean);
        }
예제 #13
0
 protected Command(IHardwareRobot hardwareRobot, Room room)
 {
     HardwareRobot = hardwareRobot;
     Room          = room;
 }
예제 #14
0
 public virtual bool IsPositionFor(IHardwareRobot hardwareRobot)
 {
     return(X == hardwareRobot.X && Y == hardwareRobot.Y);
 }
 private bool IsValidDestination(IHardwareRobot robot)
 {
     return !robot.IsObstacle() && !IsVisited(NextX(robot.X, robot.FaceTo), NextY(robot.Y, robot.FaceTo));
 }
예제 #16
0
 public void BaseSetUp()
 {
     HardwareRobot = NewMock <IHardwareRobot>();
 }
예제 #17
0
 public TurnRightCommand(IHardwareRobot hardwareRobot, Room room) : base(hardwareRobot, room)
 {
 }
예제 #18
0
 public WalkCommand(IHardwareRobot hardwareRobot, Room room) : base(hardwareRobot, room)
 {
 }
예제 #19
0
 public Return(IHardwareRobot hardwareRobot)
 {
     this.hardwareRobot = hardwareRobot;
 }
예제 #20
0
 public virtual void TrackCleaning(IHardwareRobot hardwareRobot)
 {
     cells.Single(cell => cell.IsCurrentPositionFor(hardwareRobot)).Clean();
 }