Ejemplo n.º 1
0
  public double getBinScore(Wave w, Point2D.Double targetLocation) {
    double binScore = 0;

    GuessFactorWindowSet gfWindow = w.guessFactorWindow(targetLocation);
    int lowIndex = w.guessFactorIndex(gfWindow.guessFactorLow);
    int highIndex = w.guessFactorIndex(gfWindow.guessFactorHigh);

    binScore +=
        _highStatBuffers.getWindowScore(
            w.targetScan, w.targetScan.getInverseScan(), w.bulletPower, BINS, lowIndex, highIndex);
    binScore +=
        _lowStatBuffers.getWindowScore(
            w.targetScan, w.targetScan.getInverseScan(), w.bulletPower, BINS, lowIndex, highIndex);

    if (_flattenerEnabled) {
      binScore +=
          _extraFlatStatBuffers.getWindowScore(
              w.targetScan,
              w.targetScan.getInverseScan(),
              w.bulletPower,
              BINS,
              lowIndex,
              highIndex);
    }

    return binScore;
  }
Ejemplo n.º 2
0
  public Wave findSurfableWave(int waveIndex) {
    int searchWaveIndex = 0;
    long currentTime = _robot.getTime();

    for (int x = 0; x < _waves.size(); x++) {
      Wave w = (Wave) _waves.get(x);
      double distanceToWaveSource = ScanLog.myLocation().distance(w.sourceLocation);
      double distanceToWave = distanceToWaveSource - w.distanceTraveled(currentTime);

      if (w.firingWave && !w.processedBulletHit && distanceToWave > w.bulletVelocity()) {

        if (searchWaveIndex == waveIndex) {
          //					drawCircle(w.sourceLocation,
          //						w.distanceTraveled(currentTime + 1), Color.green);
          //					drawLine(w.sourceLocation,
          //						DUtils.project(w.sourceLocation, w.absBearingRadians,
          //								w.distanceTraveled(currentTime + 1)),
          //							Color.blue);
          return w;
        } else {
          searchWaveIndex++;
        }
      }
    }

    return null;
  }
Ejemplo n.º 3
0
  /*
  	public void onPaint(Graphics2D g) {
  		Iterator i = _renderables.iterator();
  		while(i.hasNext()){
  			Renderable r = (Renderable) i.next();
  			r.render(g);
  		}
  		_renderables.clear();
  	}
  */
  public Wave processBulletReturnFiringWave(Bullet bullet, long currentTime) {

    int tightMatchDistanceThreshold = 50;
    Wave hitWave =
        DUtils.findClosestWave(
            _waves,
            new Point2D.Double(bullet.getX(), bullet.getY()),
            _robot.getTime(),
            DUtils.ANY_WAVE,
            DUtils.FIRING_WAVE,
            tightMatchDistanceThreshold);

    if (hitWave == null) {
      return NO_WAVE_FOUND;
    }

    for (int x = 0; x < _bulletHitRegisters.size(); x++) {
      BulletHitRegister bhr = (BulletHitRegister) _bulletHitRegisters.get(x);

      bhr.registerBulletHit(bullet, hitWave, currentTime);
    }

    hitWave.processedBulletHit = true;

    return hitWave;
  }
Ejemplo n.º 4
0
  public void onHitByBullet(HitByBulletEvent e) {
    ScanLog.onHitByBullet(e);

    Wave hitWave = processBulletReturnFiringWave(e.getBullet(), e.getTime());

    if (hitWave != NO_WAVE_FOUND) {
      double thisHit =
          (hitWave.targetScan.getDistance() / TYPICAL_DISTANCE)
              * (hitWave.escapeAngleRange() / TYPICAL_ESCAPE_RANGE);
      _weightedEnemyShotsHit += thisHit;
      _weightedEnemyShotsHitThisRound += thisHit;
    }
  }
Ejemplo n.º 5
0
  public Wave findNonSurfableWave(double minDistanceToWave) {
    long currentTime = _robot.getTime();

    for (int x = 0; x < _waves.size(); x++) {
      Wave w = (Wave) _waves.get(x);
      double distanceToWaveSource = ScanLog.myLocation().distance(w.sourceLocation);
      double distanceToWave = distanceToWaveSource - w.distanceTraveled(currentTime);

      if (!w.firingWave && distanceToWave > minDistanceToWave) {
        return w;
      }
    }

    return null;
  }
Ejemplo n.º 6
0
  public void checkActiveWaves() {
    long currentTime = _robot.getTime();
    Point2D.Double myLocation = ScanLog.myLocation();

    for (int x = 0; x < _waves.size(); x++) {
      Wave w = (Wave) _waves.get(x);
      if (w.processedWaveBreak) {
        if (w.wavePassed(myLocation, currentTime, Wave.INACTIVE_WAVE_OFFSET)) {
          _waves.remove(x--);
        }
      } else {
        if (w.wavePassed(myLocation, currentTime)) {
          processWave(w);
        }
      }
    }
  }
Ejemplo n.º 7
0
  public void processWave(Wave w) {
    GuessFactorWindowSet gfWindow = w.guessFactorWindow(ScanLog.myLocation());
    int gfBin = w.guessFactorIndex(gfWindow.guessFactor);
    int gfBinLow = w.guessFactorIndex(gfWindow.guessFactorLow);
    int gfBinHigh = w.guessFactorIndex(gfWindow.guessFactorHigh);
    BotScan enemyScan = w.targetScan.getInverseScan();

    for (int x = 0; x < _waveRegisters.size(); x++) {
      WaveRegister wr = (WaveRegister) _waveRegisters.get(x);

      wr.registerWaveHit(
          w.targetScan,
          enemyScan,
          w.bulletPower,
          gfWindow.guessFactor,
          gfBin,
          gfBinLow,
          gfBinHigh,
          w.firingWave,
          w.fireTime,
          w.orientation,
          w.escapeAngleRange());
    }

    w.processedWaveBreak = true;
  }
Ejemplo n.º 8
0
  public double getAbsoluteAimAngle(
      Wave aimWave, BotScan scan, BotScan enemyScan, double bulletPower) {

    if (_lastFireTime == aimWave.fireTime) {
      return _lastAimAngle;
    }

    _lastAimAngle =
        Utils.normalAbsoluteAngle(
            aimWave.absBearingRadians
                + aimWave.guessAngleFromIndex(getAimBin(aimWave, scan, enemyScan, bulletPower)));

    _lastFireTime = aimWave.fireTime;

    return _lastAimAngle;
  }
Ejemplo n.º 9
0
  public double checkDanger(
      RobotState startState,
      int movementOption,
      boolean previouslyMovingClockwise,
      int surfableWaveIndex,
      int recursionLevels) {

    if (surfableWaveIndex >= recursionLevels) {
      return 0;
    }

    boolean predictClockwiseOrNot;
    if (movementOption == CLOCKWISE_OPTION) {
      predictClockwiseOrNot = true;
    } else if (movementOption == COUNTERCLOCKWISE_OPTION) {
      predictClockwiseOrNot = false;
    } else {
      predictClockwiseOrNot = previouslyMovingClockwise;
    }

    Wave surfWave = findSurfableWave(surfableWaveIndex);

    if (surfWave == null) {
      if (surfableWaveIndex == FIRST_WAVE) {
        double nonSurfableWaveDistance = 150;
        surfWave = findNonSurfableWave(nonSurfableWaveDistance);
      }

      if (surfWave == null) {
        return NO_SURFABLE_WAVES;
      }
    }
    /*
    		Color drawColor = Color.white;
    		if (surfableWaveIndex != 0 || movementOption == STOP_OPTION) {
    			drawColor = Color.blue;
    		}
    */
    double waveHitInterceptOffset = surfWave.bulletVelocity() + BOT_HALF_WIDTH;
    double wavePassedInterceptOffset = surfWave.bulletVelocity();
    RobotState predictedState = startState;
    RobotState dangerState = startState;

    boolean wavePassed = false;
    boolean waveHit = false;

    double maxVelocity = (movementOption == STOP_OPTION) ? 0 : 8;

    do {
      double orbitAbsBearing =
          DUtils.absoluteBearing(surfWave.sourceLocation, predictedState.location);
      double orbitDistance = surfWave.sourceLocation.distance(predictedState.location);
      double attackAngle = _currentDistancer.attackAngle(orbitDistance, _desiredDistance);
      boolean clockwiseSmoothing = predictClockwiseOrNot;

      if (orbitDistance < _smoothAwayDistance) {
        clockwiseSmoothing = !clockwiseSmoothing;
      }

      predictedState =
          DUtils.nextPerpendicularWallSmoothedLocation(
              predictedState.location,
              orbitAbsBearing,
              predictedState.velocity,
              maxVelocity,
              predictedState.heading,
              attackAngle,
              clockwiseSmoothing,
              predictedState.time,
              DUtils.battleField,
              DUtils.battleFieldWidth,
              DUtils.battleFieldHeight,
              _wallStick,
              DUtils.OBSERVE_WALL_HITS);

      if (!waveHit
          && surfWave.wavePassed(
              predictedState.location, predictedState.time, waveHitInterceptOffset)) {

        dangerState = predictedState;
        waveHit = true;
      }

      if (!wavePassed
          && surfWave.wavePassed(
              predictedState.location, predictedState.time, wavePassedInterceptOffset)) {

        wavePassed = true;
      }
    } while (!wavePassed);

    //		drawPoint(predictedState.location, drawColor);

    double danger = getBinScore(surfWave, dangerState.location);
    danger *= DUtils.bulletDamage(surfWave.bulletPower);

    double currentDistanceToWaveSource = ScanLog.myLocation().distance(surfWave.sourceLocation);
    double currentDistanceToWave =
        currentDistanceToWaveSource - surfWave.distanceTraveled(_robot.getTime());
    double timeToImpact = currentDistanceToWave / DUtils.bulletVelocity(surfWave.bulletPower);

    if (_flattenerEnabled) {
      danger /= DUtils.square(timeToImpact);
    } else {
      danger /= timeToImpact;
    }

    double nextCounterClockwiseDanger =
        checkDanger(
            predictedState,
            COUNTERCLOCKWISE_OPTION,
            predictClockwiseOrNot,
            surfableWaveIndex + 1,
            recursionLevels);
    double nextStopDanger =
        checkDanger(
            predictedState,
            STOP_OPTION,
            predictClockwiseOrNot,
            surfableWaveIndex + 1,
            recursionLevels);
    double nextClockwiseDanger =
        checkDanger(
            predictedState,
            CLOCKWISE_OPTION,
            predictClockwiseOrNot,
            surfableWaveIndex + 1,
            recursionLevels);

    danger += Math.min(nextCounterClockwiseDanger, Math.min(nextStopDanger, nextClockwiseDanger));
    //		danger += Math.min(nextCounterClockwiseDanger, nextClockwiseDanger);

    if (surfableWaveIndex == FIRST_WAVE) {
      double predictedDistanceToWaveSource =
          surfWave.sourceLocation.distance(predictedState.location);
      double predictedDistanceToEnemy = ScanLog.enemyLocation().distance(predictedState.location);

      double shorterDistance = Math.min(predictedDistanceToWaveSource, predictedDistanceToEnemy);
      double distancingDangerBase = Math.max(currentDistanceToWaveSource / shorterDistance, .99);
      double distancingDangerExponent =
          shorterDistance > _fearDistance
              ? NORMAL_DISTANCING_EXPONENT
              : FEARFUL_DISTANCING_EXPONENT;

      danger *= Math.pow(distancingDangerBase, distancingDangerExponent);
    }

    return danger;
  }