@Override
 public String toString() {
   return "X ["
       + posBalon.getX()
       + "] Y ["
       + posBalon.getY()
       + "] Z["
       + altura
       + "] "
       + "\tjugador: "
       + idxJugador
       + "\tEs rival: "
       + ganaRival;
 }
Beispiel #2
0
 public Trajectory(Position ball, double velocity, double angle, double angleVert) {
   length = 75;
   positions = new Position[length];
   z = new double[length];
   AbstractTrajectory t =
       new AirTrajectory(velocity * Math.cos(angleVert), velocity * Math.sin(angleVert), 0, 0);
   for (int i = 0; i < length; i++) {
     double radio = t.getX((double) (i + 1) / 60d) * Constants.AMPLIFICA_VEL_TRAYECTORIA;
     positions[i] =
         new Position(
             ball.getX() + radio * Math.cos(angle), ball.getY() + radio * Math.sin(angle));
     z[i] = t.getY((double) (i + 1) / 60d) * Constants.AMPLIFICA_VEL_TRAYECTORIA * 2;
   }
 }
  private double calculateFitness(
      Position position, double z, int iter, Position last, double lastZ) {
    int oppIterToBall =
        ChimueloTacticUtils.calculateIterToBall(
            position,
            z,
            currentSituation.rivalPlayers(),
            currentSituation.rivalPlayersDetail(),
            currentSituation.rivalIterationsToKick());
    double Dx = position.getX() - last.getX();
    double Dy = position.getY() - last.getY();

    if (!position.isInsideGameField(0)) {
      if (position.getY() > Constants.LARGO_CAMPO_JUEGO / 2) {
        double posX =
            (Dx / Dy) * (Constants.LARGO_CAMPO_JUEGO / 2 - position.getY()) + position.getX();
        double Dz = z - lastZ;
        double posZ = (Dz / Dy) * (Constants.LARGO_CAMPO_JUEGO / 2 - position.getY()) + z;
        if (posZ <= Constants.ALTO_ARCO
            && Math.abs(posX) < Constants.LARGO_ARCO / 2 - Constants.RADIO_BALON
            && z - Dz <= Constants.ALTO_ARCO) {
          double fvel = Math.sqrt(Dx * Dx + Dy * Dy) / Constants.REMATE_VELOCIDAD_MAX;
          double fiter = Math.max(0, Math.min(1, (oppIterToBall - iter) / 75.0));
          double fx =
              Math.max(
                  0,
                  Math.min(
                      1, 1 - Math.abs(posX) / (Constants.LARGO_ARCO / 2 - Constants.RADIO_BALON)));
          return 1 + .40 * fvel + .45 * fiter + .15 * fx;
        }
      }
      return -1;
    }
    if (oppIterToBall <= iter) {
      double fdist = Math.max(0, Math.min(1, position.getY() / Constants.centroArcoSup.getY()));
      double fiter = Math.max(0.0, 1 - (iter - oppIterToBall) / 5.0);
      double fvel =
          Math.max(0, Math.min(1, Math.sqrt(Dx * Dx + Dy * Dy) / Constants.REMATE_VELOCIDAD_MAX));
      return -1 + (.3 * fdist + .1 * fiter + .6 * fvel);
    }
    return 0;
  }