public IActionResult Post(PathReq pathReq) { var input = pathReq.input ?? ""; var startX = pathReq.startX; var startY = pathReq.startY; var startDir = pathReq.startDir ?? ""; var gridWidth = pathReq.gridWidth; var gridHeight = pathReq.gridHeight; var startPoint = new PathPoint(startX, startY, startDir); var roverPath = new RoverPath(gridWidth, gridHeight, startPoint); roverPath.createRoverPath(input); var pathCount = roverPath.GetNumPositions(); var path = new List <PathResPoint>(); for (var i = 0; i < pathCount; i++) { var pathPoint = roverPath.GetPathPoint(i); var point = new PathResPoint(); point.x = pathPoint.X; point.y = pathPoint.Y; point.dir = pathPoint.Dir.ToString(); path.Add(point); } var res = new PathRes(); res.path = path; res.input = input; return(Ok(res)); }
public void CreateRoverPaths() { var positionA = new Position(5, 5); var headingA = new Heading('N'); var pathA = "MMRLMM"; var roverPathA = new RoverPath(positionA, headingA, pathA); var positionB = new Position(4, 4); var headingB = new Heading('S'); var pathB = "MMMMMMM"; var roverPathB = new RoverPath(positionB, headingB, pathB); roverPathA.GetStartHeading().GetHeading().ShouldBeEquivalentTo('N'); roverPathA.GetStartPosition().ShouldBeEquivalentTo(new Position(5, 5)); roverPathB.GetStartHeading().GetHeading().ShouldBeEquivalentTo('S'); roverPathB.GetStartPosition().ShouldBeEquivalentTo(new Position(4, 4)); }
public void Constructor() { var startPoint = new PathPoint(20, 2, "UNKOWN"); roverPath = new RoverPath(8, 10, startPoint); Assert.AreEqual(1, roverPath.GetNumPositions()); Assert.AreEqual(8, roverPath.gridWidth); Assert.AreEqual(10, roverPath.gridHeight); Assert.AreEqual(7, roverPath.GetPathPoint(0).X); Assert.AreEqual(2, roverPath.GetPathPoint(0).Y); Assert.AreEqual(PathDirection.North, roverPath.GetPathPoint(0).Dir); startPoint = new PathPoint(20, 11, "S"); roverPath = new RoverPath(8, 10, startPoint); Assert.AreEqual(PathDirection.South, roverPath.GetPathPoint(0).Dir); Assert.AreEqual(roverPath.GetPathPoint(0).X, 7); Assert.AreEqual(roverPath.GetPathPoint(0).Y, 9); Assert.AreEqual(roverPath.GetPathPoint(0).Dir, PathDirection.South); }
public IActionResult Post(MissionReq pathReq) { var gridWidth = pathReq.gridWidth; var gridHeight = pathReq.gridHeight; var resPoints = new List <MissionResPoint>(); foreach (var rover in pathReq.rovers) { var startPoint = new PathPoint(rover.startX, rover.startY, rover.startDirChar); var roverPath = new RoverPath(gridWidth, gridHeight, startPoint); roverPath.createRoverPath(rover.input); var firstPoint = roverPath.GetPathPoint(0); var lastIndex = roverPath.GetNumPositions() - 1; var lastPoint = roverPath.GetPathPoint(lastIndex); var resPoint = new MissionResPoint(); resPoint.firstX = firstPoint.X; resPoint.firstY = firstPoint.Y; resPoint.firstDir = startPoint.Dir.ToString(); resPoint.lastX = lastPoint.X; resPoint.lastY = lastPoint.Y; resPoint.lastDir = lastPoint.Dir.ToString(); resPoint.input = rover.input; resPoints.Add(resPoint); } var res = new MissionRes(); res.gridWidth = gridWidth; res.gridHeight = gridHeight; res.rovers = resPoints; string resJson = JsonConvert.SerializeObject(res); System.IO.File.WriteAllText("mission.json", resJson); return(Ok(res)); }
public Bitmap getScreenshot(int gridWidth, int gridHeight, List <MissionResPoint> rovers) { var roverPaths = new List <RoverPath>(); foreach (var rover in rovers) { var startPoint = new PathPoint(rover.firstX, rover.firstY, dirStrToChar(rover.firstDir)); var roverPath = new RoverPath(gridWidth, gridHeight, startPoint); roverPath.createRoverPath(rover.input); roverPaths.Add(roverPath); } using (var fileStream = File.OpenRead(marsGridImage)) { var bmp = new Bitmap(fileStream); var gridWidthPx = roverPaths[0].gridWidthPx; var gridHeightPx = roverPaths[0].gridHeightPx; var bmpOut = new Bitmap(bmp, new Size(gridWidthPx, gridHeightPx)); CreateRoverPathBmp(bmpOut, roverPaths); return(bmpOut); } }
public void createRoverPath_TestExamples() { //RoverPath constructor uses plateau size not upper right coordinates //plateau size is 1 unit bigger var upperRightX = 5; var upperRightY = 5; var startX = 1; var startY = 2; var startDir = "N"; var instructions = "LMLMLMLMM"; var startPoint = new PathPoint(startX, startY, startDir); roverPath = new RoverPath(upperRightX + 1, upperRightY + 1, startPoint); roverPath.createRoverPath(instructions); var numPositions = roverPath.GetNumPositions(); Assert.AreEqual(1, roverPath.GetPathPoint(numPositions - 1).X); Assert.AreEqual(3, roverPath.GetPathPoint(numPositions - 1).Y); Assert.AreEqual(PathDirection.North, roverPath.GetPathPoint(numPositions - 1).Dir); startX = 3; startY = 3; startDir = "E"; instructions = "MMRMMRMRRM"; startPoint = new PathPoint(startX, startY, startDir); roverPath = new RoverPath(upperRightX + 1, upperRightY + 1, startPoint); roverPath.createRoverPath(instructions); numPositions = roverPath.GetNumPositions(); Assert.AreEqual(5, roverPath.GetPathPoint(numPositions - 1).X); Assert.AreEqual(1, roverPath.GetPathPoint(numPositions - 1).Y); Assert.AreEqual(PathDirection.East, roverPath.GetPathPoint(numPositions - 1).Dir); }
public void Setup() { var startPoint = new PathPoint(0, 0, "N"); roverPath = new RoverPath(10, 10, startPoint); }