Sunday, October 9, 2011

Getting Ready for the Big Arena

The number of days until the big event is counting down, and quickly! I'm going through a training regime with my robot (named Narchi) to get into tip-top shape for the big Robocode competition taking place this coming Tuesday, October 11th. Each athlete has their own strategy to winning, and Narchi is no different. We are working in collaboration with each other, brainstorming and trying out different strategies, keeping ones that work, and dismissing the ones that we come to find aren't fruitful. Unfortunately, it seems like there are many more happenings of the latter versus the former, but I think we have finally come up with a strategy (at least a general one) that is a keeper. The journey up until here has been long, with lots of dead-ends and backing-ups, as illustrated here:


Thursday, October 4th
Our first approach was to start off simple-- just to get moving and/or shooting. Since the corners of the battle field seem to be the best hiding spots, we decided to go there first. Finding and going to the closest corner appeared to be the most efficient plan, but I quickly found this to be troubling, because the many (not-so-simple) calculations made the lines of code grow and grow, and grow and grow. Furthermore, this proved to be inefficient, because when I added tracking and firing capabilities to Narchi, he would forget about moving to the corner once he spotted an enemy, and would just keep firing, only remembering to go to the corner once the enemy was annihilated..


Saturday, October 8th
So, back to the drawing board it was.. I needed to work on Narchi's ease to get distracted! I'm thinking that we might simplify the movements, and just focus on getting a good firing strategy. Previously, Narchi would fire based on the enemy's distance, using less power if the enemy was far away. But as I watched Narchi practice against robots such as Corners, he would miss a lot while Corners was moving away, and once Corners stayed still, Narchi would only fire small bullets if he was far away enough. I realized that this was pretty wasteful, so we'll try and change it so that if Narchi misses a shot, then he will decrease his bullet power, and if he hits an enemy, then he will increase his power. However, this is proving to be rather difficult, because sometimes Narchi wants to fire again, but the bullet is still traveling, so he doesn't know whether to use more or less power on the next bullet.
Back to more training! Stay posted for more news!


Monday, October 10th
Well, the final version of Narchi is completed, and ready for the big unveiling tomorrow! It took quite a lot of tweaking to get it ready, but we're finally ready to roll out. For the final specifications of Narchi, we have the following:
  1. Movement - The first thing that Narchi does is moves to the closest corner to its starting point (i.e. the one defined by the quadrant that he starts off in. The algorithm is a very simple "follow-along-the-walls" one, which may work better in terms of evading enemy attacks compared to a direct path to the corner. But the movement doesn't stop there! No, for when Narchi gets hit by a bullet, he tries to move to a new (supposedly random) spot to avoid getting hit again.
  2. Targeting - Narchi is an excellent targeting robot, able to lock on to the enemy that it can see. From the beginning of the match, if another robot crosses his view, he will abandon the task of moving to the nearest corner and just focus on locking on to this target instead. One flaw that Narchi has with targeting, however, is that once he starts moving around from being hit, he quickly changes plans and abandons his targeting scheme. In terms of "fight-or-flight", he is definitely a "flight" kind of guy.
  3. Firing - Alongside targeting, Narchi will fire during his initial "lock-on" period of the battle. He is wise about his actions, and decreases his bullet power when he knows that he has previously missed a shot, and increases the power when he knows that he has shot an enemy. However, just like the targeting problem, once Narchi gets hit and goes into "flight" mode, he seldom reverts back to firing, which could spell out losses.
Results
As a result, we have a robot that can do some interesting things, but is not quite perfect. It can reliably beat the sample bots that don't fire, such as SittingDuck and Target, but does not fare very well with those that shoot, due to Narchi's tendency to freak out when getting shot. Before implementing the evasion tactics, Narchi could beat Corners and even Walls sometimes, but it seems that adding the extra functionality caused Narchi to be unable to go back to its previous task, or to do them well simultaneously. As such, it probably would be better to remove the evasion portion from the code, but then Narchi would be nearly identical to Corners, and so we'll leave it in and show off a little of Narchi's ninja skills. If this tactic could be incorporated more smoothly into the overall strategy, Narchi could possibly become a tough contender to beat.

Testing
Rather than doing any unit testing, I decided to test Narchi's behaviors, and acceptance to opponent robots. I tested the movement to a corner, whether bullet power increased upon hitting, whether bullet power decreased upon missing, and evasion when hit by a bullet. For the first two, I tested against a non-moving enemy, so that the feedback on just the movement and firing could be tested. For the latter two, I tested against enemies which Narchi struggled against. By finding a bullet that had less power than before, I was able to determine that Narchi must have missed, thus turning the dial down on the power. And by seeing that Narchi first moved to a corner and then ended up in a different spot some time later in the round, I was able to determine that Narchi must have tried to move upon getting shot. The two acceptance tests were against SittingDuck and Target, since those were the only two that Narchi could beat because he would freak out if it got hit by any other robots.

Lessons Learned
Well, I can certainly say that Robocode was quite an adventure, to say the least. It was very difficult to get started and get used to the rules, physics, and flow of Robocode, which made it even more agonizing to figure out how to code my robot effectively. I still do not completely understand some subtle nuances with the execution flow, but overall, my understanding has increased greatly. But more so than Robocode specifically, I learned a lot about build systems and tools such as JUnit, Checkstyle, PMD, FindBugs, and Jacoco, that although sometimes gave me unnecessary headaches, are very useful in writing clean, concise, and effective code, and I am very glad to have learned about this. While there are many things that I could do differently if I were to do this again, I think that the only thing I would do (other than try and spend more time on it) is figure out in more detail about how Robocode works, so that I could be a more efficient programmer when implementing strategies. I feel that I wasted a lot of time simply because I didn't know a lot of the methods and classes that could have been really helpful to me. But, what's done is done, and now it's off to see how Narchi does against the fierce competitors!

No comments:

Post a Comment