コード例 #1
0
ファイル: MatthewHebert.java プロジェクト: feetheprodigy/e2
  public void onScannedRobot(ScannedRobotEvent e) {
    robotLocation = new Point2D.Double(getX(), getY());
    enemyAbsoluteBearing = getHeadingRadians() + e.getBearingRadians();
    enemyDistance = e.getDistance();
    enemyLocation = vectorToLocation(enemyAbsoluteBearing, enemyDistance, robotLocation);

    // Change direction at random
    if (Math.random() < 0.015) {
      movementLateralAngle *= -1;
    }
    move();
    execute();

    // radar
    setTurnRadarRightRadians(
        Utils.normalRelativeAngle(enemyAbsoluteBearing - getRadarHeadingRadians()) * 2);

    /*
     * Circular Gun from wiki
     */
    double absBearing = e.getBearingRadians() + getHeadingRadians();

    // Finding the heading and heading change.
    double enemyHeading = e.getHeadingRadians();
    double enemyHeadingChange = enemyHeading - oldEnemyHeading;
    oldEnemyHeading = enemyHeading;

    double deltaTime = 0;
    double predictedX = getX() + e.getDistance() * Math.sin(absBearing);
    double predictedY = getY() + e.getDistance() * Math.cos(absBearing);
    while ((++deltaTime) * BULLET_SPEED
        < Point2D.Double.distance(getX(), getY(), predictedX, predictedY)) {

      // Add the movement we think our enemy will make to our enemy's current X and Y
      predictedX += Math.sin(enemyHeading) * (e.getVelocity());
      predictedY += Math.cos(enemyHeading) * (e.getVelocity());

      // Find our enemy's heading changes.
      enemyHeading += enemyHeadingChange;

      // If our predicted coordinates are outside the walls, put them 18
      // distance units away from the walls as we know
      // that that is the closest they can get to the wall (Bots are
      // non-rotating 36*36 squares).
      predictedX = Math.max(Math.min(predictedX, getBattleFieldWidth() - 18), 18);
      predictedY = Math.max(Math.min(predictedY, getBattleFieldHeight() - 18), 18);
    }
    // Find the bearing of our predicted coordinates from us.
    double aim = Utils.normalAbsoluteAngle(Math.atan2(predictedX - getX(), predictedY - getY()));

    // Aim and fire.
    setTurnGunRightRadians(Utils.normalRelativeAngle(aim - getGunHeadingRadians()));
    setFire(BULLET_POWER);

    setTurnRadarRightRadians(Utils.normalRelativeAngle(absBearing - getRadarHeadingRadians()) * 2);
  }
コード例 #2
0
 public static double getX(ScannedRobotEvent sre, double self_h, double self_x) {
   // returns the X position of a scanned robot
   double frame_x = self_x;
   double bearing = correct_angle(self_h + sre.getBearingRadians());
   double distance = sre.getDistance();
   return frame_x + distance * Math.cos(bearing);
 }
コード例 #3
0
 public static double getY(ScannedRobotEvent sre, double self_h, double self_y) {
   // returns the Y position of a scanned robot
   double frame_y = self_y;
   double bearing = correct_angle(self_h + sre.getBearingRadians());
   double distance = sre.getDistance();
   return frame_y + distance * Math.sin(bearing);
 }
コード例 #4
0
ファイル: TheRobot.java プロジェクト: Schmirgel/ProjectX
  public void onScannedRobot(ScannedRobotEvent e) {
    // ...
    // if(getRadarHeadingRadians() - getGunHeading() == 0)
    //			fire(1);
    // Absolute angle towards target
    double angleToEnemy = getHeadingRadians() + e.getBearingRadians();

    // Subtract current radar heading to get the turn required to face the enemy, be sure it is
    // normalized
    double radarTurn = Utils.normalRelativeAngle(angleToEnemy - getRadarHeadingRadians());

    // Distance we want to scan from middle of enemy to either side
    // The 36.0 is how many units from the center of the enemy robot it scans.
    double extraTurn = Math.min(Math.atan(5.0 / e.getDistance()), Rules.RADAR_TURN_RATE_RADIANS);

    // Adjust the radar turn so it goes that much further in the direction it is going to turn
    // Basically if we were going to turn it left, turn it even more left, if right, turn more
    // right.
    // This allows us to overshoot our enemy so that we get a good sweep that will not slip.
    radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);

    // Turn the radar
    setTurnRadarRightRadians(radarTurn);

    // is the enemy left or right of us
    double distance = getRadarHeading() - getGunHeading();
    double[] wert = {distance};

    // setTurnGunLeft(encog.Adjust.predict(NETWORK, wert));

    if (distance < 0) setTurnGunRight(distance);

    if (distance >= 0) setTurnGunRight(distance);

    // System.out.println(distance);

    // if enemy is within fire range -> fire
    //	    if (getGunHeading() > getRadarHeading()-2 && getGunHeading() < getRadarHeading()+2)

    setFire(1);

    System.out.println("gunheat:" + getGunHeat());
    if (getGunHeat() == 1.2) {
      LIST.add(getTime());
      System.out.println("distance: " + LIST);
      //	    	int shouldHit = (int) (getTime() + (e.getDistance() / 17));
      //    		System.out.println("when should it hit: " + shouldHit);
    }

    if (LIST.size() != 0) {
      if (LIST.get(0) + (getTime() - LIST.get(0)) * VELOCITY > e.getDistance()) {
        System.out.println("did you hit?: " + getTime());
        LIST.remove(0);
      }
    }

    execute();
  }
