Wednesday, September 30, 2009

Quality Assurance: Robocode Improvements

For approximately the last month, I have been working with the Robocode project, which has me creating battle robots in Java. Initially, this project development was a completely individual assignment, where I programmed robots that were designed to run only on my computer. However, during the code review we did in class a few weeks ago, this design flaw was exposed when my partner had an extremely difficult time getting my robots to work on his computer. One of the solutions to this problem is the Ant build system combined with the Ivy dependency manager, which together not only include tools to put together projects for distribution, but also includes quality assurance tools that can be used check that files have the correct formatting.

In the past week, I have installed the Ant system on my computer, and used it in conjunction with Ivy to improve my PacerEvader robot that I had designed for the class Roborumble. The first thing that I did was to adapt the Ant code that my professor provided the class with for use with my robot, and then used the Checkstyle, PMD, and FindBugs quality assurance tools to check my code. Each of these tools does slightly different tasks, ranging from formatting, to analyzing the way code works, so it was important to run each of them. In total, the tools found 34 errors, with the following breakdown:
  • Checkstyle - 31 errors
  • PMD - 3 errors
  • FindBugs - 0 errors
The Checkstyle errors were all formatting errors, mostly dealing with a lack of white space. For instance, the following line of code:
fire(minPower+(maxDist-dist)*(maxPower-minPower));
initially returned 8 errors, because I had no whitespace preceeding or following each of the operators. I fixed it to read:
fire(minPower + (maxDist - dist) * (maxPower - minPower));
The PMD errors were slightly higher-level and included unnecessary return statements in functions.

I found that automated quality assurance tools are extremely useful because they provide an easy way to check formatting so that you don't have to worry about catching every little error while programming. I think that this would be extremely valuable if I got into a programming zone and wanted to write code without having to constantly worry about the formatting or optimizing my code. However, since these errors do need to be fixed eventually, it is advantageous to try to control the number of errors that these quality assurance tools would generate.

In addition to fixing the problems found by the quality assurance tools, I also created a basic junit test case for my robot, to ensure that my robot beats SittingDuck. Again, this utilized Ant and Ivy to run the test itself and check the results.

Finally, I made a small improvement to my robot's performance and prepared a new distribution file. The improvement was to add in another case where my robot would move to the opposite wall. My robot moves ahead and backwards along a wall, and if it is hit from nearly directly in front or from nearly directly behind, it will move to the opposite wall. This is to prevent the robot from getting caught in the first of a Walls-like robot that peeks ahead and continues firing until the wall it wants to move across is cleared.

My updated PacerEvader robot can be found here.
The distribution file for the robot can be found here.
Updated distribution file (10/5): here.

After completing this assignment for class, I am beginning to really appreciate the value of Ant. At first, I was skeptical about how much it would truly do to help me, but after completing this assignment, I see that the power is not only in its features for a build system, but also in its integration of Ivy, which allows it to pull together many additonal tools. Although I am still getting use to interpreting Ant code and doubt that I would be able to write Ant code on my own, I have already reaped many of the benefits from Ant. It provided an easy way to evaluate my code for possible errors, and also packaged my robot for me, for easier distribution to others. I look forward to having Ant available to me for future projects, and also learning how to adapt Ant further for use in other projects.

No comments:

Post a Comment