Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package patel_mister;
  2. import robocode.HitRobotEvent;
  3. import robocode.Robot;
  4. import robocode.ScannedRobotEvent;
  5.  
  6. public class Dodge_Walls_V2 extends Robot
  7. {
  8.  
  9. boolean peek;
  10. double moveAmount;
  11.  
  12. public void walls(){
  13. moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
  14.  
  15. peek = false;
  16.  
  17. turnLeft(getHeading() % 90);
  18. ahead(moveAmount);
  19.  
  20. peek = true;
  21. turnGunRight(90);
  22. turnRight(90);
  23.  
  24. while (getOthers() >= 5) {
  25. peek = true;
  26. ahead(moveAmount);
  27. turnRight(90);
  28. turnRight(-90);
  29. peek = false;
  30. turnRight(90);
  31. }
  32. }
  33.  
  34. public void dodge(){
  35. getHeading();
  36. turnLeft(getHeading());
  37. ahead(1800);
  38. back(700);
  39. while (getOthers() < 5)
  40. ahead(700);
  41. turnLeft(90);
  42. ahead(700);
  43. turnLeft(90);
  44. }
  45.  
  46. public void run() {
  47. if(getOthers() >= 5)
  48. walls();
  49. else if(getOthers() < 5)
  50. dodge();
  51. }
  52.  
  53. public void onScannedRobot(ScannedRobotEvent e) {
  54. if(getEnergy() > 100)
  55. {
  56. fire(3);
  57. }
  58. if(getEnergy() > 50)
  59. {
  60. fire(2);
  61. }
  62. else
  63. {
  64. fire(1);
  65. }
  66. }
  67.  
  68. public void onHitRobot(HitRobotEvent e) {
  69. if (e.getBearing() > -90 && e.getBearing() < 90) {
  70. back(100);
  71. }
  72. else {
  73. ahead(100);
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement