/** 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(); }
/** * 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 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)); } }