コード例 #1
0
ファイル: Ninjar.java プロジェクト: liuriloami/robocode
 public void dodgeOnScanned(ScannedRobotEvent e) {
   setTurnRight(e.getBearing() + 90 - 30 * movementDirection);
   double changeInEnergy = previousEnergy - e.getEnergy();
   if (changeInEnergy > 0 && changeInEnergy <= 3) {
     movementDirection = -movementDirection;
     setAhead((e.getDistance() / 4 + 25) * movementDirection);
   }
   gunDirection = -gunDirection;
   setTurnGunRight(99999 * gunDirection);
   setFire(2);
   previousEnergy = e.getEnergy();
   execute();
 }
コード例 #2
0
ファイル: Bosilka.java プロジェクト: danione/elsys-homeworks
 public void seekAndDestroy(ScannedRobotEvent e) {
   setTurnRight(e.getBearing() + 90 - 30 * moveDirection);
   double changeInEnergy = previousEnergy - e.getEnergy();
   if (changeInEnergy > 0 && changeInEnergy <= 3) {
     moveDirection = -moveDirection;
     setAhead((e.getDistance() / 4 + 25) * moveDirection);
   }
 }
コード例 #3
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);
 }
コード例 #4
0
  /**
   * onScannedRobot: What to do when you see another robot<br>
   * The action performed here depends on the current_mode variable.<br>
   * Currently if the robot that was scanned is weak and helpless our robot takes a shot at it,<br>
   * Otherwise only fire depending on the distance the other robot was away from our robot.
   *
   * @param e , A ScannedRobotEvent of the robot that was scanned.
   */
  public void onScannedRobot(ScannedRobotEvent e) {
    timeRobotLastSeen = getTime();
    // if the robot is performing a 360 sweep only fire if it sees a
    // disabled/weak robot
    if ((current_mode == SWEEP_MODE) && (e.getEnergy() < 1)) {
      fire(1);
    } else fireBasedOnDistance(e.getDistance(), e.getVelocity());

    if (e.getDistance() <= INNER_PERIMETER) current_mode = CLOSE_COMBAT_MODE;
    else current_mode = STANDARD_COMBAT_MODE;

    printMode();
  }
コード例 #5
0
 public void update(ScannedRobotEvent sre, double self_h, double self_x, double self_y) {
   if (sre.getName().equals(name)) {
     tc.update(
         sre.getTime(),
         sre.getEnergy(),
         tm.predict_gun_heading(sre, tc),
         tm.predict_gun_heat(sre, tc),
         correct_angle(sre.getHeadingRadians()),
         sre.getVelocity(),
         getX(sre, self_h, self_x),
         getY(sre, self_h, self_y));
     mm.update(sre);
   }
 }
コード例 #6
0
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {

    info = new EnemyInfo(en, getTime());
    Enemy enemy = enemies.get(event.getName());

    if (enemy == null) {
      enemy = new Enemy(event, this);
      enemies.put(enemy.getName(), enemy);
      storages.put(enemy.getName(), new VisitCountStorage());
    }

    if (getTime() - enemy.getLastUpdated() < Costants.TIME_THRESHOLD
        && (enemy.getEnergy() - event.getEnergy()) > 0.
        && (enemy.getEnergy() - event.getEnergy()) < 3.1) {

      GBulletFiredEvent gBulletFiredEvent = new GBulletFiredEvent();
      gBulletFiredEvent.setFiringRobot(enemy);
      gBulletFiredEvent.setEnergy(enemy.getEnergy() - event.getEnergy());
      gBulletFiredEvent.setVelocity(20 - 3 * (enemy.getEnergy() - event.getEnergy()));
      gBulletFiredEvent.setFiringTime(getTime() - 1);
      gBulletFiredEvent.setFiringPosition(enemy.getPosition()); // TODO this or the updated one?
      gBulletFiredEvent.setTargetPosition(new Point2D.Double(getX(), getY()));
      org.pattern.utils.Utils.setWaveMAE(gBulletFiredEvent, getHeading(), getVelocity(), this);
      waves.addWave(gBulletFiredEvent);
    }

    enemy.updateEnemy(event, this);
    enemies.put(enemy.getName(), enemy);

    if (!meleeRadar) {
      Double radarTurn = getHeading() - getRadarHeading() + enemy.getBearing();
      setTurnRadarRight(Utils.normalRelativeAngleDegrees(radarTurn));
    }

    doShooting();
  }
コード例 #7
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;
 }
コード例 #8
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);
  }
コード例 #9
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----------------------------");
  }
コード例 #10
0
ファイル: V.java プロジェクト: tanczosm/robocode
  public void onScannedRobot(ScannedRobotEvent e) {

    if (_radarScanner._lastScan == null) {
      _radarScanner._lastScan = e;
      return;
    }

    double enemyHeading = getHeadingRadians() + _radarScanner.nme.bearingRadians;
    Situation s = _radarScanner.processScanEvent(e, true);

    try {
      double bulletPower = _radarScanner._oppEnergy - e.getEnergy();
      if (bulletPower < 3.01
          && (bulletPower > 0.09
              || (bulletPower > 0 && (s.WallTriesForward > 5 && s.WallTriesBack > 5)))
          && _radarScanner._surfDirections.size() > 2) {
        EnemyWave ew = new EnemyWave();
        ew.fireTime = getTime() - 1;
        ew.bulletPower = bulletPower;
        ew.bulletVelocity = CTUtils.bulletVelocity(bulletPower);
        ew.distanceTraveled = CTUtils.bulletVelocity(bulletPower);
        ew.direction = ((Integer) _radarScanner._surfDirections.get(2)).intValue();
        ew.directAngle = ((Double) _radarScanner._surfAbsBearings.get(2)).doubleValue();
        ew.fireLocation =
            (Point2D.Double)
                (_radarScanner.nme.lastlocation == null
                    ? _radarScanner.nme.location.clone()
                    : _radarScanner.nme.lastlocation
                        .clone()); // _radarScanner.nme.location.clone(); // last tick
        ew.playerDistance = _radarScanner.nme.location.distance(_radarScanner._myLocation);
        ew.maxEscapeAngle = CTUtils.maxEscapeAngle(ew.bulletVelocity);
        ew.waveGuessFactors =
            _surfStats[(int) Math.min((_radarScanner._lastScan.getDistance() + 50) / 200, 3)][
                (int) (CTUtils.clamp((Math.abs(_radarScanner._lastLatVel) + 1) / 2, 0, 4))];
        _enemyWaves.add(ew);
        // (int)((s.WallTriesBack+s.WallTriesForward)) (0..2)
        _radarScanner.nme.lastBulletPower = bulletPower;
      }

      if (bulletPower >= 0 && bulletPower < 3.01) _radarScanner.nme.lastShotTime = getTime();

    } catch (ArrayIndexOutOfBoundsException em) {
      System.out.println(em.getMessage());
    }

    _radarScanner._oppEnergy = _radarScanner._lastScan.getEnergy();

    // update after EnemyWave detection, because that needs the previous
    // enemy location as the source of the wave
    _radarScanner.nme.location =
        CTUtils.project(
            _radarScanner._myLocation,
            (Double) _radarScanner._surfAbsBearings.get(0) - Math.PI,
            e.getDistance());

    updateWaves();

    _targeting.selectFiringPower(_radarScanner.nme.distance);
    _targeting.process(s);

    _radarScanner.postProcessScanEvent(e);
  }