Wednesday, September 9, 2009

Robowars!

In preparation for an all out robowar I have successfully created a series of 13 basic robots that outlined basic functions a serious robot should have such as tracking enemies, firing on enemies as well as basic movement behavior. The coding for my robots can be found here.

The requirements for designing sample robots is as follows:

  • Movement01: The minimal robot. Does absolutely nothing at all.
  • Movement02: Move forward a total of 50 pixels per turn. If you hit a wall, reverse direction.
  • Movement03: Each turn, move forward a total of N pixels per turn, then turn left. N is initialized to 10, and increases by 10 per turn.
  • Movement04: Move to the center of the playing field and stop.
  • Movement05: Move to the upper left corner. Then move to the lower right corner. Then move to the upper right corner. Then move to the lower left corner.
  • Movement06: Move to the center, then move in a circle, ending up where you started.
  • Tracking01: Pick one enemy and follow them.
  • Tracking02: Pick one enemy and follow them, but stop if your robot gets within 20 pixels of them.
  • Tracking03: Each turn, Find the closest enemy, and move in the opposite direction by 100 pixels, then stop.
  • Firing01: Sit still. Rotate gun. When it is pointing at an enemy, fire.
  • Firing02: Sit still. Pick one enemy. Only fire your gun when it is pointing at the chosen enemy.
  • Firing03: 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).
  • Firing04: 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).

Movement:

I had no problems coding the first 3 movement robots and the onHitWall even made it really easy to program the second robot. However the trouble came when I had to have the robot move to the center of the field (the 4th movement). Immediately I suspected that some sort of triangulation via the Pythagorean Theorem however after numerous tries I was unable to figure out how to consistently triangulate the center so instead I had the robot move to the left top corner, move half way down the move half way in. The next problem was with the 6th movement. Using the previously mentioned I was able to get the robot to the center, however I had problems moving in a circle without using the AdvancedRobot methods, so instead I used a for loop and created a slow moving circle.

Tracking:

I was kind of lost when it came to the tracking methods, so I borrowed and modified code from the tracking.java sample robot from the Robocode files. After reviewing and analyzing the code in order to understand it, tracking became easier to understand and it was easier to modify the code that I had borrowed.

Firing:

Again like the tracking methods I was unsure of how to use the firing methods so I borrowed some code from the fire.java sample robot to get me started. Just like the tracking robot I analyzed the code to understand it, then began to modify the coding appropriately. The hardest part about the firing section robots was the Firing03 robot which required fire power proportional to the distance of the enemy. The further away the less power was to be used. In order to do this I took the max fire power for the robot (which happens to be 3) and then took 3% of the distance to the enemy and subtracted it from three thus creating the desired fire rates.


Conclusion:

It took a while for me to understand the coding for tracking however once I got the hang of it things were a lot easier to code. At first I thought there was a tracking method call, but I realized that robots automatically scan and that in order to track I needed to use the onScannedRobot method call. Also I realized that geometry will play a huge part in creating a successful robot as geometry influences movement, firing and even tracking an enemy robot. With that said I think its time for me to hit the books to review my geometry.

0 comments:

Post a Comment