boolean ally = true; //will we work together with other //Crazy? robots? |
static int targetStrategy = 1; //1 is Linear //2 is Head On Targeting int misscount; //how many times my shots missed |
setAdjustGunForRobotTurn(true);//allow gun to move //freely |
setAdjustGunForRobotTurn(true);//allow gun and radar setAdjustRadarForGunTurn(true);//free movement |
//ensure that we don't fire upon other //Crazy? robots if(e.getName().length() >= 5 && getOthers() > 1){ if((getName().subSequence(0,5)) .equals(e.getName().subSequence(0,5))){ if(ally==true){//if they have fired at us, we will return; //not ally with them } } } |
if(targetStrategy == 1){ |
double theta = Utils.normalAbsoluteAngle?(Math.atan2(predictedX |
double theta = Utils.normalAbsoluteAngle?(Math.atan2(predictedX |
if(targetStrategy==2||getOthers()>3){ // Calculate exact location of the robot double absoluteBearing = getHeading() + e.getBearing(); double bearingFromGun? = normalRelativeAngle(absoluteBearing - getGunHeading?()); // If it's close enough, fire! if (Math.abs(bearingFromGun?) <= 3) { turnGunRight?(bearingFromGun?); // We check gun heat here, because calling fire() // uses a turn, which could cause us to lose track // of the other robot. if (getGunHeat() == 0) fire (Math.min(3 - Math.abs(bearingFromGun?),getEnergy() - .1)); } // otherwise just set the gun to turn. // Note: This will have no effect until we call scan() else { turnGunRight?(bearingFromGun?); } // Generates another scan event if we see a robot. // We only need to call this if the gun (and therefore radar) // are not turning. Otherwise, scan is called automatically. if (bearingFromGun? == 0) scan(); } } public void onWin(WinEvent? e) { //My? favorite little victory dance. setAdjustRadarForRobotTurn?(true); setAdjustRadarForGunTurn(true); setAdjustGunForRobotTurn(true); for(;;){ setTurnRadarRight(360); setTurnGunLeft?(180); setTurnLeft?(90); if(getEnergy() > 0.1) fire(0.1); } } // Helper function public double normalRelativeAngle(double angle) { if (angle > -180 && angle <= 180) return angle; double fixedAngle = angle; while (fixedAngle <= -180) fixedAngle += 360; while (fixedAngle > 180) fixedAngle -= 360; return fixedAngle; } /** * onHitByBullet?: Randomize my movement */ public void onBulletMissed?(BulletMissedEvent? e) { misscount++; if(misscount > 5){ if(targetStrategy==1) targetStrategy=2; if(targetStrategy==2) targetStrategy=1; } } |
//make sure my allies aren't firing on me, and if //they are, I will cut short our alliance if(e.getName().length() >= 5 && getOthers() > 1){ if((getName().subSequence(0,5)) .equals(e.getName().subSequence(0,5))){ if(ally==true){ally = false;}}} }} </pre> |
} }</pre> |