Esempio n. 1
0
 protected void excecute(AdvancedRobot myBot) {
   myBot.setAdjustGunForRobotTurn(
       true); // TODO: probably bad design to call this every turn, but still better than spreading
   // AdvancedRobot all
   // over the code
   myBot.setTurnGunRightRadians(gTurn);
 }
Esempio n. 2
0
  public void evaluateDistancingControl() {
    double powerTwoHitPercentageThreshold;

    if (_robot.getRoundNum() < 2) {
      _desiredDistance = 420;
      _fearDistance = 175;
      _smoothAwayDistance = 75;
    } else if (normalizedEnemyHitPercentage() > (powerTwoHitPercentageThreshold = 7.5)) {
      _desiredDistance = 525 + (Math.max((ScanLog.avgEnemyPower() - 2), 0) * 165);
      _fearDistance = 250;
      _smoothAwayDistance = 75;
    } else if (normalizedEnemyHitPercentage() > (powerTwoHitPercentageThreshold = 3)) {
      _desiredDistance = 450 + (Math.max((ScanLog.avgEnemyPower() - 2), 0) * 150);
      _fearDistance = 175;
      _smoothAwayDistance = 75;
    } else {
      _desiredDistance = 420;
      _fearDistance = 0;
      _smoothAwayDistance = 0;
    }

    if (_robot.getRoundNum() < 2 || normalizedEnemyHitPercentage() > 7.5) {
      _currentDistancer = _aggressiveDistancer;
    } else {
      _currentDistancer = _subtleDistancer;
    }
  }
Esempio n. 3
0
  public void fireWave(boolean isFiringWave) {
    int timeSinceEnemyFired = (int) ScanLog.getLastFireOffset();
    double bulletPower = ScanLog.getLastEnemyBulletPower();

    try {
      Point2D.Double myTargetLocation = ScanLog.getLocation(timeSinceEnemyFired);
      Point2D.Double enemyFireLocation = ScanLog.getEnemyLocation(timeSinceEnemyFired);
      BotScan enemySegmentationScan = ScanLog.getEnemyScan(timeSinceEnemyFired + 1);

      Wave enemyWave =
          new Wave(
              enemySegmentationScan,
              enemyFireLocation,
              myTargetLocation,
              _robot.getTime() - timeSinceEnemyFired,
              isFiringWave ? Wave.FIRING_WAVE : Wave.NON_FIRING_WAVE,
              enemySegmentationScan.getAbsBearingRadians(),
              bulletPower,
              "Surf Wave",
              Wave.TRADITIONAL_MAX_ESCAPE_ANGLE,
              enemySegmentationScan.getHeadingRadians(),
              enemySegmentationScan.getVelocity(),
              _lastEnemyWaveOrientation,
              SURF_ORIENTATION_VELOCITY_THRESHOLD);

      _waves.add(enemyWave);

      _lastEnemyWaveOrientation = enemyWave.orientation;
    } catch (IndexOutOfBoundsException noScanDataYet) {
    }
  }
Esempio n. 4
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;
  }
Esempio n. 5
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;
  }
Esempio n. 6
0
  public DookiCape(AdvancedRobot robot, boolean mc) {
    DUtils.setBattleFieldWidth(robot.getBattleFieldWidth());
    DUtils.setBattleFieldHeight(robot.getBattleFieldHeight());
    _mcMode = mc;

    _waves = new ArrayList();
    _waveRegisters = new ArrayList();
    _bulletHitRegisters = new ArrayList();

    _flattenerEnabled = false;
    _currentDistancer = _subtleDistancer = new SubtleDistancing();
    _aggressiveDistancer = new AggressiveDistancing();

    _renderables = new Vector();

    initializeSurfBuffers();
    reset(robot);
  }
Esempio n. 7
0
  public void onPaint(Graphics2D g) {
    _lastPaintRound = _robot.getRoundNum();
    _lastPaintTime = _robot.getTime();

    _radar.onPaint(g);
    if (!_tcMode) {
      _move.onPaint(g);
    }
    if (!_mcMode) {
      _gun.onPaint(g);
    }

    if (robocodePaintingOn()) {
      drawMenu();
      for (RoboGraphic r : _renderables) {
        r.render(g);
      }
      _renderables.clear();
    }
  }
