Wednesday, September 30, 2009

SideStep Steps up with Better QA

After suffering a tragic defeat at the Robocode Tournament last week. I was determine to return victorious for the next tournament. As you all know, my robot (SideStep) was able to consistently beat all but one of the 8 sample robots, which was pretty good. But ironically, most of my classmates modeled their robots off that ONE robot(Walls) that it can't beat. Hence forcing me to revise my robot....

Luckily this week we're learning about Quality Assurance using Ant and Ivy build system. These build system are great tools for almost any programmer. It consolidate a bunch of automated quality tools such as Checkstyle, FindBugs, and PMD all in one. Using these tools will cut out a lot of time spend searching for errors in your code and proof reading for formatting errors.

To perform the automated quality assurance on our project we had to invoke the following commands:

  • ant -f checkstyle.build.xml
  • ant -f pmd.build.xml
  • ant -f findbugs.build.xml

After running these commands, checkstyle was the only one that returned with errors.

Missing package-info-.java file. line 0 (1 error)
Missing a Javadoc comment. (5 error)
*After fixing errors above*
First sentence should end with a period. (1 error)
Expected @param tag for "robotDistance". (1 error)

Most of the error were in the javadoc comments, since none of my previous course ever stress on it. I've never ran into a missing package-info-.java file error before and had no clue what it is. After looking at the sample project giving by our professor, I realized that I was missing a package.html file which I later created and the error was fixed.

These tools helped my immensely because I was constantly hacking up my codes conducting trail and error in attempt to beat Walls. After many fail attempts I've realize why I was losing to it. It was because I would use up all my energy moving and firing it ending up being disabled. I didn't work to change the movement or velocity because that was the bread and butter of my robot. So I decide to lower the firepower of the bullets, and voila. Walls ends up being disabled before mine does and it becomes a sitting duck.

Now, I'll just wait patiently to see what improvements the my "Walls" competition made.
If you want to see source code, you can click SideStep v. 1.1.

Monday, September 21, 2009

A robot that'll side step the competition...

As you all know by now from reading my recent blogs, we're been working with RoboCode these pass weeks. As this project comes near the end, we're task to design a robot that will not just beat the 8 sample programs that came along with the program, but also the robots design by our fellow classmates. To beat all the sample robots is no easy task considering that some of their movements and tactics are completely opposite, such as Walls and RamFire. Here is a brief overview of my design:

Movement: Movement is the most important part of this design. In order to beat the 8 sample robots, it had to be able to out maneuver them. I wanted to keep my robot at a certain range away from the enemy robot, where it can chose between different firepower. This is extremely useful when dealing with robots that have a fixed firepower. To get to this certain range, it goes in a diagonal pattern so it avoids majority of the incoming bullets. And when dealing with bots that charges or gets extremely close, it backs off a bit and side steps the enemy. With this design, I was able to keep away from enemies that charges in, and get close to enemies that runs around or away.

Targeting: For target, I used codes from one of the sample robots written by Mathew A. Nelson. It allows the gun to follow the enemy during the onScannedRobot. This is a lot faster than turning the whole robot with a stationary gun.

Firing: For firing, I used a modified version of the smartFire method in the Corner robot. This allow me to adjust the robot's firepower with it's distance away from the enemy. A very useful strategy to conserve energy, and attack enemies with fixed firepower.

Now that you know what the basic design of my robot does, Here are the results from battling the 8 sample robot. To test my robot, I did a 100 rounds against each of the robots.

SittingDuck: Win: 100/100
Fire: Win: 100/100
Corners: Win: 100/100
Tracker: Win: 96 /100
RamFire: Win: 90 /100
Crazy: Win: 97 /100
SpinBot: Win: 67 /100
Walls: Win: 34 /100

As you can see from my result, it didn't do so well against Walls and SpinBot, I knew from the start that these 2 robots would be the hardest to beat. Going up against these 2 robots with my design is seeing how lucky I am at dodging their bullets. I ran a few more test with SpinBot and Walls and the result fluctuate between 50-75% for SpinBot and 25%-40% on Walls. It's not the best design but it's the best that I can come up with at the moment.

I have to admit, I did do some googling to see what the strategies were for some of the advance robots. You know, just to get the feel and some ideas for similar strategies. but the implementation for some of the strategies that I found were way too complicated for me to understand. So I used a simplified version of the "chicken" strategy that I found. Instead of hiding behind other robots, it simply moves back and to the side as the enemy comes close. I know this is just the tip of the iceberg for RoboCode and for Java programming. Hopefully with time, I'll be able to explore deeper into this iceberg.

To download my source code for this SideStep Robot, Please click Here!

Wednesday, September 16, 2009

Simple Samples, Learn by Examples

So to increase our knowledge of RoboCode and give us some strategic ideas, we were tasked to review the codes for some of the sample robots that came with the RoboCode Installation. This was a great idea, because after reviewing their codes and actually running them in Robocode, I can see each of their strengths and weaknesses.Below is a brief subscription of the sample robots that I reviewed...

Corners:
This robot will start off going to the upper-left hand corner. Once it gets there, it'll remain there and fire at any robot that it finds. If it dies while there are more than 75% of other robots remaining, it'll change it corner going clockwise. The bad side to this is that it becomes a sitting duck once it gets to the corner. Or worst if it bumps into a robot, it treats it as a wall. So if it bumps into another robot, it'll think that it's a corner and stops there. When it scans and finds a robot, it'll use it's smartFire methods which chooses the firepower depending on the distance of the enemy. This looks good on paper, but when testing it up other robots, it tends to lose to robots that uses a stronger firepower.

