qtinio

boczkowski

Jun 10th, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1.  
  2. package nielegalnaplantacja;
  3.  
  4.  
  5. import robocode.HitByBulletEvent;
  6. import robocode.ScannedRobotEvent;
  7. import robocode.TeamRobot;
  8.  
  9. import java.awt.*;
  10. import java.io.IOException;
  11. import robocode.HitRobotEvent;
  12. import robocode.StatusEvent;
  13. import sampleteam.Point;
  14. import static robocode.util.Utils.normalRelativeAngleDegrees;
  15.  
  16.  
  17. public class LeszekBoczkowski extends TeamRobot {
  18.  
  19. boolean peek;
  20. double moveAmount;
  21.  
  22. public void run() {
  23. // Set the color of this robot containing the RobotColors
  24. setBodyColor(Color.yellow);
  25. setGunColor(Color.yellow);
  26. setRadarColor(Color.white);
  27. setScanColor(Color.yellow);
  28. setBulletColor(Color.white);
  29.  
  30. moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
  31. peek = false;
  32.  
  33. turnLeft(getHeading() % 90);
  34. ahead(moveAmount);
  35. peek = true;
  36. turnGunRight(90);
  37. turnRight(90);
  38. execute();
  39. while (true) {
  40. peek = true;
  41. ahead(moveAmount);
  42. peek = false;
  43. turnRight(90);
  44. execute();
  45. }
  46. }
  47.  
  48. public void onScannedRobot(ScannedRobotEvent e) {
  49. // Don't fire on teammates
  50. if (isTeammate(e.getName())) {
  51. return;
  52. }
  53. // Calculate enemy bearing
  54. double enemyBearing = this.getHeading() + e.getBearing();
  55. double bearingFromGun = normalRelativeAngleDegrees(enemyBearing - getGunHeading());
  56.  
  57. // Calculate enemy's position
  58. double enemyX = getX() + e.getDistance() * Math.sin(Math.toRadians(enemyBearing));
  59. double enemyY = getY() + e.getDistance() * Math.cos(Math.toRadians(enemyBearing));
  60.  
  61. if (Math.abs(bearingFromGun) <= 3) {
  62. turnGunRight(bearingFromGun);
  63. if (getGunHeat() == 0) {
  64. fire(Math.min(3 - Math.abs(bearingFromGun), getEnergy() - .1));
  65. }
  66. }
  67. else {
  68. turnGunRight(bearingFromGun);
  69. }
  70.  
  71. try {
  72. broadcastMessage(new Point(enemyX, enemyY));
  73. } catch (IOException ex) {
  74. out.println("Unable to send order: ");
  75. ex.printStackTrace(out);
  76. }
  77. }
  78.  
  79. public void onStatus( StatusEvent e) {
  80. setTurnRadarRightRadians(Double.POSITIVE_INFINITY);
  81. }
  82.  
  83. public void onHitRobot(HitRobotEvent e) {
  84. if (e.getBearing() > -90 && e.getBearing() < 90) {
  85. back(100);
  86. }
  87. else {
  88. ahead(100);
  89. }
  90. }
  91.  
  92.  
  93.  
  94.  
  95. }
Add Comment
Please, Sign In to add comment