コード例 #5
0
ファイル: GeneticRobot.java プロジェクト: kursovoyPr/kursovoy
 public void onScannedRobot(ScannedRobotEvent event) {
   a = Utils.normalRelativeAngle(getHeadingRadians() + event.getBearingRadians());
   e = event.getEnergy();
   d = event.getDistance();
   x = d * Math.sin(a);
   y = d * Math.cos(a);
   h = event.getHeadingRadians();
   dh = -Utils.normalRelativeAngle(getGunHeadingRadians() - a);
 }
コード例 #6
0
ファイル: BasicRobotProxy.java プロジェクト: andy521/robocode
  private final Bullet setFireImpl(double power) {
    if (Double.isNaN(power)) {
      println("SYSTEM: You cannot call fire(NaN)");
      return null;
    }
    if (getGunHeatImpl() > 0 || getEnergyImpl() == 0) {
      return null;
    }

    power = min(getEnergyImpl(), min(max(power, Rules.MIN_BULLET_POWER), Rules.MAX_BULLET_POWER));

    Bullet bullet;
    BulletCommand wrapper;
    Event currentTopEvent = eventManager.getCurrentTopEvent();

    nextBulletId++;

    if (currentTopEvent != null
        && currentTopEvent.getTime() == status.getTime()
        && !statics.isAdvancedRobot()
        && status.getGunHeadingRadians() == status.getRadarHeadingRadians()
        && ScannedRobotEvent.class.isAssignableFrom(currentTopEvent.getClass())) {
      // this is angle assisted bullet
      ScannedRobotEvent e = (ScannedRobotEvent) currentTopEvent;
      double fireAssistAngle =
          Utils.normalAbsoluteAngle(status.getHeadingRadians() + e.getBearingRadians());

      bullet =
          new Bullet(
              fireAssistAngle, getX(), getY(), power, statics.getName(), null, true, nextBulletId);
      wrapper = new BulletCommand(power, true, fireAssistAngle, nextBulletId);
    } else {
      // this is normal bullet
      bullet =
          new Bullet(
              status.getGunHeadingRadians(),
              getX(),
              getY(),
              power,
              statics.getName(),
              null,
              true,
              nextBulletId);
      wrapper = new BulletCommand(power, false, 0, nextBulletId);
    }

    firedEnergy += power;
    firedHeat += Rules.getGunHeat(power);

    commands.getBullets().add(wrapper);

    bullets.put(nextBulletId, bullet);

    return bullet;
  }
コード例 #7
0
 /** onScannedRobot: What to do when you see another robot */
 public void onScannedRobot(ScannedRobotEvent e) {
   if (isFriend(e.getName())) {
     return;
   }
   Enemy en;
   if (targets.containsKey(e.getName())) {
     en = (Enemy) targets.get(e.getName());
   } else {
     en = new Enemy();
     targets.put(e.getName(), en);
   }
   // the next line gets the absolute bearing to the point where the bot is
   double absbearing_rad = (getHeadingRadians() + e.getBearingRadians()) % (2 * PI);
   // this section sets all the information about our target
   en.name = e.getName();
   double h = normaliseBearing(e.getHeadingRadians() - en.heading);
   h = h / (getTime() - en.ctime);
   en.changehead = h;
   en.x = getX() + Math.sin(absbearing_rad) * e.getDistance(); // works out
   // the x
   // coordinate
   // of where
   // the
   // target is
   en.y = getY() + Math.cos(absbearing_rad) * e.getDistance(); // works out
   // the y
   // coordinate
   // of where
   // the
   // target is
   en.bearing = e.getBearingRadians();
   en.heading = e.getHeadingRadians();
   en.ctime = getTime(); // game time at which this scan was produced
   en.speed = e.getVelocity();
   en.distance = e.getDistance();
   en.live = true;
   if ((en.distance < target.distance) || (target.live == false)) {
     target = en;
   }
 }
