Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package man;
- import robocode.*;
- import static robocode.util.Utils.normalRelativeAngleDegrees;
- public class Pai_de_Todos extends AdvancedRobot {
- int moveDirection=0;
- public void run() {
- do {
- ahead(100);
- turnGunRight(360);
- back(100);
- turnGunRight(360);
- // Check for new targets.
- // Only necessary for Narrow Lock because sometimes our radar is already
- // pointed at the enemy and our onScannedRobot code doesn't end up telling
- // it to turn, so the system doesn't automatically call scan() for us
- // [see the javadocs for scan()].
- scan();
- } while (true);
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- double absoluteBearing = getHeading() + e.getBearing();
- double bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading());
- // If it's close enough, fire!
- if (Math.abs(bearingFromGun) <= 3) {
- turnGunRight(bearingFromGun);
- // We check gun heat here, because calling fire()
- // uses a turn, which could cause us to lose track
- // of the other robot.
- if (getGunHeat() == 0) {
- fire(Math.min(3 - Math.abs(bearingFromGun), getEnergy() - .1));
- }
- } // otherwise just set the gun to turn.
- // Note: This will have no effect until we call scan()
- else {
- turnGunRight(bearingFromGun);
- }
- // Generates another scan event if we see a robot.
- // We only need to call this if the gun (and therefore radar)
- // are not turning. Otherwise, scan is called automatically.
- if (bearingFromGun == 0) {
- scan();
- }
- }
- public void onBulletHit(BulletHitEvent e) {
- // switch directions if we've stopped
- if (getVelocity() == 0)
- moveDirection *= -1;
- // circle our enemy
- setTurnRight(90);
- setAhead(1000 * moveDirection);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement