Exemple #1
0
  @Override
  public void paint(Graphics2D g) {
    // create graphics with reset transform
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setTransform(new AffineTransform());

    g2.setColor(new Color(255, 255, 255));
    g2.setFont(new Font("Consolas", Font.PLAIN, 12));
    g2.drawString("State: " + state, 160.0f, 20.0f);
    g2.drawString("Guessed angle: " + ramses.getGuessedAngleToGoal(), 160.0f, 42.0f);

    // highlight the ball we're after
    if (state == State.FETCH && realTargetId != -1) {
      Ball ball = ramses.getGameInfo().getBallById(realTargetId);

      if (ball != null) {
        float radius = ball.getRadius();

        g.setStroke(new BasicStroke(0.02f));

        if (ramses.getSide() == Simulation.Side.YELLOW) {
          g.setColor(new Color(220, 220, 0));
        } else {
          g.setColor(new Color(0, 0, 220));
        }

        g.draw(
            new Ellipse2D.Float(
                ball.getX() - radius, ball.getY() - radius, radius * 2.0f, radius * 2.0f));
      }
    }
  }
Exemple #2
0
  private void stepGuessedAngleUpdater(float dt) {
    List<Camera.GoalInfo> goals = ramses.getCamera().getVisibleGoals();

    Simulation.Side oppositeSide =
        ramses.getSide() == Simulation.Side.BLUE ? Simulation.Side.YELLOW : Simulation.Side.BLUE;

    for (Camera.GoalInfo goal : goals) {
      if (goal.side == oppositeSide) {
        ramses.setGuessedAngleToGoal(goal.angle / (float) Math.PI * 180.0f);
      } else {
        ramses.setGuessedAngleToGoal(goal.angle / (float) Math.PI * 180.0f - 180.0f);
      }
    }
  }
Exemple #3
0
  private void stepSearchGoal(float dt) {
    if (!stateReady) {
      targetGoalSightDuration = -1.0f;
      searchYawDir = 1.0f;
      stateReady = true;
    }

    if (!ramses.getDribbler().hasBall()) {
      setState(State.SEARCH_BALL);

      return;
    }

    ramses.setPower(0.0f);

    List<Camera.GoalInfo> goals = ramses.getCamera().getVisibleGoals();

    Simulation.Side oppositeSide =
        ramses.getSide() == Simulation.Side.BLUE ? Simulation.Side.YELLOW : Simulation.Side.BLUE;

    Camera.GoalInfo oppositeGoal = null;

    for (Camera.GoalInfo goal : goals) {
      if (goal.side == oppositeSide) {
        oppositeGoal = goal;

        if (targetGoalSightDuration == -1.0f) {
          targetGoalSightDuration = 0.0f;

          float guessedAngle = ramses.getGuessedAngleToGoal();

          if (guessedAngle > 0.0f && guessedAngle < 180.0f) {
            searchYawDir = 1.0f;
          } else {
            searchYawDir = -1.0f;
          }
        } else {
          targetGoalSightDuration += dt;
        }

        break;
      }
    }

    if (oppositeGoal != null) {
      if (targetGoalSightDuration < 0.2f) {
        // quick brake when first sighting the goal
        float guessedAngle = ramses.getGuessedAngleToGoal();

        if (guessedAngle > 0.0f) {
          ramses.setYawRate(-1.0f);
        } else {
          ramses.setYawRate(1.0f);
        }
      } else {
        // we can see the goal, turn to it
        float angleDegrees = oppositeGoal.angle / (float) Math.PI * 180.0f;

        // we know the angle right know, set it to improve guess later
        ramses.setGuessedAngleToGoal(angleDegrees);

        // the required accuracy depends on how far away the goal is - the closer
        // we are, the more we can miss the center
        float requiredAccuracy = Math.max(10.0f / (oppositeGoal.distance * 5.0f), 2.0f);

        if (angleDegrees <= requiredAccuracy) {
          // goal is centered, shoot!

          ramses.kick();

          targetId = -1;
          realTargetId = -1;
        } else {
          // goal is not centered enough, correct
          float yawRate = Math.max(Math.min(angleDegrees / 30.0f, 1.0f), -1.0f);

          ramses.setYawRate(yawRate);
        }
      }
    } else {
      ramses.setYawRate(0.25f * searchYawDir);

      targetGoalSightDuration = -1.0f;
    }
  }