Esempio n. 8
0
  public void evaluateFlattener() {
    double powerTwoHitPercentageThreshold;

    if (_robot.getRoundNum() >= 20) {
      setFlattener(
          normalizedEnemyHitPercentage() > ((powerTwoHitPercentageThreshold = 9.8))
              && _weightedEnemyShotsFired > 100);
    } else if (_robot.getRoundNum() >= 10) {
      setFlattener(
          normalizedEnemyHitPercentage() > ((powerTwoHitPercentageThreshold = 10.5))
              && _weightedEnemyShotsFired > 50);
    } else if (_robot.getRoundNum() >= 5) {
      setFlattener(
          normalizedEnemyHitPercentage() > ((powerTwoHitPercentageThreshold = 13))
              && normalizedEnemyHitPercentageLastRound() > (powerTwoHitPercentageThreshold = 14)
              && _weightedEnemyShotsFired > 20);
    } else {
      setFlattener(false);
    }
  }
Esempio n. 9
0
 public MovSimStat[] futurePos(int steps, AdvancedRobot b, double maxVel, double maxTurnRate) {
   return futurePos(
       steps,
       b.getX(),
       b.getY(),
       b.getVelocity(),
       maxVel,
       b.getHeadingRadians(),
       b.getDistanceRemaining(),
       b.getTurnRemainingRadians(),
       maxTurnRate,
       b.getBattleFieldWidth(),
       b.getBattleFieldHeight());
 }
Esempio n. 10
0
 public RobotModel(ScannedRobotEvent fs, AdvancedRobot parent) { // firstScan
   this(
       fs.getName(),
       parent.getHeight(),
       parent.getWidth(),
       fs.getEnergy(),
       // TODO update parent. if a more intelligent method is found
       parent.getGunCoolingRate(),
       parent.getGunHeadingRadians(),
       parent.getGunHeat(),
       parent.getRadarHeadingRadians(),
       fs.getHeadingRadians(),
       fs.getVelocity(),
       // adjusted locations
       getX(fs, parent.getHeadingRadians(), parent.getX()),
       getY(fs, parent.getHeadingRadians(), parent.getY()));
   this.parent = parent;
 }
Esempio n. 11
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;
  }
Esempio n. 12
0
 public void update(AdvancedRobot self) {
   if (self.getName().equals(name)) {
     tc.update(
         self.getTime(),
         self.getEnergy(),
         tm.predict_gun_heading(self, tc),
         tm.predict_gun_heat(self, tc),
         correct_angle(self.getHeadingRadians()),
         self.getVelocity(),
         self.getX(),
         self.getY());
     mm.update(self);
   }
 }
Esempio n. 13
0
  public void disableFlattener() {
    _flattenerEnabled = false;

    _waveRegisters.remove(_highStatBuffers);
    _waveRegisters.remove(_lowStatBuffers);

    if (_robot.getRoundNum() >= 3 && normalizedEnemyHitPercentage() < 4) {
      _highStatBuffers.setBulletHitWeight(0.2);
      _lowStatBuffers.setBulletHitWeight(0.2);
    } else {
      _highStatBuffers.setBulletHitWeight(1.0);
      _lowStatBuffers.setBulletHitWeight(1.0);
    }

    System.out.println("Curve Flattening disabled.");
  }
Esempio n. 14
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);
        }
      }
    }
  }
Esempio n. 15
0
  public void roundOver() {
    _lastRoundNormalizedHitPercentage = normalizedEnemyHitPercentageThisRound();

    System.out.println();
    System.out.println(
        "Enemy's hit % this round: "
            + ((int) ScanLog.getEnemyBulletHitsThisRound())
            + " / "
            + ((int) ScanLog.getEnemyBulletsFiredThisRound())
            + ", "
            + DUtils.round(ScanLog.getEnemyHitPercentageThisRound(), 2));
    System.out.println(
        "Enemy's normalized hit % this round: "
            + DUtils.round(_weightedEnemyShotsHitThisRound, 2)
            + " / "
            + DUtils.round(_weightedEnemyShotsFiredThisRound, 0)
            + ", "
            + DUtils.round(_lastRoundNormalizedHitPercentage, 2));

    System.out.println(
        "Enemy's cumulative hit %: "
            + ((int) ScanLog.getEnemyBulletHits())
            + " / "
            + ((int) ScanLog.getEnemyBulletsFired())
            + ", "
            + DUtils.round(ScanLog.getEnemyHitPercentage(), 2));
    System.out.println(
        "Enemy's normalized cum hit %: "
            + DUtils.round(_weightedEnemyShotsHit, 2)
            + " / "
            + DUtils.round(_weightedEnemyShotsFired, 0)
            + ", "
            + DUtils.round(normalizedEnemyHitPercentage(), 2));
    System.out.println("Curve Flattener: " + ((_flattenerEnabled) ? "Enabled" : "Disabled"));
    System.out.println("Total damage taken: " + DUtils.round(ScanLog.getBulletDamageTaken(), 2));

    if (_mcMode) {
      System.out.println();
      System.out.println(
          "MC score: "
              + DUtils.round(
                  (100.0 - (ScanLog.getBulletDamageTaken() / (_robot.getRoundNum() + 1.0))), 3));
    }
  }
 public static void setBackAsFront(AdvancedRobot robot, double goAngle) {
   double angle = Utils.normalRelativeAngle(goAngle - robot.getHeadingRadians());
   if (Math.abs(angle) > (Math.PI / 2)) {
     if (angle < 0) {
       robot.setTurnRightRadians(Math.PI + angle);
     } else {
       robot.setTurnLeftRadians(Math.PI - angle);
     }
     robot.setBack(100);
   } else {
     if (angle < 0) {
       robot.setTurnLeftRadians(-1 * angle);
     } else {
       robot.setTurnRightRadians(angle);
     }
     robot.setAhead(100);
   }
 }
Esempio n. 17
0
 public RobotModel(AdvancedRobot self) {
   this(
       self.getName(),
       self.getHeight(),
       self.getWidth(),
       self.getEnergy(),
       self.getGunCoolingRate(),
       self.getGunHeadingRadians(),
       self.getGunHeat(),
       self.getRadarHeadingRadians(),
       self.getHeadingRadians(),
       self.getVelocity(),
       self.getX(),
       self.getY());
 }
Esempio n. 18
0
 public void setOut(PrintStream printStream) {
   helperRobot.setOut(printStream);
 }
Esempio n. 19
0
 public void turnGunRight(double degrees) {
   helperRobot.turnGunRight(degrees);
 }
Esempio n. 20
0
 public void turnLeft(double degrees) {
   helperRobot.turnLeft(degrees);
 }
