コード例 #1
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);
 }
コード例 #2
0
  @Override
  public void onScannedRobot(ScannedRobotEvent event) {

    double headingBearing = getHeading() + event.getBearing();
    double bearingFromGun = headingBearing - getGunHeading();
    double bearingFromRadar = headingBearing - getRadarHeading();

    setTurnRight(event.getBearing() + 90);

    if (bearingFromGun <= 4) {
      setTurnGunRight(bearingFromGun);
      setTurnRadarRight(bearingFromRadar);

      if (getEnergy() > 0.2) {
        fire(event.getDistance() / 250);
      }
    } else {
      setTurnGunRight(bearingFromGun);
      setTurnRadarRight(bearingFromRadar);
    }

    if (bearingFromGun == 0) {
      scan();
    }
  }
コード例 #3
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);
 }
コード例 #4
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);
   }
 }
コード例 #5
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();
  }
コード例 #6
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);
 }
コード例 #7
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;
  }
コード例 #8
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();
  }
コード例 #9
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();
 }
コード例 #10
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);
   }
 }
コード例 #11
0
  /**
   * When scanning a robot we need to add it to the collection of scanned objects so it can be used
   * later for updates to the bots movement.
   */
  public void onScannedRobot(ScannedRobotEvent e) {
    double targetBearing = getHeading() + e.getBearing();
    double tmpX = getX() + e.getDistance() * Math.sin(Math.toRadians(targetBearing));
    double tmpY = getY() + e.getDistance() * Math.cos(Math.toRadians(targetBearing));
    String name = e.getName();

    if (name.equals(GOAL_NAME)) {
      foundGoal = true;
    }

    obstacles.put(name, new Enemy(tmpX, tmpY, e.getBearing()));

    setTurnRadarRight(getRadarTurnRemaining());
  }
コード例 #12
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();
  }
コード例 #13
0
 public void enemyPosition(ScannedRobotEvent e, double x, double y) {
   // poll subtargetters for their opinions
   virtualBulletTick++;
   lastEnemyScanTime = owner.getTime();
   // only log it when we actually fire: the enemy may respond to that
   if (owner.shouldFireShot(e)) {
     double bulletPower = e.getDistance() > 500.0 ? 2.0 : 3.0;
     for (int i = 0; i < numVirtualGuns; i++) {
       double angle = targetters[i].target(e, bulletPower);
       VirtualBullet bullet = new VirtualBullet();
       bullet.targetter = i;
       bullet.x = owner.getX();
       bullet.y = owner.getY();
       bullet.velX = Targetting.bulletSpeed(bulletPower) * Math.sin(angle);
       bullet.velY = Targetting.bulletSpeed(bulletPower) * Math.cos(angle);
       bullet.lastUpdateTime = lastEnemyScanTime;
       virtualBullets.add(bullet);
     }
   }
   for (int i = 0; i < numVirtualGuns; i++) {
     targetters[i].enemyPosition(e, x, y);
   }
   enemyX = x;
   enemyY = y;
 }
コード例 #14
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);
  }
コード例 #15
0
ファイル: Bosilka.java プロジェクト: danione/elsys-homeworks
  public void doStraffing(ScannedRobotEvent enemy) {
    setTurnRight((enemy.getBearing() + 90 - (15 * moveDirection)));

    if (getTime() % 20 == 0) {
      moveDirection *= -1;
      setAhead(150 * moveDirection);
    }
  }
コード例 #16
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);
  }
コード例 #17
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;
 }
コード例 #18
0
  /** onScannedRobot: Here's the good stuff */
  @Override
  public void onScannedRobot_(solomon s, ScannedRobotEvent e) {

    // If we have a target, and this isn't it, return immediately
    // so we can get more ScannedRobotEvents.
    if (trackName != null && !e.getName().equals(trackName)) {
      return;
    }

    // If we don't have a target, well, now we do!
    if (trackName == null) {
      trackName = e.getName();
      // out.println("Tracking " + trackName);
    }
    // This is our target.  Reset count (see the run method)
    count = 0;
    // If our target is too far away, turn and move torward it.
    if (e.getDistance() > 150) {
      gunTurnAmt = normalRelativeAngle(e.getBearing() + (s.getHeading() - s.getRadarHeading()));

      s.turnGunRight(gunTurnAmt); // Try changing these to setTurnGunRight,
      s.turnRight(e.getBearing()); // and see how much Tracker improves...
      // (you'll have to make Tracker an AdvancedRobot)
      s.ahead(e.getDistance() - 135);
      return;
    }

    // Our target is close.
    gunTurnAmt = normalRelativeAngle(e.getBearing() + (s.getHeading() - s.getRadarHeading()));
    s.turnGunRight(gunTurnAmt);
    s.fire(3);

    // Our target is too close!  Back up.
    if (e.getDistance() < 100) {
      if (e.getBearing() > -90 && e.getBearing() <= 90) {
        s.back(30);
      } else {
        s.ahead(40);
      }
    }
    s.scan();
  }
コード例 #19
0
ファイル: Ninjar.java プロジェクト: liuriloami/robocode
 public void onScannedRobot(ScannedRobotEvent e) {
   switch (individual) {
     case DODGE:
       dodgeOnScanned(e);
       break;
     default:
       setTurnGunRight(99999);
       setFire(2 / (1 + 0.25 * (e.getDistance() - getBattleFieldWidth())));
       execute();
       break;
   }
 }
コード例 #20
0
  public void onScannedRobot(ScannedRobotEvent e) {

    // track if we have no enemy, the one we found is significantly
    // closer, or we scanned the one we've been tracking.
    if (enemy.none()
        || e.getDistance() < enemy.getDistance() - 70
        || e.getName().equals(enemy.getName())) {

      // track him
      enemy.update(e);

      // if the gun is cool and we're pointed at the target, shoot!
      // Note: we can put the firing code before the turning code
      // because we're testing to see if we're aiming at our enemy
      if (getGunHeat() == 0 && Math.abs(getGunTurnRemaining()) < 10)
        setFire(Math.min(400 / enemy.getDistance(), 3));

      //  calculate gun turn toward enemy
      double turn = getHeading() - getGunHeading() + e.getBearing();
      // normalize the turn to take the shortest path there
      setTurnGunRight(normalizeBearing(turn));
    }
  }
コード例 #21
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();
  }
コード例 #22
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);
  }
コード例 #23
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);
    }
  }
コード例 #24
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void onScannedRobot(ScannedRobotEvent e) {
    ScanLog.onScannedRobot(_robot, e);

    evaluateDistancingControl();
    evaluateWallStick();
    evaluateFlattener();

    boolean realShotFired;
    if (ScanLog.enemyFired(e.getTime())) {
      realShotFired = true;
      _weightedEnemyShotsFired++;
      _weightedEnemyShotsFiredThisRound++;
      //            	(e.getDistance()
      //            		/ DUtils.bulletVelocity(ScanLog.getLastEnemyBulletPower()))
      //            	/ (TYPICAL_DISTANCE / POWER_TWO_BULLET_VELOCITY);
    } else {
      realShotFired = false;
    }

    fireWave(realShotFired ? Wave.FIRING_WAVE : Wave.NON_FIRING_WAVE);
    checkActiveWaves();

    surf();
  }
コード例 #25
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);
  }
コード例 #26
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;
   }
 }
コード例 #27
0
 @Override
 public String toString() {
   return "Hit with bearing " + robot.getBearing() + " at distance " + robot.getDistance();
 }
コード例 #28
0
ファイル: Bosilka.java プロジェクト: danione/elsys-homeworks
 public void doCircling(ScannedRobotEvent enemy) {
   if (getVelocity() == 0) moveDirection *= -1;
   setTurnRight(enemy.getBearing() + 90);
   setAhead(1000 * moveDirection);
 }
コード例 #29
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----------------------------");
  }
コード例 #30
-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);
  }