Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fire219;
- import robocode.*;
- import robocode.util.*;
- //import java.awt.Color;
- /**
- * Cymba - a robot by fire219
- * Proving simple is better since 2014
- */
- public class Cymba extends AdvancedRobot
- {
- int moveDirection = 1; //0 = left, 1 = right
- int turnmodifier = 0;
- public void run() {
- setAdjustRadarForRobotTurn(true);
- // setAdjustRadarForGunTurn(true);
- do {
- // ...
- // Turn the radar if we have no more turn, starts it if it stops and at the start of round
- if ( getRadarTurnRemaining() == 0.0 )
- setTurnRadarRightRadians( Double.POSITIVE_INFINITY );
- execute();
- setAhead(15 * moveDirection);
- scan();
- } while ( true );
- // ...
- }
- public void onScannedRobot(ScannedRobotEvent e) {
- // ...
- // Absolute angle towards target
- double angleToEnemy = getHeadingRadians() + e.getBearingRadians();
- // Subtract current radar heading to get the turn required to face the enemy, be sure it is normalized
- double radarTurn = Utils.normalRelativeAngle( angleToEnemy - getRadarHeadingRadians() );
- // Distance we want to scan from middle of enemy to either side
- // The 36.0 is how many units from the center of the enemy robot it scans.
- double extraTurn = Math.min( Math.atan( 72.0 / e.getDistance() ), Rules.RADAR_TURN_RATE_RADIANS );
- // Adjust the radar turn so it goes that much further in the direction it is going to turn
- // Basically if we were going to turn it left, turn it even more left, if right, turn more right.
- // This allows us to overshoot our enemy so that we get a good sweep that will not slip.
- radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);
- //Turn the radar
- setTurnRadarRightRadians(radarTurn);
- double gunangle = (getHeading() - getGunHeading() + e.getBearing() - 5*e.getVelocity());
- while (gunangle > 180) gunangle -= 360;
- while (gunangle < -180) gunangle += 360;
- setTurnGunRight(gunangle);
- // always square off against our enemy
- if (e.getDistance() < 400) {
- out.println("too close!" + e.getDistance());
- if (moveDirection == 1) {
- turnmodifier = -40;
- }
- if (moveDirection == -1) {
- turnmodifier = 40;
- }
- }
- if (e.getDistance() > 100) {
- turnmodifier = 0;
- }
- setTurnRight(e.getBearing() + 90);
- // strafe by changing direction every 20 ticks
- if (Math.random() > .9999) {
- out.println("Changing dir");
- moveDirection = moveDirection * -1;
- }
- if (Math.random() > .9) {
- fire(3);
- }
- // ...
- }
- public void onHitByBullet(HitByBulletEvent e) {
- execute();
- }
- public void onHitWall(HitWallEvent e) {
- moveDirection = moveDirection * -1;
- setAhead(150 * moveDirection);
- execute();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement