Robocode is an open source game that was originally developed by IBM. It was meant to be an ongoing project, but IBM lost interest in the project and discontinued the project. The project was picked up by Flemming N. Larsen and Parvel Savara and it is available to download on sourceforge.
This game involves writing code in Java and having the created robot(s) battle each other by moving around, firing at enemies, or just following the enemy around the battlefield. In order to win this game it is not about using strategies but it is to create a robot from algorithms that allows the robot to predict enemy movements, firing of bullets and other actions.
For my project or kata (a Japanese martial arts term) I had to program robots to perform the following thirteen actions:
- 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).
As you can see, the list of actions can be separated into three categories. The first category is mainly for you to understand how the robot moves around the battlefield, and get familiar with the methods provided. Position 4 and 5 in this first category gave me the hardest time because it involved using trig functions. I was unfortunate in implementing a code that directly uses trig functions in calculating the robot’s angle. Therefore, I have the robot move linearly to the center and corners as specified for those positions. Currently I am still in the process of experimenting with how to incorporate trig functions into calculating the angle and have the robot directly move to center or the corners.
The second category involves picking an enemy robot and follows it around; which doesn’t involve any trig functions. Generally speaking, for the three exercises in this category I have the robot get the name of the enemy robot and follow it around, and if the one being followed lost contact with my robot I have it rescan for other robots to follow.
In the final category, it involves exercises to either fire at an enemy or have the gun follow the enemy. For the first three exercises in this category, it was relatively easy to understand how to scan for a robot and fire at it. In the final exercise I had problems of trying to have the gun track the enemy relative to the distance from enemy to my robot. I had to calculate the angle of my robot and its gun relative to the enemy so that the robot knows where to follow the enemy.
Overall, I think this project is great for people to get familiar with coding standards and learn how to read up API of a project. It is crucial to read up an API of a project because it provides descriptions of all the methods used in the class. This project also helps one to be familiar in using an IDE such as Eclipse to code their projects because it provides many features to help one implement their code.
No comments:
Post a Comment