Showing posts with label robocode. Show all posts
Showing posts with label robocode. Show all posts

Thursday, October 20, 2011

Google Code Project Hosting

I've been working with hosting my Robocode robot on Google Code's project hosting site. So far my experience with it has been most satisfactory, as I was able to successfully host my distribution on Google Code and sync it with my SVN client.  I've tested the SVN capabilities by uploading all the files for my project onto the truck portion of my project webpage. The most difficult thing I had to troubleshoot was the formatting of the wiki pages to adhere to my liking. I was most surprised with the quality of hosting projects on Google Code. It was very easy to create a page and start uploading and creating wiki pages. Plus the fact that other developers are able to join the project by just adding their email makes Google Code very simple.

A link to my robocode robot I've been developing is here. Overall I look forward to using the Google Code project hosting site to work on future projects, since it is a great free option for developers. 

Tuesday, October 11, 2011

One robot to rule them all

Alas, my robot project has come to an end. However there is still one more act in this play, the epilogue of my journey of which is called robocode. The name of my competitive robot is called RobotDevil because just like the real devil, you never know what (s)he is going to do, or not do... The inspiration of my robot was the idea of a snowflake. They say that no two snowflakes are alike, and I would like to believe that when a user runs RobotDevil, no two instances will behave the same. Without further ado, whose cuisine robot will reign supreme?

Overview 
If I asked you to pick a number between 1-10 and use that number as some sort of 'random' generated output, how 'random' would that be? The same theory applies to what I had attempted in my robocode project. I had set out to try create a robot that ideally will not win 100% of the time yet not lose 100% of the time either. A rudimentary coin flip of a robot would be my esoteric description. In essence I opted to build a robot that would display 'random' movement behavior, an optimal firing scheme and sophisticated tracking logic.

Design
Movement: Movement is the heart and soul of RobotDevil, since our movement paradigm is limited to the battlefield and 360 degrees of turning options, the 3 factors in movement for RobotDevil was the degree of the turn, length of the turn, and condition of a hit wall. The general strategy for moving the robot was to create unpredictable behavior, since most advance robots will attempt to predict RobotDevil's next movement. The only downside to this approach is that RobotDevil may not make the most logical decisions, such as moving towards an enemy bullet or walls.

Targeting: Targeting is relatively simple in the design of RobotDevil, once an enemy robot has been scanned by our robot, the robot will adjust the firepower to either the MAX_BULLET_POWER or 1. RobotDevil continuously sweeps the area by rotating the radar and gun 360 degrees.

Firing: Firing is simple since once RobotDevil sees another robot it either fires a weak bullet or the strongest bullet. The measure taken to anticipate the movement of an enemy robot was not taken since our movement is not predictable.

Results (Out of 100 rounds)
RobotDevil 2606 (14%) V.S. Walls 16575 (86%)
RobotDevil 17549 (52%) V.S. RamFire 16466 (48%)
RobotDevil 1867 (10%) V.S. SpinBot 17423 (90%)
RobotDevil 10136 (59%) V.S. Crazy 6993 (41%)
RobotDevil 20612 (68%) V.S. Fire 9593 (32%)
RobotDevil 15093 (51%) V.S. Corners 14241 (49%)
RobotDevil 2664 (12%) V.S. Tracker 19446 (88%)
RobotDevil 18020 (100%) V.S. SittingDuck 0 (0%)

As the results show, RobotDevil performed horribly against Tracker, SpinBot and Walls. Partly due to the fact that these robots stay at a distance and attack rather than approach other robots. I suppose one design improvement RobotDevil could use is a better tracking system. 

Testing
Majority of the testing was done to ensure that the movement of RobotDevil was truly random. So jUnit tests to check between two length in distances traveled are not the same. It is suffice to say that the tests were a good indicator of random movement but this brings me back to my original question of how random is random.

Lessons Learned
I felt that this robocode development experience provided myself with invaluable experience in jUnit and simple software development principals. It was a great introduction in testing practices such as behavior in code. Perhaps after seeing some of the robots developed by my fellow software developers, it will provide me with inspiration on possible future implementations in RobotDevil.

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.