コード例 #8
0
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {
    /**
     * ScannedRobotEvent не содержит в себе явно положения противника, однако, его легко вычислить,
     * зная направление своего корпуса, беаринг (по сути угол относительный чего-то, в данном случае
     * относительно корпуса) и расстояние до противника
     */

    // абсолютный угол до противника
    final double alphaToEnemy = getHeadingRadians() + event.getBearingRadians();

    // а далее элементарная геометрия
    enemyX = getX() + Math.sin(alphaToEnemy) * event.getDistance();
    enemyY = getY() + Math.cos(alphaToEnemy) * event.getDistance();
  }
コード例 #9
0
ファイル: VertiMicro.java プロジェクト: PEZ/Bots
  public void onScannedRobot(ScannedRobotEvent e) {
    oldRobotLocation.setLocation(robotLocation);
    robotLocation.setLocation(getX(), getY());
    enemyAbsoluteBearing = getHeadingRadians() + e.getBearingRadians();
    enemyDistance = e.getDistance();
    oldEnemyLocation.setLocation(enemyLocation);
    toLocation(enemyAbsoluteBearing, enemyDistance, robotLocation, enemyLocation);

    deltaBearing =
        Utils.normalRelativeAngle(
            absoluteBearing(oldRobotLocation, enemyLocation)
                - absoluteBearing(oldRobotLocation, oldEnemyLocation));

    currentAimFactors =
        aimFactors[aimDirectionSegment()][
            Math.min(
                (int) (enemyDistance / (getBattleFieldWidth() / DISTANCE_SEGMENTS)),
                DISTANCE_SEGMENTS - 1)][
            Math.min(
                (int) (enemyLocation.getY() / (getBattleFieldHeight() / VERTICAL_SEGMENTS)),
                VERTICAL_SEGMENTS - 1)];

    setTurnGunRightRadians(
        Utils.normalRelativeAngle(
            enemyAbsoluteBearing
                + maxEnemyBearing * sign(deltaBearing) * mostVisitedFactor()
                - getGunHeadingRadians()));

    if (getEnergy() > 3.1) {
      Bullet bullet = setFireBullet(3);
      if (bullet != null) {
        Wave wave = new Wave();
        wave.wTime = getTime();
        wave.bearingDelta = deltaBearing;
        wave.oldRLocation.setLocation(robotLocation);
        wave.oldELocation.setLocation(enemyLocation);
        wave.wAimFactors = currentAimFactors;
        addCustomEvent(wave);
      }
    }

    setAhead(getY() > enemyLocation.getY() ? -50 : 50);

    setTurnRadarRightRadians(
        Utils.normalRelativeAngle(enemyAbsoluteBearing - getRadarHeadingRadians()) * 2);
  }
コード例 #10
0
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {
    double absoluteBearing = robot.getHeadingRadians() + event.getBearingRadians();
    lastTurnGunRadiansDiff =
        robocode.util.Utils.normalRelativeAngle(absoluteBearing - robot.getGunHeadingRadians());
    robot.setTurnGunRightRadians(lastTurnGunRadiansDiff);

    double MAX_DIST = 1000;
    double dist = Math.min(MAX_DIST, event.getDistance());
    double multi = ((MAX_DIST - dist) / MAX_DIST);
    double firePower = multi * Rules.MAX_BULLET_POWER;
    firePower = Math.max(Rules.MIN_BULLET_POWER, firePower);

    //		System.out.println(String.format("dist: %f, multi: %f, fire: %f", dist, multi, firePower));

    robot.setFire(firePower);
  }
コード例 #11
0
ファイル: Bosilka.java プロジェクト: danione/elsys-homeworks
  public void onScannedRobot(ScannedRobotEvent e) {
    double absBearing = e.getBearingRadians() + getHeadingRadians();
    setTurnRadarRightRadians(
        FACTOR * robocode.util.Utils.normalRelativeAngle(absBearing - getRadarHeadingRadians()));
    aceInTheHole(e);
    if (getOthers() > 10) {

      doCircling(e);
      wallSmoothing(absBearing);

    } else if (getOthers() < 10 && getOthers() > 1) {
      doStraffing(e);
      wallSmoothing(absBearing);
    } else if (getOthers() == 1) {
      seekAndDestroy(e);
      wallSmoothing(absBearing);
    }
  }
