Here I am with a new Robocode blog entry.
Having a general idea on how Robocode works by doing the katas, now I am facing with a extremely difficult task: Create a robot that can defeat some of the sample robots. I had put it some time and effort, but from lack of time, my robot is able to defeat 100% 5 out of the 8 samples (SittingDuck, Walls, RamFire, SpinBot, Crazy, Fire, Corners, and Tracker).
Design.
My robot basic movement is a very newbie dodging bullets which I tried to implement by myself. It takes in account the energy of the enemy robot. So if its energy drops by 0.1 or 3, then it is high a chance that it fired a bullet. My robot will then try to dodge it. Sounds good right? But I never take in account that if I hit my enemy, his energy will also drop. Or when my enemy hits a wall or ram onto me.
My targeting was an upgrade of the robocode katas "Boom04" which 95% of the time, my robot will point its gun to my enemy.
My firing also takes in account the robocode katas "Boom03" which the power of the fire is proportional to the distance of the enemy. The farther the enemy is, the stronger the firepower. Also I realized that if my robot is most of the time pointing its gun to the enemy, why not fire a bullet with stronger power? So if my robot's gun faces directly to its enemy, then it will fire a bullet with power of 2.
Results.
Out of 10 rounds this are my results.
SittingDuck : 100%.
Walls: 100%.
RamFire: 50%.
SpinBot: 0%.
Crazy: 0%.
Fire: 100%.
Corners: 100%.
Tracker: 100%.
My robot has a flaw: it fires linearly. Also my dodging bullets is not the best.
Testing.
Due to time constraint, I did some unit test of some helper methods I created. I tested them using some "obvious" inputs to correctly output the expected value. All tests passed.
I also did a behavioral test in which I test whether my robot should fire or not. My robot will fire only if it is directly pointing to the enemy, or its gunHeat is 0. So for each turn, I verify its angle and gunHeat, which 100% of time my robot fires as expected.
Lessons.
I think my code looks "beautiful" thanks to the automated quality assurance I had. I learned how hard is to keep up with the coding standards in Java. For every tiny error you had in your code, the xml files will not let you to build successfully. Also the testing part I find that it will save a lot of time. I didnt have to run every time the robocode application to see if my robot behave as I expected. I just need to write test cases that will run immediately.

No comments:
Post a Comment