Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. package period2;
  2. import robocode.*;
  3. import java.awt.Color;
  4.  
  5. // API help : https://robocode.sourceforge.io/docs/robocode/robocode/Robot.html
  6.  
  7. /**
  8. * AhmadAdam - a robot by (Adam Ahmad)
  9. */
  10. public class AhmadAdam extends Robot
  11. {
  12. /**
  13. * run: AhmadAdam's default behavior
  14. */
  15. public void run() {
  16. setAdjustRadarForRobotTurn(true);
  17. setAdjustGunForRobotTurn(true);
  18. setAdjustRadarForGunTurn(true);
  19. setBodyColor(new Color(255, 209, 26));
  20. setGunColor(new Color(0, 0, 0));
  21. setRadarColor(new Color(0, 0, 0));
  22. setBulletColor(new Color(255, 255, 255));
  23. setScanColor(Color.red);
  24.  
  25. while(true) {
  26. // Replace the next 4 lines with any behavior you would like
  27. turnRadarRight(45);
  28. }
  29. }
  30.  
  31. /**
  32. * onScannedRobot: What to do when you see another robot
  33. */
  34. public void onScannedRobot(ScannedRobotEvent e) {
  35. // Replace the next line with any behavior you would like
  36. double gunDist = getHeading() + e.getBearing() - getGunHeading();
  37. double radarDist = getHeading() + e.getBearing() - getRadarHeading();
  38. turnRadarRight(efficientAngle(radarDist));
  39. turnGunRight(efficientAngle(gunDist));
  40. double distance = e.getDistance();
  41.  
  42. if(distance <= 40){
  43. fire(3);
  44. }
  45. else if(distance > 40 && distance <= 150){
  46. fire(2);
  47. }
  48. else {
  49. fire(1);
  50. }
  51. scan();
  52. }
  53.  
  54. /**
  55. * onHitByBullet: What to do when you're hit by a bullet
  56. */
  57. public void onHitByBullet(HitByBulletEvent e) {
  58. // Replace the next line with any behavior you would like
  59. ahead((int)(80 * Math.random())+40);
  60. }
  61.  
  62. /**
  63. * onHitWall: What to do when you hit a wall
  64. */
  65. public void onHitWall(HitWallEvent e) {
  66. turnLeft(90-e.getBearing());
  67. }
  68.  
  69. public double efficientAngle(double angle){
  70. while (angle > 180) angle -= 360;
  71. while (angle < -180) angle += 360;
  72. return angle;
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement