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(); }
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); }
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; }
/** * 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(); }
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(); }
/** * 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()); }
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; }
/** 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(); }
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; } }
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)); } }
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); }
public void onScannedRobot(ScannedRobotEvent event) { scannedDistance = (int) (event.getDistance() + 0.5); scannedEnergy = Math.max(1, (int) (event.getEnergy() + 0.5)); scannedAngle = (int) (Math.toDegrees( Utils.normalAbsoluteAngle(peer.getBodyHeading() + event.getBearingRadians())) + 0.5); scannedBearing = (int) (event.getBearing() + 0.5); scannedHeading = (int) (event.getHeading() + 0.5); scannedVelocity = (int) (event.getVelocity() + 0.5); JuniorRobot.this.onScannedRobot(); }
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(); }
/** Returns the priority of a ScannedRobotEvent. */ public int getScannedRobotEventPriority() { return dummyScannedRobotEvent.getPriority(); }