SHARE
TWEET

cymba v0.21

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