// @param allowGreaterDistance whether or not the robot is allowed to move further away in moving
  // toward
  public Direction moveToward(MapLocation location, Boolean allowGreaterDistance)
      throws GameActionException {

    if (location == null) return null;

    MapLocation currentLocation = this.robot.locationController.currentLocation();
    double currentDistance = currentLocation.distanceSquaredTo(location);

    Direction direction = this.robot.robotController.getLocation().directionTo(location);
    int directionInteger = directionToInt(direction);

    int[] offsets = {0, 1, -1, 2, -2};
    for (int offset : offsets) {

      direction = MovementController.directionFromInt(directionInteger + offset);
      MapLocation moveLocation = currentLocation.add(direction);
      if (!allowGreaterDistance && moveLocation.distanceSquaredTo(location) > currentDistance)
        continue;

      if (this.moveTo(direction)) {

        return direction;
      }
    }
    return null;
  }
  public Direction moveToward(MapLocation location, Boolean allowGreaterDistance, int[] offsets)
      throws GameActionException {

    if (location == null) return null;

    MapLocation currentLocation = this.robot.locationController.currentLocation();
    double currentDistance = currentLocation.distanceSquaredTo(location);

    Direction direction = currentLocation.directionTo(location);
    int directionInteger = directionToInt(direction);

    if (this.actualLastPosition != null
        && currentLocation.distanceSquaredTo(this.actualLastPosition) <= 1) this.turnsStuck++;

    if (this.turnsStuck > 1) return this.moveAroundObstacleToward(location);

    if (moveTo(direction)) {

      this.actualLastPosition = currentLocation;
      return direction;

    } else {

      for (int offset : offsets) {

        Direction directionOne = MovementController.directionFromInt(directionInteger + offset);
        Direction directionTwo = MovementController.directionFromInt(directionInteger - offset);
        direction =
            this.moveTowardDirections(
                currentLocation,
                location,
                directionOne,
                directionTwo,
                allowGreaterDistance,
                currentDistance);
        if (direction != null) {

          this.actualLastPosition = currentLocation;
          return direction;
        }
      }
    }

    this.turnsStuck++;
    return null;
  }
 public static Direction directionWithOffset(Direction direction, int offset) {
   return MovementController.directionFromInt(
       MovementController.directionToInt(direction) + offset);
 }