Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. package man;
  2. import robocode.*;
  3. import static robocode.util.Utils.normalRelativeAngleDegrees;
  4.  
  5. public class Pai_de_Todos extends AdvancedRobot {
  6.  
  7. int moveDirection=0;
  8.  
  9. public void run() {
  10. do {
  11. ahead(100);
  12. turnGunRight(360);
  13. back(100);
  14. turnGunRight(360);
  15. // Check for new targets.
  16. // Only necessary for Narrow Lock because sometimes our radar is already
  17. // pointed at the enemy and our onScannedRobot code doesn't end up telling
  18. // it to turn, so the system doesn't automatically call scan() for us
  19. // [see the javadocs for scan()].
  20. scan();
  21. } while (true);
  22. }
  23.  
  24. public void onScannedRobot(ScannedRobotEvent e) {
  25.  
  26. double absoluteBearing = getHeading() + e.getBearing();
  27. double bearingFromGun = normalRelativeAngleDegrees(absoluteBearing - getGunHeading());
  28.  
  29. // If it's close enough, fire!
  30. if (Math.abs(bearingFromGun) <= 3) {
  31. turnGunRight(bearingFromGun);
  32. // We check gun heat here, because calling fire()
  33. // uses a turn, which could cause us to lose track
  34. // of the other robot.
  35. if (getGunHeat() == 0) {
  36. fire(Math.min(3 - Math.abs(bearingFromGun), getEnergy() - .1));
  37. }
  38. } // otherwise just set the gun to turn.
  39. // Note: This will have no effect until we call scan()
  40. else {
  41. turnGunRight(bearingFromGun);
  42. }
  43. // Generates another scan event if we see a robot.
  44. // We only need to call this if the gun (and therefore radar)
  45. // are not turning. Otherwise, scan is called automatically.
  46. if (bearingFromGun == 0) {
  47. scan();
  48. }
  49. }
  50.  
  51. public void onBulletHit(BulletHitEvent e) {
  52.  
  53. // switch directions if we've stopped
  54. if (getVelocity() == 0)
  55. moveDirection *= -1;
  56.  
  57. // circle our enemy
  58. setTurnRight(90);
  59. setAhead(1000 * moveDirection);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement