SHARE
TWEET

Cymba v0.1

fire219 Dec 29th, 2014 179 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fire219;
  2. import robocode.*;
  3. import robocode.util.*;
  4. //import java.awt.Color;
  5.  
  6. /**
  7.  * Cymba - a robot by fire219
  8.  */
  9. public class Cymba extends AdvancedRobot
  10. {
  11.         int moveDirection = 1; //0 = left, 1 = right  
  12.         int turnmodifier = 0;
  13.         public void run() {
  14.            
  15.            setAdjustRadarForRobotTurn(true);
  16.            setAdjustRadarForGunTurn(true);
  17.            do {
  18.                // ...
  19.               // Turn the radar if we have no more turn, starts it if it stops and at the start of round
  20.               if ( getRadarTurnRemaining() == 0.0 )
  21.                   setTurnRadarRightRadians( Double.POSITIVE_INFINITY );
  22.                   execute();
  23.                   setAhead(15 * moveDirection);
  24.          } while ( true );
  25.        
  26.           // ...
  27.         }
  28.  
  29.         public void onScannedRobot(ScannedRobotEvent e) {
  30.            // ...
  31.  
  32.            // Absolute angle towards target
  33.            double angleToEnemy = getHeadingRadians() + e.getBearingRadians();
  34.  
  35.           // Subtract current radar heading to get the turn required to face the enemy, be sure it is normalized
  36.            double radarTurn = Utils.normalRelativeAngle( angleToEnemy - getRadarHeadingRadians() );
  37.  
  38.             // Distance we want to scan from middle of enemy to either side
  39.            // The 36.0 is how many units from the center of the enemy robot it scans.
  40.            double extraTurn = Math.min( Math.atan( 36.0 / e.getDistance() ), Rules.RADAR_TURN_RATE_RADIANS );
  41.  
  42.           // Adjust the radar turn so it goes that much further in the direction it is going to turn
  43.            // Basically if we were going to turn it left, turn it even more left, if right, turn more right.
  44.            // This allows us to overshoot our enemy so that we get a good sweep that will not slip.
  45.           radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);
  46.  
  47.           //Turn the radar
  48.           setTurnRadarRightRadians(radarTurn);
  49.          // setTurnGunRightRadians(radarTurn);
  50.           setTurnGunRight(getHeading() - getGunHeading() + e.getBearing());
  51.         // always square off against our enemy
  52.                 if (e.getDistance() < 100) {
  53.                         out.println("too close!" + e.getDistance());
  54.                         if (moveDirection == 1) {
  55.                                 turnmodifier = 20;
  56.                         }
  57.                         if (moveDirection == -1) {
  58.                                 turnmodifier = -20;
  59.                         }                      
  60.                 }
  61.                 if (e.getDistance() > 100) {
  62.                         turnmodifier = 0;
  63.                 }
  64.                 setTurnRight(e.getBearing() + 90);
  65.         // strafe by changing direction every 20 ticks 
  66.                 if (Math.random() > .9999) {
  67.                         out.println("Changing dir");
  68.                         moveDirection = moveDirection * -1;    
  69.                 }      
  70.                 if (Math.random() > .9) {
  71.                         fire(3);
  72.                 }      
  73.     // ...
  74. }
  75.  
  76.  
  77.         public void onHitByBullet(HitByBulletEvent e) {
  78.  
  79.                 execute();
  80.         }
  81.        
  82.  
  83.         public void onHitWall(HitWallEvent e) {
  84.                 moveDirection = moveDirection * -1;    
  85.                 setAhead(150 * moveDirection);
  86.                 execute();
  87.        
  88.         }      
  89. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top