Advertisement
ConorB4

Untitled

Oct 12th, 2015
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. package sample;
  2.  
  3. import robocode.HitRobotEvent;
  4. import robocode.Robot;
  5. import robocode.ScannedRobotEvent;
  6.  
  7. import java.awt.*;
  8.  
  9. public class Conor extends Robot {
  10.  
  11.     double moveAmount; // How much to move
  12.  
  13.     public void run() {
  14.         // Set colors
  15.         setBodyColor(Color.green);
  16.         setGunColor(Color.white);
  17.         setRadarColor(Color.white);
  18.         setBulletColor(Color.green);
  19.         setScanColor(Color.green);
  20.  
  21.         // Initialize moveAmount to the maximum possible for this battlefield.
  22.         moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight());
  23.  
  24.         turnLeft(getHeading() % 90);
  25.         ahead(moveAmount);
  26.  
  27.         turnGunRight(90);
  28.         turnRight(90);
  29.  
  30.         while (true) {
  31.             if (getRandomBoolean()) {
  32.                 goRight();
  33.             }
  34.             else goLeft();
  35.         }
  36.     }
  37.    
  38.     public void goRight() {
  39.    
  40.         turnGunRight(360);
  41.         ahead(moveAmount/4);
  42.  
  43.     }
  44.    
  45.     public void goLeft() {
  46.  
  47.         turnGunRight(360);
  48.         back(moveAmount/4);
  49.  
  50.     }
  51.    
  52.     public boolean getRandomBoolean() {
  53.        
  54.         return Math.random() < 0.5;
  55.  
  56.     }
  57.    
  58.  
  59.     public void onHitRobot(HitRobotEvent e) {
  60.         turnRight(90);
  61.         back(moveAmount);
  62.     }
  63.  
  64.     public void onScannedRobot(ScannedRobotEvent e) {
  65.         fire(3);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement