This is a get-your-feet wet with Robocode project, which was designed by IBM initially before being adopted by the internet community. Our assignment is to create a series of starter robots to familiarize ourselves with Robocode prior to creating our tournament-ready version.
Robots:
- Position01: 9/2/10 -The minimal robot. Does absolutely nothing at all.
- Position02: 9/2/10 - Move forward a total of 100 pixels per turn. When you hit a wall, reverse direction.
- Position03: 9/2/10 - 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: 9/5/10 - Move to the center of the playing field, spin around in a circle, and stop.
- Position05: 9/4/10 - 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: 9/4/10 - Move to the center, then move in a circle with a radius of approximately 100 pixels, ending up where you started.
- Follow01: 9/12/10 - Pick one enemy and follow them.
- Follow02: 9/12/10 - Pick one enemy and follow them, but stop if your robot gets within 50 pixels of them.
- Follow03: 9/13/10 - Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
- Boom01: 9/7/10 - Sit still. Rotate gun. When it is pointing at an enemy, fire.
- Boom02: 9/7/10 - Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
- Boom03: 9/11/10 - 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: 9/13/10 - 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).
This definitely seems like a fun project. There's a good deal of quality documentation out there and games are always fun. Some notes on a few of the implementations:
Position04:
After programming the first three positions, this position caught me a little off guard by the amount of trigonometry that was involved in the calculations. Overall though, I like math and it was still a fun exercise. I'm currently trying to modularize the code a little more for the subsequent tasks.
Modularization complete. Version 2.0 of Position04 here with some enhancements. I was able to get the robot to swivel directly to the desired angle, rather than setting it at 0 degrees first.
Without the use of the advanced robot class features, moving the robot in a complete circle of a set radius was simple, but it did have some drawbacks. To move it in a smooth circle I moved it at 1-5 degrees/turn, resulting in a very slow circular path.
Follow01:
I first implemented a simple tracking robot, but after reviewing the code from the Tracker robot packaged with Robocode, I opted to integrate it's more efficient radar movement into my robot.
Follow03:
This robot forced me to investigate the relationship between time and robot movement. I learned that a scan returns all robots detected, the first one being the closest one. I also gained some insight from the following site about what happens in the course of a single turn, in addition to the processing order during gameplay:
Final Thoughts:
This was an excellent (and fun) coding assignment. I learned a little bit about importing external files and .jar files into Eclipse, which I didn't have too much experience doing. I also improved my code-reading a little since the sample robot code is very simple and well-commented. As a final note, I've started to code every day - after a long layoff during summer - and this is going to help me immensely in my growth as a programmer. I just need to keep it up :)
On to the Tourney Robot:
I definitely want to implement a better radar function. This page seems to be worth looking into:
I'd also like to improve the robot's firing mechanism and how it adjusts for enemy robot movement as well as the defensive movement of the robot.
The Code:
Source code can be found here: