Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. package nsi;
  2. import robocode.*;
  3. //import java.awt.Color;
  4.  
  5. // API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
  6.  
  7. /**
  8. * Teste - a robot by (your name here)
  9. */
  10. public class NsiDestroyer extends Robot
  11. {
  12. /**
  13. * run: Teste's default behavior
  14. */
  15. public void run() {
  16. // Initialization of the robot should be put here
  17.  
  18. // After trying out your robot, try uncommenting the import at the top,
  19. // and the next line:
  20.  
  21. // setColors(Color.red,Color.blue,Color.green); // body,gun,radar
  22.  
  23. // Robot main loop
  24. while(true){
  25. ahead(100); //Go ahead 100 pixels
  26. turnGunRight(360); //scan
  27. back(75); //Go back 75 pixels
  28. turnGunRight(360); //scan
  29.  
  30. //For each second the robot go ahead 25 pixels.
  31. }
  32. }
  33.  
  34. /**
  35. * onScannedRobot: What to do when you see another robot
  36. */
  37. public void onScannedRobot(ScannedRobotEvent e) {
  38. // Replace the next line with any behavior you would like
  39. double distance = e.getDistance(); //get the distance of the scanned robot
  40. if(distance > 800) //this conditions adjust the fire force according the distance of the scanned robot.
  41. fire(5);
  42. else if(distance > 600 && distance <= 800)
  43. fire(4);
  44. else if(distance > 400 && distance <= 600)
  45. fire(3);
  46. else if(distance > 200 && distance <= 400)
  47. fire(2);
  48. else if(distance < 200)
  49. fire(1);
  50. }
  51.  
  52. /**
  53. * onHitByBullet: What to do when you're hit by a bullet
  54. */
  55. public void onHitByBullet(HitByBulletEvent e) {
  56. // Replace the next line with any behavior you would like
  57. back(10);
  58. }
  59.  
  60. /**
  61. * onHitWall: What to do when you hit a wall
  62. */
  63. public void onHitWall(HitWallEvent e) {
  64. // Replace the next line with any behavior you would like
  65. double bearing = e.getBearing(); //get the bearing of the wall
  66. turnRight(-bearing); //This isn't accurate but release your robot.
  67. ahead(100); //The robot goes away from the wall.
  68. }
  69.  
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement