SHARE
TWEET

cymba v0.4

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