SHARE
TWEET

Cymba v0.2

fire219 Dec 30th, 2014 175 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; //0 = left, 1 = right  
  13.         int turnmodifier = 0;
  14.         public void run() {
  15.            
  16.            setAdjustRadarForRobotTurn(true);
  17.           // setAdjustRadarForGunTurn(true);
  18.            do {
  19.                // ...
  20.               // Turn the radar if we have no more turn, starts it if it stops and at the start of round
  21.               if ( getRadarTurnRemaining() == 0.0 )
  22.                   setTurnRadarRightRadians( Double.POSITIVE_INFINITY );
  23.                   execute();
  24.                   setAhead(15 * moveDirection);
  25.                   scan();
  26.          } while ( true );
  27.        
  28.           // ...
  29.         }
  30.  
  31.         public void onScannedRobot(ScannedRobotEvent e) {
  32.            // ...
  33.  
  34.            // Absolute angle towards target
  35.            double angleToEnemy = getHeadingRadians() + e.getBearingRadians();
  36.  
  37.           // Subtract current radar heading to get the turn required to face the enemy, be sure it is normalized
  38.            double radarTurn = Utils.normalRelativeAngle( angleToEnemy - getRadarHeadingRadians() );
  39.  
  40.             // Distance we want to scan from middle of enemy to either side
  41.            // The 36.0 is how many units from the center of the enemy robot it scans.
  42.            double extraTurn = Math.min( Math.atan( 72.0 / e.getDistance() ), Rules.RADAR_TURN_RATE_RADIANS );
  43.  
  44.           // Adjust the radar turn so it goes that much further in the direction it is going to turn
  45.            // Basically if we were going to turn it left, turn it even more left, if right, turn more right.
  46.            // This allows us to overshoot our enemy so that we get a good sweep that will not slip.
  47.           radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);
  48.  
  49.           //Turn the radar
  50.           setTurnRadarRightRadians(radarTurn);
  51.                 double gunangle = (getHeading() - getGunHeading() + e.getBearing() - 5*e.getVelocity());
  52.                 while (gunangle >  180) gunangle -= 360;
  53.                 while (gunangle < -180) gunangle += 360;
  54.           setTurnGunRight(gunangle);
  55.         // always square off against our enemy
  56.                 if (e.getDistance() < 400) {
  57.                         out.println("too close!" + e.getDistance());
  58.                         if (moveDirection == 1) {
  59.                                 turnmodifier = -40;
  60.                         }
  61.                         if (moveDirection == -1) {
  62.                                 turnmodifier = 40;
  63.                         }                      
  64.                 }
  65.                 if (e.getDistance() > 100) {
  66.                         turnmodifier = 0;
  67.                 }
  68.                 setTurnRight(e.getBearing() + 90);
  69.         // strafe by changing direction every 20 ticks 
  70.                 if (Math.random() > .9999) {
  71.                         out.println("Changing dir");
  72.                         moveDirection = moveDirection * -1;    
  73.                 }      
  74.                 if (Math.random() > .9) {
  75.                         fire(3);
  76.                 }      
  77.     // ...
  78. }
  79.  
  80.  
  81.         public void onHitByBullet(HitByBulletEvent e) {
  82.  
  83.                 execute();
  84.         }
  85.        
  86.  
  87.         public void onHitWall(HitWallEvent e) {
  88.                 moveDirection = moveDirection * -1;    
  89.                 setAhead(150 * moveDirection);
  90.                 execute();
  91.        
  92.         }      
  93. }
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