/// <summary> /// Builds a robot /// </summary> /// <param name="startingPoint">Starting point in the grid</param> /// <param name="startingDirection">Direction to start in. 0 is north, 1 is east, 2 is south, 3 is west</param> /// <param name="obstacleHolder">holder for the obstacles</param> /// <param name="maxX">Maximum x location</param> /// <param name="maxY">Maximum y location</param> public ARobot(Point startingPoint, int startingDirection, ObstacleHolder obstacleHolder, int maxX, int maxY) { _currentPoint = new Point(); _currentPoint.XPoint = startingPoint.XPoint; _currentPoint.YPoint = startingPoint.YPoint; _currentDirection = startingDirection; _maxX = maxX; _maxY = maxY; _path = new List <Point>(); _path.Add(_currentPoint); _obstacleHolder = obstacleHolder; }
static void Main(string[] args) { string filepath = ""; //get the file to parse if (args.Length == 0) { //if there's no argument, assume that it's in the same directory as the EXE filepath = "RobotSetup.json"; } else { filepath = args[0]; } //parse the file and store the values FileParser parser = new FileParser(); var setValues = parser.ParseFile(filepath); _obstacleHolder = setValues.ObstacleHolder; _steps = setValues.Steps; _maxX = setValues.MaxX; _maxY = setValues.MaxY; //make a bot Point startingPoint = new Point(0, 0); IRobot robot = new SimpleRobot(startingPoint, 0, _obstacleHolder, _maxX, _maxY); //start running the bot foreach (var step in _steps) { robot.Move(step); } //print the path int counter = 0; foreach (var step in robot.GetPath()) { Console.WriteLine(String.Format("{0}: ({1},{2})", counter, step.XPoint, step.YPoint)); counter++; } Console.WriteLine("\n\nEnter to exit..."); Console.ReadLine(); }
public void SetGetObstacleByCoords() { _obstacleHolder = new ObstacleHolder(5, 5); _obstacleHolder.SetObstacle(new Point(2, 2), new Rock()); Assert.IsInstanceOfType(_obstacleHolder.GetObstacle(new Point(2, 2)), typeof(IObstacle)); }
public void SetGetObstacleByPoint() { _obstacleHolder = new ObstacleHolder(5, 5); _obstacleHolder.SetObstacle(1, 1, new Rock()); Assert.IsInstanceOfType(_obstacleHolder.GetObstacle(1, 1), typeof(IObstacle)); }
/// <summary> /// Builds a simple robot /// </summary> /// <param name="startingPoint">Starting point in the grid</param> /// <param name="startingDirection">Direction to start in. 0 is north, 1 is east, 2 is south, 3 is west</param> /// <param name="obstacleHolder">holder for the obstacles</param> /// <param name="maxX">Maximum x location</param> /// <param name="maxY">Maximum y location</param> public SimpleRobot(Point startingPoint, int startingDirection, ObstacleHolder obstacleHolder, int maxX, int maxY) : base(startingPoint, startingDirection, obstacleHolder, maxX, maxY) { }