SHARE
TWEET

cymba v0.5

fire219 Jan 4th, 2015 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fire219.cymba;
  2. import robocode.*;
  3. import robocode.util.*;
  4. //import java.awt.Color;
  5.  
  6. /**
  7.  * Cymba - a robot by fire219
  8.  * version 1-4-15
  9.  * Proving simple is better since 2014
  10.  */
  11. public class Cymba extends AdvancedRobot
  12. {
  13.         int moveDirection = 1; //-1 = left, 1 = right  
  14.         int turnmodifier = 0;
  15.         double targetdist1 = 0;
  16.         double targetingmod = 0;
  17.         double nprand = 0;
  18.         double lastenergy = 0;
  19.         public void run() {
  20.            
  21.            setAdjustRadarForRobotTurn(true);
  22.           // setAdjustRadarForGunTurn(true);
  23.            do {
  24.                // ...
  25.               // Turn the radar if we have no more turn, starts it if it stops and at the start of round
  26.               if ( getRadarTurnRemaining() == 0.0 )
  27.                   setTurnRadarRightRadians( Double.POSITIVE_INFINITY );
  28.                   execute();
  29.                   setAhead(150 * moveDirection);
  30.                   if (Math.random() > .7) {
  31.                         out.println("Changing dir");
  32.                         moveDirection = moveDirection * -1;    
  33.                         }      
  34.                   scan();
  35.          } while ( true );
  36.        
  37.           // ...
  38.         }
  39.  
  40.         public void onScannedRobot(ScannedRobotEvent e) {
  41.            // ...
  42.  
  43.            // Absolute angle towards target
  44.            double angleToEnemy = getHeadingRadians() + e.getBearingRadians();
  45.  
  46.           // Subtract current radar heading to get the turn required to face the enemy, be sure it is normalized
  47.            double radarTurn = Utils.normalRelativeAngle( angleToEnemy - getRadarHeadingRadians() );
  48.  
  49.             // Distance we want to scan from middle of enemy to either side
  50.            // The 36.0 is how many units from the center of the enemy robot it scans.
  51.            double extraTurn = Math.min( Math.atan( 72.0 / e.getDistance() ), Rules.RADAR_TURN_RATE_RADIANS );
  52.  
  53.           // Adjust the radar turn so it goes that much further in the direction it is going to turn
  54.            // Basically if we were going to turn it left, turn it even more left, if right, turn more right.
  55.            // This allows us to overshoot our enemy so that we get a good sweep that will not slip.
  56.           radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);
  57.  
  58.           //Turn the radar
  59.           setTurnRadarRightRadians(radarTurn);
  60.           if (Math.random() > 0.5) {
  61.         nprand = -1*Math.random();
  62.                 }
  63.           else {
  64.                 nprand = Math.random();
  65.                 }
  66.           double bulletPower = 3;
  67.       double headOnBearing = getHeadingRadians() + e.getBearingRadians();
  68.       double linearBearing = headOnBearing + Math.asin(e.getVelocity() / Rules.getBulletSpeed(bulletPower) * Math.sin(e.getHeadingRadians() - headOnBearing));
  69.       setTurnGunRightRadians(Utils.normalRelativeAngle(linearBearing - getGunHeadingRadians()) + .1*nprand);
  70.           if (getGunTurnRemaining() < 2) {
  71.                 setFire(3);
  72.           }    
  73.                
  74.                 //Modifies trajectory based on proximity to target.
  75.                 if (e.getDistance() < 100) {
  76.                         out.println("too close!" + e.getDistance());
  77.                         if (moveDirection == 1) {
  78.                                 turnmodifier = -20;
  79.                         }
  80.                         if (moveDirection == -1) {
  81.                                 turnmodifier = 20;
  82.                         }                      
  83.                 }
  84.                 if (e.getDistance() > 100) {
  85.                         turnmodifier = 0;
  86.                 }
  87.                 setTurnRight(e.getBearing() + 100 + turnmodifier);
  88.                        
  89.        
  90.                 if (getGunTurnRemaining() < 5) {
  91.                         setFire(3);
  92.                 }
  93.                 if (lastenergy != e.getEnergy());
  94.                         moveDirection = moveDirection * -1;    
  95.                 lastenergy = e.getEnergy();
  96. }
  97.  
  98.  
  99.         public void onHitByBullet(HitByBulletEvent e) {
  100.  
  101.                 execute();
  102.         }
  103.        
  104.  
  105.         public void onHitWall(HitWallEvent e) {
  106.                 moveDirection = moveDirection * -1;    
  107.                 setAhead(150 * moveDirection);
  108.                 execute();
  109.        
  110.         }      
  111. }
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