コード例 #12
0
ファイル: RaikoGun.java プロジェクト: bsdmkx/jdevs-robocode
  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);
  }
コード例 #13
0
  /** onScannedRobot: What to do when you see another robot */
  public void onScannedRobot(ScannedRobotEvent e) {
    System.out.println("START at : " + getTime() + " onScannedRobot----------------------------");
    String nnn = e.getName();
    System.out.println("scan " + nnn);
    double eneX =
        getX() + Math.sin(e.getBearingRadians() + Math.toRadians(getHeading())) * e.getDistance();
    double eneY =
        getY() + Math.cos(e.getBearingRadians() + Math.toRadians(getHeading())) * e.getDistance();
    Enemy_info enem = null;
    if (!isTeammate(nnn)) {
      // 味方への情報送信
      try {
        broadcastMessage(
            nnn
                + ", "
                + e.getBearing()
                + ", "
                + e.getBearingRadians()
                + ", "
                + e.getDistance()
                + ", "
                + e.getEnergy()
                + ", "
                + e.getHeading()
                + ", "
                + e.getHeadingRadians()
                + ", "
                + e.getVelocity()
                + ", "
                + eneX
                + ", "
                + eneY);
      } catch (IOException ignored) {
      }
      // スキャンした車両がLocal敵リストにいるかどうかのフラグ
      boolean flag = false;
      System.out.println("send scanned info");
      // スキャンした敵がLocal敵リストの中に存在するか
      for (Enemy_info temp : enes) {
        if (nnn.equals(temp.get_en_name())) {
          flag = true;
          enem = temp;
          // Local敵リストのアップデート
          temp.updateInformation(
              e.getBearing(),
              e.getBearingRadians(),
              e.getDistance(),
              e.getEnergy(),
              e.getHeading(),
              e.getHeadingRadians(),
              e.getVelocity(),
              eneX,
              eneY);
          System.out.println("	update scanned Info");
        }
      }
      // スキャンした敵がLocal敵リストの中に存在しない場合
      if (!flag) {
        // Local敵リストに新規追加
        enem =
            new Enemy_info(
                nnn,
                e.getBearing(),
                e.getBearingRadians(),
                e.getDistance(),
                e.getEnergy(),
                e.getHeading(),
                e.getHeadingRadians(),
                e.getVelocity(),
                eneX,
                eneY);
        enes.add(enem);
        System.out.println("	add scanned info");
      }
      if (enemy_detected == false) {
        // 共通の敵が設定されていない場合
        enemy_detected = true;
        target_enemy = enem;
        try {
          broadcastMessage("Kill , " + target_enemy.get_en_name() + ", !!");
        } catch (IOException ignored) {
        }
      }

      if (enemy_detected == true) {
        try {
          double enemyX = target_enemy.get_en_expX();
          double enemyY = target_enemy.get_en_expY();
          setTurnRadarLeftRadians(getRadarTurnRemainingRadians());

          System.out.println("abs : eX " + enemyX + " : " + "eY " + enemyY);

          // 共通の敵が設定されている場合
          double enemyBearing = Math.atan((enemyX - getX()) / (enemyY - getY()));
          // if(enemyBearing<0){
          // 	System.out.println("change");
          // 	enemyBearing = Math.PI*2 + enemyBearing;
          // }else if (enemyBearing < Math.PI){

          // }
          // System.out.println("atan " + Math.atan((eneY-getY())/(eneX-getX())));
          // System.out.println("atan1 " + Math.atan((eneX-getX())/(eneY-getY())));
          // System.out.println("trueeee " + (e.getBearingRadians() + this.getHeadingRadians()));
          System.out.println(
              "enerad"
                  + enemyBearing
                  + " ?= "
                  + "enemyBearing "
                  + (this.getHeadingRadians() + e.getBearingRadians()));
          System.out.println(enemyBearing + Math.PI);
          double enemyHeading = target_enemy.get_en_heading(); // 敵の向き
          System.out.println("enemy heading:" + enemyHeading);
          // double enemyBearing = this.getHeadingRadians() +
          // target_enemy.get_en_bearingRadians();// 自分と敵の角度

          // double enemyX = target_enemy.get_en_distance() * Math.sin(enemyBearing);
          // double enemyY = target_enemy.get_en_distance() * Math.cos(enemyBearing);

          enemyX = enemyX - getX();
          enemyY = enemyY - getY();
          System.out.println("Relative : eX " + enemyX + " : " + "eY " + enemyY);

          double battlefieldWidh = getBattleFieldWidth(); // フィールド幅
          double battlefieldHeight = getBattleFieldHeight(); // フィールド高さ

          boolean isHeadingToCenter = (int) enemyHeading % 90 == 0; // 中心を向いている
          boolean isOnWall =
              nearlyEquals(enemyX, 18)
                  || nearlyEquals(enemyX + 18, battlefieldWidh)
                  || nearlyEquals(enemyY, 18)
                  || nearlyEquals(enemyY + 18, battlefieldHeight); // 壁に張り付いている

          // 中心を向いている&&壁際にいる(=Walls)なら射撃
          if (isHeadingToCenter && isOnWall) {
            System.out.println("Walls!!");
          }

          double dis = 0;
          double heading = lastEnemyHeading;
          do {
            dis += Rules.getBulletSpeed(power);
            heading += target_enemy.get_en_headingRadians() - lastEnemyHeading;
            enemyX += target_enemy.get_en_velocity() * Math.sin(heading);
            enemyY += target_enemy.get_en_velocity() * Math.cos(heading);
          } while (dis < Point2D.distance(0, 0, enemyX, enemyY)); //

          // 相対角度に変換した上で砲塔の向きを変える
          setTurnGunRightRadians(
              Utils.normalRelativeAngle(Math.atan2(enemyX, enemyY) - getGunHeadingRadians()));
          setFire(power);
          // lastEnemyHeading = e.getHeadingRadians();
          lastEnemyHeading = target_enemy.get_en_headingRadians();
          System.out.println("lastEnemyHeading " + e.getHeadingRadians());
          System.out.println(lastEnemyHeading);

          // 敵の居る方向へターンする
          // setTurnRightRadians(e.getBearingRadians());
          setTurnRightRadians(enemyBearing - this.getHeadingRadians());
          System.out.println("setTurnRightRadians " + e.getBearingRadians());
          System.out.println(enemyBearing - this.getHeadingRadians());

          // 前進する
          setAhead(moveAmount);
        } catch (NullPointerException ee) {
          System.out.println("NullPointerException");
          System.out.println(target_enemy);
        }
      }
    }

    System.out.println("enemy_detected = " + enemy_detected);
    System.out.println("target is " + target_enemy.get_en_name());
    System.out.println(target_enemy.get_en_expX() + " " + target_enemy.get_en_expY());
    System.out.println("END at : " + getTime() + " onScannedRobot----------------------------");
  }
