Thursday, September 29, 2011

Using ant as an alternative to make?

I'm a bit biased when dealing with build systems, because I've worked with the very simple make build tool.  Yes it doesn't have all the bells and whistles as ant does but it gets the job done and it was popular before build systems took off. (make was the original build system hipster)

I approached ant just like how I would approach women. I would try to RTFM look at example files and try to understand how it works by just reading the code.  The code I tried to analyze first was the XML files packaged in the PMJ.dacruzer folder. I took a look at the build.xml file, only to be stumped as to what the heck was going on after 30 minutes. However the structure of the build.xml file was similar to a make file, which led me to believe I was on the right path.  I attempted to try complete a couple of ant katas, as a way of getting my feet wet. The katas dealt with cleaning, compiling, javadocs and packaging a system.

Eventually I turned to the ant manual for more information. The manual has a lot of information but it was a bit difficult to understand what exactly was going on. I had also asked a couple of software developer friends of mine on some insight about some of these katas.

In the end I was able to finish all of the katas, except the packaging kata.  The difficulty I had with this kata was the creation of the zip file.  However from completing all the other katas I have learned a lot about ant. For example I learned about basic dependencies, immutable properties, and working with java files within ant. I still appreciate make but ant seems to provide software developers with a much more convenient tool than make. The fact that ivy and ant works together to provide a build system + dependency management tool for a software developer, is awesome.

Tuesday, September 20, 2011

Robocode Katas

When thinking of katas the first thing that comes to my mind is the next karate kid.  More specifically the scene where Julie-San asks Mr. Miyagi when she was going to start breaking boards.  Mr. Miyagi responds by telling her to continue washing his car, remember 'wax on, wax off.'  This is where the beauty of Katas come in, it might seem repetitive to wash a car, or print a hello world program, however the underlying idea is that you are sharpening specific skills.  Katas are not necessarily easy, some katas may challenge you and bring you to the brink of frustration and insanity.  I welcomed this idea of a programming challenge and applied the code kata idea on building robots.

danger danger will robinson... these aren't the robots you're looking for. In fact these robots are part of an open source game called Robocode.  These robots fight for the user and set out to destroy other robots, until there is only one.  Robocode is a game in Java, where programmers can build their robots to do all sorts of fantastic things. These robots are very intricate, because of all the things the user must account for when building his/her ultimate robot.  Such as the direction the robot is facing, the direction the gun is facing, the enemy robot, and the strength of attack. 

  • 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.
  • 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). 
I've successfully finished the code katas listed above, however I've yet to implement a working version of the following robots
  • Position06: Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
  • 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). 
The main problem I've had with these 2 code katas is that it involves the use of trigonometry and that is a field where I lack in. Although I have gained a lot of knowledge in developing a basic robot that involves moving, firing, and scanning. While doing these katas I found myself looking at the Robocode API since it was a very useful page displaying the functionality of everything in Robocode. Also I've gotten more comfortable reading other people's code. One of the code katas asked for the robot to reach the middle, and a researcher at IBM had posted his code that solves this in an intricate way. Overall my ineptness to use trigonometry haltered the completion of the last two katas.  

My future plans on Robocode would involve building a competitive robot that will incorporate trigonometry. I will focus on the firing aspect on my competitive robot, as this will indefinitely help fire me into robot glory.