Thursday, September 29, 2011

Oh nooo! We're going to have Ants!

Without a doubt, ants are some of the world's most determined creatures. Despite their sometimes small sizes, they are some of the most hardworking insects in the sense that they work together to build massive systems, or colonies, that are deeply layered in order to survive. In fact, as a result of their work, ants have colonized almost every landmass on Earth. They have come thrive in nearly all ecosystems,representing almost 15-25% of all land animals. I guess this is one good reason why Apache decided to rely on an ant symbol for their own Ant build system tool.
Apache Ant, or Ant("another neat tool") is a tool for automating software build process. It does draw parallels to the way ants build their so called "system", relying on scripting that is compilable,creates documentation, package, test and deploy code (thought, not necessarily in that order). Each piece plays a role in helping to neatly manage and export Java programs for both aspiring and long-time software developers.
Often one of the most noticeable differences between Ant and other build system tools (and yes, there are many others! Take Maven, for example) is that Ant relies on XML (frankly, a language that I lack the necessary experience in). Despite my unpreparedness, I dove right into the deep, practicing with Ant-Katas (you saw this coming, didn't you?). I managed to complete each kata, however not unscathed, having to go review my code on multiple occasions for forgetting symbols like "/" or ">" and even for getting to declare variables like "system.name" with a value (all of which almost drove me to the brink of insanity!). But thanks to these katas, I have learned some of the most important ANT basics like the immutabilities of properties, how dependencies work (in that, avoiding the dreaded circular dependency!) and how to interact with the console. With the help of some of my fellow classmates, the Ant API, and a nights supply of red bull (since it really does give you wings!), I was able to create some simple programs that were complete time savers.

Tuesday, September 20, 2011

r..r..r...Robocode!

Ever wonder what it takes to become an avid programmer? If you have just started programming or have even been doing it for some amount of time, this is one question that will often appear from time to time in the depths of your subconscious (or in my case, usually while I'm programming!). There is no doubt that a study of the formal techniques of programming (which you can find in any book) will have an important role to play in any programming career. However, the most vital task in becoming an avid programmer, I believe, is practice (a task,sadly, we often don't have much time to do with our busy schedules).Practice, indeed, does makes perfect. In fact, it is often the detail that distinguishes great programmers from the not so great, since programmers who practice understand the need to challenge themselves by taking on tasks that take them beyond their usual comfort level.

And to both my surprise and satisfaction, I was able to get a good amount of practice in using Robocode. Robocode is an open source programming game that was originally developed by IBM, which was later picked up by Flemming N. Larsen and Parvel Savara. The goal of Robocode is two folded; Sticking to their motto, the first, "build the best to destroy the rest", alludes to the ability to create, manipulate, and destroy Robots in a no holds bard, fight to the death, battlefield. The second, which is my favorite, is to enhance the users knowledge of Java since the game involves writing code in Java and having the created robot(s) battle one other by moving around, shooting at enemies, or just following enemies around on the battlefield. Specifically, I worked with implementing 13 katas, or simply, 13 robots that that helped me to see where I am as a Java programmer. At first I thought with my previous experience in Java ( and Java robots) this project would be very easy, but as I soon found out, it was not as simple as I thought. Take a gander at the 13 katas:

Position01: The minimal robot. Does absolutely nothing at all.
Position02: Move forward a total of 100 pixels per turn. When you hit a wall, reverse direction.
Position03: Each turn, move forward a total of N pixels per turn, then turn right. N is initialized to 15, and increases by 15 per turn.
Position04: Move to the center of the playing field, spin around in a circle, and stop.
Position05: Move to the upper right corner. Then move to the lower left corner. Then move to the upper left corner. Then move to the lower right corner.
Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
Follow01: Pick one enemy and follow them.
Follow02: Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
Follow03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
Boom01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
Boom02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
Boom03: Sit still. Rotate gun. When it is pointing at an enemy, use bullet power proportional to the distance of the enemy from you. The farther away the enemy, the less power your bullet should use (since far targets increase the odds that the bullet will miss).
Boom04: Sit still. Pick one enemy and attempt to track it with your gun. In other words, try to have your gun always pointing at that enemy. Don't fire (you don't want to kill it).

While I was able to successfully implement all 13, by no means was it an easy feat. In fact, I had the help of two of my fellow classmates, Marifel Barbasa and Hansen Cheng. In the implementations, the most difficult portions (and I mean mind-numbingly difficult!) were the Positions 04,05, and 06. I was completely taken off by the amount of trigonometry needed (or the amount of trigonometry that I had forgotten) in these implementations in order for the robots to function as intended. I must say, if it wasn't for the help of my classmates, Java's helpful (and sometimes helpless) Math class, and the, what I thought were endless, hours of drawing out angles and directions on paper, then I probably would have not have finished these particular katas.

After having finished them however, I still feel that there is so much more for me to learn (and yes, trig is on the list!). The katas were great insightful tools that let me know where some of my comfort levels are and what I need to do in order to push past them. While I do have an idea about how to build a "good" competitive robot, in respect to positioning in a way to make escape easy and constant targeting a must, it is far from "great". I will still have to iron out some of the kinks.