Crazy: This robot's movement is just like it's name. It's movement is so unpredictable which makes it really hard to hit. Once it's scan and finds a robot, it'll fire a weak bullet. But due to its weird movements and weak firepower, it's more of a decoy bot if it was in a team battle.

Fire: This robot is a partial sitting duck. It's starts off by spinning it's gun and radar and fires at the first robot it sees. When it gets hit, it'll move perpendicular to the bullet by 50 pixels and sits until it gets hit again. These small movement help it avoid getting hit by a chain of bullets. It constantly scans 360 degrees with its radar/gun each time it gets hit and chooses either max or min firepower depending on the distance of the target.

RamFire: This robot scans for enemy robots and attempts to ram the first one it see. It doeesnt fire until it gets into point blank range. It also lowers it's firepower depending on the target's energy trying to finish it off by ramming it to get the bonus points. This robot's strategy will normally lose to other robot that uses a high firepower or smart fire, because it's not firing at the target until it's at point blank and it lowers it's firepower when it's about to kill it's target. In my opinion, this robot is too greedy for the bonus point which is not really worth it. It's also horrible at chasing highly mobile robots such s Walls and Crazy.

Sitting Duck: This robot does extra what it's name says. It pretty much just sits there like a target dummy. But it also does one extra thing which is that it outputs a file called "count.dat" which contains the number of rounds and battles that it was it.

SpinBot: This robot constantly moves in a circular motion scanning and firing max firepower bullets at it's targets. It's circular movements helps it avoid bullets and it's max firepower allows it to tear apart stationary target with eases.

Tracker: This robot is quite similar to the RamFire in the sense that it scans for a enemy robot and chases after it, but not to a point blank range. It'll stop about 140 pixels away form it's target and then fires max firepower bullets at it. This robot similar to RamFire will have a disadvantage against high mobile robot and robot that use max firepower or smart fire. A simple improvement to this and RamFire is to just make them begin firing at their target once it's found.

Walls:This robot is the king of the sample robots and I can see why. It is always constantly moving along the walls making it a hard target. And since it's running allow the walls, it can never get hit from behind. It also peeks at the next wall before turning to make sure that there's no robots on it. That way, it doesn't get flanked from the side. I was told that the corner robot was a counter to this robot, but after reading their codes and running tests with them, the Walls always wins. It's because the Walls robot uses a fixed medium firepower while the Corner robot uses smartFire. SmartFire becomes a disadvantage because these 2 robots are always firing at each other at a full length/width of the battlefield. So if Corner uses a stronger fixed firepower, it'll probably win.

So after reading all the source code for these sample robot and doing actual tests with them, I got a pretty good idea on what strategies to implement for my robot. I'll be looking forward to see what strategies my classmates came up with and Hopefully I'll find a counter strategy.

Monday, September 14, 2009

Meeting the standards while setting the standards

When I took my first programming course a few years back. I use to think "why do I have to format my code to the professor's way? As long as I can read my code and it does what it's suppose to do, it should be fine." Boy, was I naive back then. As the programs get more difficult, I was having a harder time debugging my code. And when asking classmates for help, it took them a very long time just to follow my code and find any errors.

The point of me telling this story is that if you ever want to a real programmer and be able to write codes with other programmers, you need to follow a coding standard. The point of setting standards and meeting these standards is so that everyone is on the same page. There are technically no real "set" standards that everyone MUST follow, but there are a lot of general guidelines that most programmers follow.

For our Robocode project, we follow the following three guidelines(standards)



By following these standards, we are able to easily follow and edit codes that are written by other classmates. In the real world, writing code that only you can read don't set you apart for the others. Its writing codes that everyone can easily read and follow that makes you special. So be meeting the standards, you are setting the standards...

Here is a link to my revised codes following these standards...

Wednesday, September 9, 2009

Robocode, Show your Java supremacy

Robocode, an open source once created by IBM has now became an educational game designed to help people learn to program Java and have fun doing it. For me, it's been quite a while since I've did any serious programing in Java. To be honest, programming has never been my strong point, so when we were giving this assignment, memories of staying up all night debugging code came flashing through my head.

But to my surprise, this assignment was quite enjoyable. We were task to design 13 robot to do certain tasks. The first robot we designed was a sitting duck, which like it's name just sits there and do nothing. This was basically a "Hello World" program, as simple as it gets. But by completing this first design, I was about to run the Robocode program and see my "sitting duck". I was actually proud of myself for making this robot, kind of like a new parent seeing their new born baby. It made me feel enthusiastic and motivated to program and design more robots.

As I complete more robot designs, the task which they perform gets a little more complicated to program, and eventually I ran into a few problems. Due to my lack of program skills and time away from the Java language, I wasn't able to complete all of the 13 designs. I've managed to complete 10 out of the 13 leaving Tracking03, Firing03, and Firing04 unfinished. I was stuck on tracking03 for quite a while trying to figure out how to scan for the closest enemy, but time ran out on me before I could figure it out.

One thing that I've learned from this assignment is that these robot vary greatly depending on the programmer. A novice programmer can create simple robot that does 1 simple task, while expert programmer can create robot to be like Rombo (Rambo) a one man killing machine.

As of right now, I'm no where near these expert programmer that design robot worthy of competition. But someday, I will show you my java supremacy and create a robot worthy of competition. Til then, I'll be bushing up on my Java, and I hope you will too.

Here is the link to download my design