Robocode By Zack Smith

Bent metal, flying projectiles, explosions galore. This is the world of Robocode, a program that allows you to code and create your own “A.I.” and battle it against others. In a strange homage to the battlebots of old this program allows the battler in all of us to feel that excitement. This is my journey to becoming the best robot coder in the class.( My only other challenger being Andrew Mahoney the lad sitting to my left. )

A true enemy to be feared.

The first step was to create as robot, except what Andrew doesn’t know is I had a trick up my sleeve. While he was messing about making his single perfect robot. I’d create the perfect team of bots. My “Squad” as I called them named after a stupid nickname me and my friends came uup with when we were much younger. My first robot I made was by the name of Cpt.dapper he was simple not built to last. All he did was move in a square and on the ever so lucky occasion he might shoot. The hitting things however was not his strong suit. It could beat MyFirstRobot However which was the single bot Andrew could not.

imag1

Pictured above you can see what Cpt.Dapper does in all of his glory. Like mentioned above just  a square.

Here’s his original code

While(x) {

ahead(100);
turnGunRight(360);
turnGunLeft(360);
turnRight(90);
turnGunRight(360);
turnGunLeft(360);
ahead(100);
turnGunLeft(360);
turnGunRight(360);
turnRight(90);
ahead(100);
turnGunLeft(360);
turnRight(90);
ahead(100);
turnGunLeft(360);
turnGunRight(360);
turnLeft(90);
}

The turnGunRight/Left lines tell the robot to turn it’s turret which also counts as it’s scanner so while it turns it scans for enemies.

PvtPuppyYawn was different I originally gave her the ability to just spin. In an homage to the sample robot fire she sits in one spot and scans the arena. Once she sets here eyes upon a target she opened fire. Relentlessly attacking her foe with a fire power of four ( the slowest and hardest hitting attack.)

imag2

 

Puppy stays on the blue dot and spins counter-clockwise, with the red arrows.

Puppy was my beast robot when I made her. Because she never moved she never lost sight of a target and almost never missed which was the bane of Andrew’s existence. The issue was her code was extremely simple, so simple that Andrew made a carbon copy and named it Beta.

while (x){
turnGunRight(360);
}

That’s it that’s the code. Nothing to be proud of.

A few days had passed where I was constantly just tweaking small things that Dapper or Puppy did. I changed their damage output to a smaller number so their bullets could travel fire and actually hit. As I watched Andrew coded his bots though I knew that something needed to change. I needed to stop goofing off and focus. Andrew knew what my robots did and he made his bots to completely and absolutely destroy them. He knew too much about my bots so I had to fix that.

Over the course of the weekend I deleted all the code for both PuppyYawn and Dapper. I had to start from scratch to win this battle. I decided that Dapper would never be the powerhouse of the group that would have to be Puppy. I made Dapper to have him be a leader and to skirt around the enemies shooting them quickly and with small bursts of fire.  He pecks away at the enemy while the bigger badder bots attack them with everything they’ve got. His code tells him to move in theory in a figure eight shape.

The code for the figure eight:

while(true) {
setAhead(30000);
setTurnLeft(60);
setTurnGunRight(360);
waitFor(new TurnCompleteCondition(this));
setTurnRight(360);
setTurnGunLeft(360);
waitFor(new TurnCompleteCondition(this));
setTurnLeft(90);
setTurnGunRight(360);
waitFor(new TurnCompleteCondition(this));
}

imag3

PuppyYawn had been completely revamped.  No longer the statue she takes a page out of Andrew’s book. His main bot, his tank Alpha has several steps to his code, Several stages. The stages depend on the amount of robots in the game. The stages go as follows, Hide in the corner shooting until there is only two robots left, then he drives around and shoots. With the last remaining robot on the field he rams the enemy, shooting them with every thing it’s got. The final step is a death sentence for any robot it comes in contact with. I had to prevent the final stage no matter what. The second stage is too random to do anything against it. That left only one option left, the first stage. Every time the game started Alpha did the same thing every time, it went straight up and left every single game.  PuppyYawn was made to extort that. Puppy would go straight up and left she would look ahead and behind her to find and destroy alpha wherever he may be. once she reached the corner she spirals around the top of the map.

Her movement code

 

// Robot main loop
while(true) {
while(x){
turnLeft(90);
setTurnGunLeft(360);
waitFor(new TurnCompleteCondition(this));
setAhead(1000);
setTurnGunLeft(360);
waitFor(new TurnCompleteCondition(this));
setTurnGunRight(360);
}
for (int i = 0; i < 30; i++) {
turnGunLeft(gunIncrement);
}
gunIncrement *=-1;
}
}
public void goCorner() { //head to the corner
stopWhenSeeRobot = false;
turnRight(normalRelativeAngleDegrees(corner-getHeading()));
stopWhenSeeRobot=true;
ahead(5000);
turnLeft(90);
ahead(5000);
turnGunLeft(90);
}

(imag4)

 

I then created Sgt.CupCake His job was simple. Go to the closest wall and go back and forth shooting whenever he sees and enemy. Simple but extremely effective against the enemy. The last robot I made was Lt.Corky who was the revers of Puppy he went to the corner on the other side.

The code for cupcake’s actions:

moveAmount =Math.max(getBattleFieldWidth(), getBattleFieldHeight());//this is where it gets the size of the battlefield so it can learn how far it needs to go
peek = false;
turnLeft(getHeading()%90);
ahead(moveAmount);
peek = true;
turnGunRight(90);
turnRight(90);

while(true) {
peek= true;
ahead(moveAmount);
peek = false;
back(moveAmount);
}
}

 

(imag5 imag6)

I had one robot who never made it into the fray. Pvt.TooTall a droid. Droids are unable to see so they recieve information form the leader (Cpt.Dapper) and shoot where he tells them. There was a slight issue however.  I could never figure out how to get the information to send. So that idea was bust. So the fifth robot was a repeat of  Dapper.

The time finally arrived to have the battle. Andrew much to my disappointment had made no progress over the final weekend. His robots weren’t even part of a team. His five robots. Alpha, Alpha 2, and Beta 1,2,3 all destroyed each other before the fight would even really begin. The battle was laughably one sided. We then moved to a one V. one. Alpha vs. Dapper once again I was victorious. I gave Andrew twenty minutes and and the code needed to make them work as a team. The true fight had begun. After what seemed to be a struggle the true winner had emerged. I had defeated him 66% to 34%.

Here’s the code for Dapper, Cupcake, and Puppy. Corky is just a reverse of puppy so he doesn’t need to be shown. You guys need to figure out the code to make them act as a team. (it’s a separate file completely

Dapper: His Code

Puppy: Her Code

CupCake:  His Code

 

Leave a Reply

Your email address will not be published. Required fields are marked *