WaveManager { public Wave findClosestWave(Point2D.Double targetLocation, long currentTime, boolean onlyFiring, String botName, double bulletPower) { double closestDistance = Double.POSITIVE_INFINITY; Wave closestWave = null; for (Wave w : _waves) { if (!w.altWave && (!onlyFiring || w.firingWave) && (bulletPower == Wave.ANY_BULLET_POWER || Math.abs(bulletPower - w.bulletPower()) < 0.001) && (botName == null || botName.equals(w.botName) || botName.equals(""))) { double targetDistanceSq = w.sourceLocation.distanceSq(targetLocation); double waveDistanceTraveled = w.distanceTraveled(currentTime); if (targetDistanceSq < square( waveDistanceTraveled + WAVE_MATCH_THRESHOLD) && targetDistanceSq > square( Math.max(0, waveDistanceTraveled - WAVE_MATCH_THRESHOLD))) { double distanceFromTargetToWave = Math.sqrt(targetDistanceSq) - waveDistanceTraveled; if (Math.abs(distanceFromTargetToWave) < closestDistance) { closestDistance = Math.abs(distanceFromTargetToWave); closestWave = w; } } } } return closestWave; } WaveManager(); void initRound(); void addWave(Wave wave); void checkCurrentWaves(
      long currentTime, CurrentWaveListener listener); void forAllWaves(AllWaveListener listener); void checkActiveWaves(
      long currentTime, RobotState lastScanState, WaveBreakListener listener); Wave findClosestWave(Point2D.Double targetLocation, long currentTime,
      boolean onlyFiring, String botName, double bulletPower); Wave findSurfableWave(
      int surfIndex, RobotState targetState, WavePosition unsurfablePosition); Wave getPastWave(int x); Wave getWaveByFireTime(long fireTime); Wave interpolateWaveByFireTime(long fireTime, long currentTime,
      double sourceHeading, double sourceVelocity, RobotStateLog stateLog,
      BattleField battleField, MovementPredictor predictor); long getLastFireTime(); int size();  }
@Test public void testFindClosestWave() { WaveManager waveManager = new WaveManager(); Wave w = newWave(newLocation(100, 100), newLocation(100, 300), 100L, 1.0); waveManager.addWave(w); waveManager.addWave( newWave(newLocation(500, 500), newLocation(550, 550), 100L, 1.0)); waveManager.addWave( newWave(newLocation(100, 100), newLocation(100, 200), 100L, 1.09)); Wave closestWave = waveManager.findClosestWave( newLocation(130, 140), 103L, false, null, 1.0); assertEquals(w, closestWave); }