# Robocode(A.K.A. how to make Zach eat his words and that strategy wins over sheer power!) by Andy Mahoney

Explosions galore fighting to the death with these battle bots is the type of excitement every programmer lives for. Program these Robots in Java and battle them in a struggle to the top! Now I will become number 1 in QHS my only challenger is Zack Smith, the man sitting to my right.

Alpha has three tactics based on how many enemies he’s facing. if it’s 1 he rams into them and fires as many times as possible. If it’s 2 he swerves around avoiding fire, and if it’s three he hides in a corner and snipes for the points. But Zack Exploited this.

code for startagy:

while(true) {

// Replace the next 4 lines with any behavior you would like
if (getOthers()>2){
turnGunRight(360);
goCorner();
}
else if (getOthers()<2){
turnGunRight(360);
turnRight(5 * turnDirection);

}

else {
movingForward = true;
// Tell the game we will want to turn right 90
setTurnRight(90);
// At this point, we have indicated to the game that *when we do something*,
// we will want to move ahead and turn right. That’s what “set” means.
// It is important to realize we have not done anything yet!
// In order to actually move, we’ll want to call a method that
// takes real time, such as waitFor.
// waitFor actually starts the action — we start moving and turning.
// It will not return until we have finished turning.
waitFor(new TurnCompleteCondition(this));
// Note: We are still moving ahead now, but the turn is complete.
// Now we’ll turn the other way…
setTurnLeft(180);
// … and wait for the turn to finish …
waitFor(new TurnCompleteCondition(this));
// … then the other way …
setTurnRight(180);
// .. and wait for that turn to finish.
waitFor(new TurnCompleteCondition(this));
// then back to the top to do it all again
}
}
}

Don’t worry though because Alpha has back up on his team The Greeks. Meet Beta, the camping Tank ofg doom used to counter act PvtPuppyYawn.

Code for Beta:

public void onScannedRobot(ScannedRobotEvent e) {
// Replace the next line with any behavior you would like
if (isTeammate(e.getName())) {
return;
}
else{
fire(2);
}
}

/**
* onHitByBullet: What to do when you’re hit by a bullet
*/
public void onHitByBullet(HitByBulletEvent e) {
// Replace the next line with any behavior you would like
}

/**
* onHitWall: What to do when you hit a wall
*/
public void onHitWall(HitWallEvent e) {
// Replace the next line with any behavior you would like
back(20);