コード例 #1
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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;
    }
  }
コード例 #2
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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) {
    }
  }
コード例 #3
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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;
  }
コード例 #4
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void processWave(Wave w) {
    GuessFactorWindowSet gfWindow = w.guessFactorWindow(ScanLog.myLocation());
    int gfBin = w.guessFactorIndex(gfWindow.guessFactor);
    int gfBinLow = w.guessFactorIndex(gfWindow.guessFactorLow);
    int gfBinHigh = w.guessFactorIndex(gfWindow.guessFactorHigh);
    BotScan enemyScan = w.targetScan.getInverseScan();

    for (int x = 0; x < _waveRegisters.size(); x++) {
      WaveRegister wr = (WaveRegister) _waveRegisters.get(x);

      wr.registerWaveHit(
          w.targetScan,
          enemyScan,
          w.bulletPower,
          gfWindow.guessFactor,
          gfBin,
          gfBinLow,
          gfBinHigh,
          w.firingWave,
          w.fireTime,
          w.orientation,
          w.escapeAngleRange());
    }

    w.processedWaveBreak = true;
  }
コード例 #5
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void reset(AdvancedRobot robot) {
    _robot = robot;
    _waves.clear();
    _renderables.clear();
    _weightedEnemyShotsFiredThisRound = 0;
    _weightedEnemyShotsHitThisRound = 0;

    ScanLog.reset();
  }
コード例 #6
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void onBulletHitBullet(BulletHitBulletEvent e) {
    ScanLog.onBulletHitBullet(e);

    processBulletReturnFiringWave(e.getHitBullet(), e.getTime());

    _weightedEnemyShotsFired--;
    _weightedEnemyShotsFiredThisRound--;
    //        	(firingDistance
    //        		/ DUtils.bulletVelocity(e.getBullet().getPower()))
    //        	/ (TYPICAL_DISTANCE / POWER_TWO_BULLET_VELOCITY);
  }
コード例 #7
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void onHitByBullet(HitByBulletEvent e) {
    ScanLog.onHitByBullet(e);

    Wave hitWave = processBulletReturnFiringWave(e.getBullet(), e.getTime());

    if (hitWave != NO_WAVE_FOUND) {
      double thisHit =
          (hitWave.targetScan.getDistance() / TYPICAL_DISTANCE)
              * (hitWave.escapeAngleRange() / TYPICAL_ESCAPE_RANGE);
      _weightedEnemyShotsHit += thisHit;
      _weightedEnemyShotsHitThisRound += thisHit;
    }
  }
コード例 #8
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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;
  }
コード例 #9
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();
  }
コード例 #10
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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));
    }
  }
コード例 #11
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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);
        }
      }
    }
  }
コード例 #12
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
 public void evaluateWallStick() {
   _wallStick = (ScanLog.enemyIsRammer()) ? RAMMER_WALL_STICK : DEFAULT_WALL_STICK;
 }
コード例 #13
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void onWin(WinEvent e) {
    ScanLog.onWin(e);

    roundOver();
  }
コード例 #14
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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;
  }
コード例 #15
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  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;
  }
コード例 #16
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
  public void onDeath(DeathEvent e) {
    ScanLog.onDeath(e);

    roundOver();
  }
コード例 #17
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
 public void onBulletMissed(BulletMissedEvent e) {
   ScanLog.onBulletMissed(e);
 }
コード例 #18
0
ファイル: DookiCape.java プロジェクト: louisccc/QRobot
 public void onBulletHit(BulletHitEvent e) {
   ScanLog.onBulletHit(e);
 }