Esempio n. 21
0
  public void surf() {
    RobotState currentState =
        new RobotState(
            ScanLog.myLocation(),
            _robot.getHeadingRadians(),
            _robot.getVelocity(),
            _robot.getTime());
    boolean goingClockwise = (_lastMovementChoice == CLOCKWISE_OPTION);

    double orbitCounterClockwiseDanger =
        checkDanger(
            currentState, COUNTERCLOCKWISE_OPTION, goingClockwise, FIRST_WAVE, WAVES_TO_SURF);
    double stopDanger =
        checkDanger(currentState, STOP_OPTION, goingClockwise, FIRST_WAVE, WAVES_TO_SURF);
    double orbitClockwiseDanger =
        checkDanger(currentState, CLOCKWISE_OPTION, goingClockwise, FIRST_WAVE, WAVES_TO_SURF);

    int goOrientation = _lastMovementChoice;

    Wave orbitWave = findSurfableWave(FIRST_WAVE);
    double orbitAbsBearing, distanceToClosestWaveSource;

    try {
      distanceToClosestWaveSource = ScanLog.myLocation().distance(orbitWave.sourceLocation);
      orbitAbsBearing = DUtils.absoluteBearing(orbitWave.sourceLocation, ScanLog.myLocation());
    } catch (NullPointerException noSurfableWaves) {
      distanceToClosestWaveSource = ScanLog.getLastDistance();
      orbitAbsBearing = ScanLog.getLastEnemyScan().getAbsBearingRadians();
    }

    double goAngle, attackAngle;
    if (stopDanger == NO_SURFABLE_WAVES) {
      attackAngle = -1.047;
      _robot.setMaxVelocity(8);

      double goAngleCcw =
          orbitAbsBearing + (COUNTERCLOCKWISE_OPTION * ((Math.PI / 2) + attackAngle));
      goAngleCcw =
          wallSmoothing(
              ScanLog.myLocation(),
              goAngleCcw,
              COUNTERCLOCKWISE_OPTION,
              distanceToClosestWaveSource);

      double goAngleCw = orbitAbsBearing + (CLOCKWISE_OPTION * ((Math.PI / 2) + attackAngle));
      goAngleCw =
          wallSmoothing(
              ScanLog.myLocation(), goAngleCw, CLOCKWISE_OPTION, distanceToClosestWaveSource);

      if (Math.abs(Utils.normalRelativeAngle(goAngleCw - orbitAbsBearing))
          < Math.abs(Utils.normalRelativeAngle(goAngleCcw - orbitAbsBearing))) {
        goOrientation = CLOCKWISE_OPTION;
        goAngle = goAngleCw;
      } else {
        goOrientation = COUNTERCLOCKWISE_OPTION;
        goAngle = goAngleCcw;
      }
    } else {
      _robot.setMaxVelocity(8);
      attackAngle = _currentDistancer.attackAngle(distanceToClosestWaveSource, _desiredDistance);

      if (ScanLog.enemyIsRammer()
          && ScanLog.getLastDistance() < 300
          && orbitWave != NO_WAVE_FOUND) {
        if (Utils.normalRelativeAngle(
                DUtils.absoluteBearing(ScanLog.myLocation(), orbitWave.sourceLocation)
                    - ScanLog.getLastScan().getAbsBearingRadians())
            > 0) {
          goOrientation = -1;
        } else {
          goOrientation = 1;
        }
      } else if (stopDanger <= orbitCounterClockwiseDanger
          && stopDanger <= orbitClockwiseDanger
          && !ScanLog.enemyIsRammer()) {

        _robot.setMaxVelocity(0);
      } else {
        if (orbitClockwiseDanger < orbitCounterClockwiseDanger) {
          goOrientation = CLOCKWISE_OPTION;
        } else {
          goOrientation = COUNTERCLOCKWISE_OPTION;
        }
      }

      goAngle = orbitAbsBearing + (goOrientation * ((Math.PI / 2) + attackAngle));
      goAngle =
          wallSmoothing(ScanLog.myLocation(), goAngle, goOrientation, distanceToClosestWaveSource);
    }

    DUtils.setBackAsFront(_robot, goAngle);

    _lastMovementChoice = goOrientation;
  }
Esempio n. 22
0
 public void setPeer(IBasicRobotPeer robotPeer) {
   helperRobot.setPeer(robotPeer);
 }
Esempio n. 23
0
 public void ahead(double distance) {
   helperRobot.ahead(distance);
 }
Esempio n. 24
0
 public void back(double distance) {
   helperRobot.back(distance);
 }
Esempio n. 25
0
 protected boolean robocodePaintingOn() {
   return (_lastPaintRound == _robot.getRoundNum() && _robot.getTime() - _lastPaintTime <= 1);
 }
Esempio n. 26
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;
  }
