/** onWin: Do a victory dance */ public void onWin(solomon s, WinEvent e) { for (int i = 0; i < 50; i++) { s.turnRight(30); s.turnLeft(30); s.turnRight(36000); } }
/** 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(); }