Thursday, September 29, 2011

Let's mess around with ANT!

On our continuous journey through the glamorous and exciting world of software engineering, we come across another valuable programming tool, which goes by the name of ANT. And yes, while those tiny insects that scrounge the earth may come to mind upon hearing this name, it's actually an acronym standing for "Another Neat Tool". So the whole insect thing was actually just an afterthought, as it turns out. Anyways, so what exactly does this ANT do? Well simply put, it's an Apache-built automated software build tool, which given the right commands, can automatically compile java files, alter directories, grab updates and modules and whatnot from the internet and place them in the proper system directories on your computer, and that's just the tip of the iceberg. It's as if it gives you the power of an ant-whisperer of sorts, where you tell the ants what you want to be done and they just all go off and do what you told them to do. For more fun facts on ANT, here you go.

In order to get our feet wet with ANT, we were assigned 8 little katas to figure out and compile. Some took more time than others, but for the most part they were all relatively straight-forward.  In order to complete these katas, we had to make various build files, which were to be done in XML(ANT uses xml files to execute commands and whatnot). Although lacking in prior experience with the language, the resources provided online, including the apache ant website and tutorials pages proved to be of great assistance in helping me to get off the ground.

There are a couple of special things about ANT that I noticed while going through the katas. Why some of these things are present in ANT I do not know, but they're just things that you're going to have to get used to. For example, properties, which can be thought of as variables, are immutable in ANT, meaning that once you've declared something, you can't change the value, which was the point of one of the katas.

Another interesting feature of ANT is dependencies, which are pretty much what targets, which can be thought of as methods, need to do in order for them to run. For example, if I had a target="foo" that had a dependency on another target="bar", denoted by depends="bar", that means that in order for "foo" to run, "bar" must first be run. Even though the code for "foo" might be written before the code for "bar", when compiled, "bar" is run first, followed by "foo". It's a pretty interesting feature of ANT.

Another thing that ANT allows you to do is to run features from JAVA from within ANT. This includes compiling java files, running java files, and even generating javadocs, all of which were some of the katas assigned.  In order for ANT to be able to use the features from java, however, it's important to make sure that java is properly installed on your computer, and that all your environmental variables are inputted correctly.  This proved to be a minor setback for me completing all of the katas, but eventually I was able to find the errors and fix them accordingly.

Well, that just about sums up my experiences with ANT thus far, and my impressions thus far is that it's a pretty powerful development tool to use, and if done right, it can make one's job as a software developer a lot less difficult.

Tuesday, September 20, 2011

Robocode!

For this week's program we've been dabbling with a little something called robocode, and as the name implies, yes, there are robots involved! Unfortunately however, it's all within a computer simulation, so my hopes of pitting customized roomba bots against each other in a fight to the death will have to wait for now.
Simply put, robocode is a game where you can program custom robots and then put them in a virtual arena where they do battle with other robots until the last one stands. Robots have three basic functions; movement, firing, and detection of other robots, and although that may not seem like a lot, you have the whole java arsenal at your disposal to customize how a robot moves, how it reacts to other enemies, and a multitude of other things. From dancing in sine curves around your enemy to doing a little victory dance when you've destroyed an opponent, the sky's the limit with how detailed and intricate you can get. Robots can be programmed in either java or .NET, but for the purposes of this project java will be exclusively used.  For those of you who wish for a more detailed explanation of the wonderful world of robocode, here you go.

I must say that it was a bit difficult at first to get my homemade robots actually working, but after looking over many tutorials and reading through the robowiki, I was able to make a bot that could move around, and eventually destroy other bots.  The great thing about robocode is that there is a pretty sizable community, with a multitude of resources including tutorials, explanations, forums and whatnot, something for people of all skill-levels.

Programming knowledge aside however, honestly I'd say the most difficult part of robocode is using trigonometry. Of course, it is by no means mandated that you use trig in order to move around your robot, but without it your code is going to be a lot longer and you're going to have find a lot of workarounds in order to get your robot to do what you want it to do. For example, when locking on to a coordinate, you have to take into account the current angle the robot is facing and the position of the coordinate relative to that robot, calculate the slope and convert that to degrees, then get the robot to face that position and then calculate the distance to determine how far to send the robot. Doing that without trigonometry, you're gonna have a hard time finding those calculations.  I personally spent a good 3 to 4 hours trying to come up with a sufficient formula to calculate angles, but not being the trig-whiz I once was in high school, I was unable to figure it out myself.  Fortunately however, with help from my good friend the internet, I was able to find a method from a bot that did the exact same thing, and with some slight modifications to the code I was able to implement the function within my robot (properly cited in my code, of course). Right there is another great thing about robocode, you are able to take things you like from other robots and add them to your own, and for the most part it's easily compatible, because all robots are an extension of just one of two classes, Robot or AdvancedRobot.

We were tasked with making a grand total of 13 robots, each with their own specific function. From doing nothing, to travelling in a spiral, to following other robots, to shooting all robots, in all they all pretty much cover the basics of robot movement and action.  I was able to complete 12 of the 13 robots, the only one left undone being a bot that tracks another robot with it's gun but does not fire.

Having gotten my feet wet with robocode, I feel that I'm a bit more familiar with the way these robots function. It's easy to pick up, but underneath that simplicity there's just so much depth and so much you're able to do with these robots, that in order to master it, it's gonna take a while. It was really helpful that the project was divided into bots with incremental steps in complexity, so that when you completed one robot you gained insight as to how to program other robots. I'm better off than I was when I started this project, but of course, there's still a long way to go in order to "build the best, destroy the rest!"

Seeing as how the next project involving robocode will be to create a competitive robot and facing off against classmates, I have a feeling that it's definitely going to be harder than fighting with practice bots that just stay still and don't fire at you. It's really going to be important to be mindful of a bunch of factors in order to build a robot that can survive in the arena, things such as ammo depletion, turning direction, trajectory and so on. I know I already have some ideas for my robot (none of which I shall disclose at this time), and am looking forward to programming it in to my robot and pitting it up against my classmates in the upcoming weeks.

Well that just about sums up my experiences with robocode thus far, and I'm sure there's plenty more to come down the line. For those of you who are interested in robots, or just improving your programming skills, I would definitely recommend dabbling in robocode, just to see how far and how skilled you can become.