Esempio n. 27
0
  public void onScannedRobot(ScannedRobotEvent e) {

    /*-------- setup data -----*/
    if (enemyName == null) {

      enemyName = e.getName();
    }
    Point2D.Double robotLocation = new Point2D.Double(bot.getX(), bot.getY());
    double theta;
    final double enemyAbsoluteBearing = bot.getHeadingRadians() + e.getBearingRadians();
    final double enemyDistance = e.getDistance();
    enemyLocation = projectMotion(robotLocation, enemyAbsoluteBearing, enemyDistance);
    final double enemyEnergy = e.getEnergy();

    Rectangle2D.Double BF = new Rectangle2D.Double(18, 18, 764, 564);

    /*
        To explain the below; if the enemy's absolute acceleration is
        zero then we segment on time since last velocity change, lateral
        acceleration and lateral velocity.
        If their absolute acceleration is non zero then we segment on absolute
        acceleration and absolute velocity.
        Regardless we segment on walls (near/far approach to walls) and distance.
        I'm trying to have my cake and eat it, basically. :-)
    */
    MicroWave w = new MicroWave();

    final double lastLatVel = enemyLatVel;
    double lastVelocity = enemyVelocity;
    enemyLatVel =
        (enemyVelocity = e.getVelocity()) * Math.sin(e.getHeadingRadians() - enemyAbsoluteBearing);

    int distanceIndex = (int) enemyDistance / 140;

    double bulletPower = distanceIndex == 0 ? 3 : 2;
    theta = Math.min(bot.getEnergy() / 4, Math.min(enemyEnergy / 4, bulletPower));
    if (theta == bulletPower) bot.addCustomEvent(w);
    bulletPower = theta;
    w.bulletVelocity = 20D - 3D * bulletPower;

    int accelIndex = (int) Math.round(Math.abs(enemyLatVel) - Math.abs(lastLatVel));

    if (enemyLatVel != 0) bearingDirection = enemyLatVel > 0 ? 1 : -1;
    w.bearingDirection = bearingDirection * Math.asin(8D / w.bulletVelocity) / GF_ZERO;

    double moveTime = w.bulletVelocity * lastVChangeTime++ / enemyDistance;
    int bestGF = moveTime < .1 ? 1 : moveTime < .3 ? 2 : moveTime < 1 ? 3 : 4;

    int vIndex = (int) Math.abs(enemyLatVel / 3);

    if (Math.abs(Math.abs(enemyVelocity) - Math.abs(lastVelocity)) > .6) {
      lastVChangeTime = 0;
      bestGF = 0;

      accelIndex = (int) Math.round(Math.abs(enemyVelocity) - Math.abs(lastVelocity));
      vIndex = (int) Math.abs(enemyVelocity / 3);
    }

    if (accelIndex != 0) accelIndex = accelIndex > 0 ? 1 : 2;

    w.firePosition = robotLocation;
    w.enemyAbsBearing = enemyAbsoluteBearing;
    // now using PEZ' near-wall segment
    w.waveGuessFactors =
        guessFactors[accelIndex][bestGF][vIndex][
            BF.contains(
                    projectMotion(
                        robotLocation,
                        enemyAbsoluteBearing + w.bearingDirection * GF_ZERO,
                        enemyDistance))
                ? 0
                : BF.contains(
                        projectMotion(
                            robotLocation,
                            enemyAbsoluteBearing + .5 * w.bearingDirection * GF_ZERO,
                            enemyDistance))
                    ? 1
                    : 2][
            distanceIndex];

    bestGF = GF_ZERO;

    for (int gf = GF_ONE; gf >= 0 && enemyEnergy > 0; gf--)
      if (w.waveGuessFactors[gf] > w.waveGuessFactors[bestGF]) bestGF = gf;

    bot.setTurnGunRightRadians(
        Utils.normalRelativeAngle(
            enemyAbsoluteBearing
                - bot.getGunHeadingRadians()
                + w.bearingDirection * (bestGF - GF_ZERO)));

    if (bot.getEnergy() > 1 || distanceIndex == 0) bot.setFire(bulletPower);

    bot.setTurnRadarRightRadians(
        Utils.normalRelativeAngle(enemyAbsoluteBearing - bot.getRadarHeadingRadians()) * 2);
  }
Esempio n. 28
0
 public void fire(double power) {
   helperRobot.fire(power);
 }