Пример #1
0
  @Override
  public void onStep(Controller controller, Snapshot snapshot) throws ConfusedException {

    // get our robot and the ball
    Robot ourRobot = snapshot.getBalle();
    Ball ball = snapshot.getBall();

    // if neither the ball nor the robot can be found then return
    if ((ourRobot.getPosition() == null) || (ball.getPosition() == null)) {
      return;
    }

    Strategy strategy = getStrategy(snapshot);
    LOG.debug("Selected strategy: " + strategy.getClass().getName());

    // use strategy that was chosen
    setCurrentStrategy(strategy.getClass().getName());

    try {

      strategy.step(controller, snapshot);

    } catch (ConfusedException e) {

      // If a strategy does not know what to do
      LOG.error("Wut Wut?", e);
      // Default to goToBallPFN
      Intercept.step(controller, snapshot);
    }
  }
Пример #2
0
  // function to choose strategy to be used
  private Strategy getStrategy(Snapshot snapshot) {

    // get all objects
    Robot ourRobot = snapshot.getBalle();

    RectangularObject dribbleBox = ourRobot.getFrontSide().extendBothDirections(0.01).widen(0.25);
    addDrawable(new DrawableRectangularObject(dribbleBox, Color.CYAN));

    System.out.println((boolean) ((CurvyIntercept) Intercept).isDone());
    if (!(boolean) ((CurvyIntercept) Intercept).isDone()) {
      addDrawables(Intercept.getDrawables());
      return Intercept;
    } else {
      return Score;
    }
  }
  public MovementDirection getMovementDirection(Snapshot snapshot) {
    Robot opponent = snapshot.getOpponent();
    Robot ourRobot = snapshot.getBalle();
    Goal ourGoal = snapshot.getOwnGoal();
    Ball ball = snapshot.getBall();

    if ((opponent.getPosition() == null) || (ourRobot.getPosition() == null))
      return MovementDirection.NONE;

    Coord intersectionPoint = null;
    if ((ball.getPosition() != null) && (!ball.getPosition().isEstimated()))
      intersectionPoint =
          opponent.getBallKickLine(ball).getIntersect(ourRobot.getFacingLineBothWays());

    if (intersectionPoint == null)
      intersectionPoint = opponent.getFacingLine().getIntersect(ourRobot.getFacingLineBothWays());

    if (intersectionPoint == null) return MovementDirection.NONE;

    double yCoord = intersectionPoint.getY();
    yCoord = Math.max(yCoord, ourGoal.getMinY() + Globals.ROBOT_LENGTH / 3);
    yCoord = Math.min(yCoord, ourGoal.getMaxY() - Globals.ROBOT_LENGTH / 3);

    Coord targetPoint = new Coord(ourRobot.getPosition().getX(), yCoord);
    addDrawable(new Dot(targetPoint, Color.WHITE));

    boolean isUpward;
    Orientation ourOrientation = ourRobot.getOrientation();
    if ((ourOrientation.radians() >= 0) && (ourOrientation.radians() < Math.PI)) isUpward = true;
    else isUpward = false;

    // If we are already blocking the point stop
    if (ourRobot.containsCoord(targetPoint)) return MovementDirection.NONE;

    double diff = (targetPoint.getY() - ourRobot.getPosition().getY());
    if (diff > 0)
      if (isUpward) return MovementDirection.FORWARD;
      else return MovementDirection.BACKWARD;
    else if (isUpward) return MovementDirection.BACKWARD;
    else return MovementDirection.FORWARD;
  }