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; }
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; }
public override Position GetPositionFacing(IHardwareRobot hardwareRobot) { return(NewPosition(hardwareRobot.X - 1, hardwareRobot.Y)); }
public Cleaning(IHardwareRobot hardwareRobot, Room room) { this.hardwareRobot = hardwareRobot; this.room = room; }
public abstract Position GetPositionFacing(IHardwareRobot hardwareRobot);
public bool MapsToHardwareDirectionFor(IHardwareRobot hardwareRobot) { return(hardwareRobot.FaceTo.Equals(HardwareDirection)); }
public bool IsCurrentPositionFor(IHardwareRobot hardwareRobot) { return(Position.IsPositionFor(hardwareRobot)); }
public Position GetPositionFacingRobot(IHardwareRobot hardwareRobot) { return (Directions.Single(direction => direction.MapsToHardwareDirectionFor(hardwareRobot)).GetPositionFacing( hardwareRobot)); }
public virtual bool IsCleanInFront(IHardwareRobot hardwareRobot) { var positionInFrontOfRobot = directionMapper.GetPositionFacingRobot(hardwareRobot); return(cells.Single(cell => cell.IsAtPosition(positionInFrontOfRobot)).IsClean); }
protected Command(IHardwareRobot hardwareRobot, Room room) { HardwareRobot = hardwareRobot; Room = room; }
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)); }
public void BaseSetUp() { HardwareRobot = NewMock <IHardwareRobot>(); }
public TurnRightCommand(IHardwareRobot hardwareRobot, Room room) : base(hardwareRobot, room) { }
public WalkCommand(IHardwareRobot hardwareRobot, Room room) : base(hardwareRobot, room) { }
public Return(IHardwareRobot hardwareRobot) { this.hardwareRobot = hardwareRobot; }
public virtual void TrackCleaning(IHardwareRobot hardwareRobot) { cells.Single(cell => cell.IsCurrentPositionFor(hardwareRobot)).Clean(); }