コード例 #14
-1
ファイル: Bosilka.java プロジェクト: danione/elsys-homeworks
  public void aceInTheHole(ScannedRobotEvent e) {
    double bulletPower = Math.min(3.0, getEnergy());
    double myX = getX();
    double myY = getY();
    double absoluteBearing = getHeadingRadians() + e.getBearingRadians();
    double enemyX = getX() + e.getDistance() * Math.sin(absoluteBearing);
    double enemyY = getY() + e.getDistance() * Math.cos(absoluteBearing);
    double enemyHeading = e.getHeadingRadians();
    double enemyVelocity = e.getVelocity();

    double deltaTime = 0;
    double battleFieldHeight = getBattleFieldHeight(), battleFieldWidth = getBattleFieldWidth();
    double predictedX = enemyX, predictedY = enemyY;
    while ((++deltaTime) * (20.0 - 3.0 * bulletPower)
        < Point2D.Double.distance(myX, myY, predictedX, predictedY)) {
      predictedX += Math.sin(enemyHeading) * enemyVelocity;
      predictedY += Math.cos(enemyHeading) * enemyVelocity;
      if (predictedX < 18.0
          || predictedY < 18.0
          || predictedX > battleFieldWidth - 18.0
          || predictedY > battleFieldHeight - 18.0) {
        predictedX = Math.min(Math.max(18.0, predictedX), battleFieldWidth - 18.0);
        predictedY = Math.min(Math.max(18.0, predictedY), battleFieldHeight - 18.0);
        break;
      }
    }
    double theta = Utils.normalAbsoluteAngle(Math.atan2(predictedX - getX(), predictedY - getY()));

    setTurnRadarRightRadians(Utils.normalRelativeAngle(absoluteBearing - getRadarHeadingRadians()));
    setTurnGunRightRadians(Utils.normalRelativeAngle(theta - getGunHeadingRadians()));
    fire(bulletPower);
  }