« Review: XPlanner | Main | Eclipse M8: Milestone or inchpebble? »
March 22, 2004
Fighting with Local Maxima (aka Domo Arigato, Mr Robocode-o)
Many moons ago, I had run a little refactoring competition on a Friday afternoon to give my development team a bit of a heads-up on an aspect of the codebase that they hadn't seen before, and also to try and focus them on the importance of the "refactor" phase of the "red/green/refactor" TDD cycle.
The format of the competition was:
- A time-boxed pair-programming session (60 minutes) to refactor the class in question
- Determination of the winner by using Checkstyle's Cyclomatic Complexity check to determine the greatest change to the initial complexity (which had a CC level of 15!)
To my great surprise, everyone had a great time and requested similar exercises on a semi-regular basis. With this in mind, I ran a second team-building exercise this Friday just gone. This time the focus was ... robocode.
Robocode is a way cool little game engine that simulates battles between programmable tanks written in Java.
It's very easy to start from scratch and build a simple robot that can be placed into the arena to do bloody battle with other such bots. We had three pairs writing bots (namely, PCBot, MightyBot and JoshieBot) over 4 stages (between 15 and 30 minutes for each stage) with all bots being shared between competitors at the end of each stage. Using this approach, each team got a chance to evolve their bots from stage to stage, with the winner of the final stage to be declared the overall victor.
As independent BattleMiester, my role was to collect the modified bots at the end of each stage and run 10-round battles to see how the individual bots fared. Not surprisingly, each stages' bots were considerable improvements on the ones from the previous stages and the results were somewhat surprising:
- The first stage showed a distinct advantage to PCBot, which won the 8 of the battles. MightyBot came second with 2 and JoshieBot last (or 2nd runner up ;-)) with 0.
- Stage 2 saw a different leader with MightyBot coming to the fore with 7 wins, 3 to PCBot and the consistent and dependable 0 to JoshieBot
- Stage 3 continued the reign of MightyBot with 7 wins again but this time the gap between 2nd and 3rd narrowed with PCBot scoring 2 battle wins to JoshieBot's debut win
- The fourth and final round had everyone shouting "recount!" as JoshieBot evolved into a mean mothertruckin' bot with 6 wins, with the other 4 wins split evenly between MightyBot and PCBot. Talk about leaving your run to the last minute!
Although some thought it unfair that the final round counted for everything, I was quite happy that the evolutionary approach had given the rank underdogs a chance to claim victory. I dare say another round might have seen MightyBot return to the throne, but JoshieBot made it's run when it counted. Interestingly, although JoshieBot only won a single battle (out of 30) prior to the final stage, it was almost never the first to die. Unfortunately for poor JoshieBot, it wasn't the last to die either.
The end result was that the team had a challenging and enjoyably geeky way to finish out the week (thankfullly - I haven't had any repercussions from management regarding the obviously non work-related Friday afternoon). For some of the team, it was their first experience in programming in a highly threaded environment, which took some time to come to grips with. The look of delight on the teams' faces when they first saw their bots appear in the arena and begin to do "battle" (even if their battle stategy consisted solely of spinning in a tight circle and not firing - a la JoshieBot from stage #1) was priceless. I'm hoping some of them glimpsed the beauty of the decoupling of the Robocode rendering subsystem from the bot's implementation.
Footnote: a curious MightyBot author made the humbling discovery over the weekend that all of the competition bots would have been creamed by any of the basic supplied bots that ship with Robocode. This is an indication of how the strategies evolved to match the environment: the bots were only competing against each other (hence the slightly obscure statistical reference in the title), and each stage made modifications to counter the winning strategy from the previous stage. None of the teams took an "outside the square" approach and made a revolutionary change in tactics, which might have tipped the balance of power in their favour... or not.
As they say in the classics: "in the land of the blind, the one-eyed man is king!"
p.s. I ummed and aahhed about distributing the supplied sample bots with the version of robocode I gave to the pairs. In the end, I chose not to as I wanted all the competing bots to be 100% their designs and not a "here's one someone else prepared earlier" with a different name. Using this approach, all the pairs quickly had to come to grips with the event model and API required to develop bots.
Posted by Andy Marks at March 22, 2004 07:35 PM
Comments
Post a comment
Thanks for signing in, . Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)