public async Task <Robot> SetCurrentPosition(RobotPositionRequest request) { var enumDirection = Helpers.ParseEnum <GeoDirection>(request.direction); var storedRobot = await GetCurrentPosition(request.id); if (storedRobot == null) { return(null); } storedRobot.XAxis = request.horizontalAxis; storedRobot.YAxis = request.verticalAxis; storedRobot.FacingDirection = enumDirection; _robotCache.StoreCache(storedRobot); return(storedRobot); }
public async Task <Robot> MoveRobot(string robotId) { var currentRobot = await _robotCache.GetCache(robotId); if (currentRobot == null) { return(null); } var step = FinalizeRobotStepValue(currentRobot.FacingDirection); if (IsValidRobotFacingAxis(currentRobot, GeoDirection.North) || IsValidRobotFacingAxis(currentRobot, GeoDirection.South)) { if (IsWithinRange(currentRobot.YAxis, step, _config.RobotMaxRange, _config.RobotMinRange)) { currentRobot.YAxis += step; } } else { if (IsWithinRange(currentRobot.XAxis, step, _config.RobotMaxRange, _config.RobotMinRange)) { currentRobot.XAxis += step; } } _robotCache.StoreCache(currentRobot); return(currentRobot); }
public Robot GetNewRobot() { var robot = new Robot(); _robotCache.StoreCache(robot); return(robot); }
public async Task <Robot> Turn(string robotId, TurnType turnType) { var robotMaxRange = _config.RobotMaxRange; var robotMinRange = _config.RobotMinRange; var robot = await _robotCache.GetCache(robotId); if (robot == null) { return(null); } int turn = (int)turnType; var newFacingPosition = (int)robot.FacingDirection + turn > robotMaxRange ? (int)GeoDirection.North : (int)robot.FacingDirection + turn; if ((GeoDirection)newFacingPosition == GeoDirection.NotSet) { newFacingPosition = (turn < robotMinRange) ? (int)GeoDirection.West : (int)GeoDirection.East; } robot.FacingDirection = (GeoDirection)newFacingPosition; _robotCache.StoreCache(robot); return(robot); }