Tuesday, September 15, 2009

Learning from the Enemy: Analyses of Other Developers' Robots

Before I design my competitive robot, I thought it would be necessary to see what other people did with their robots first. In particular, I looked at the sample robots that came with the Robocode installation package. Specifically, I will talk about how the authors of the Corners, Crazy, Fire, RamFire, Sitting Duck, SpinBot, Tracker, and Walls robots implemented the movement, tracking, and firing functions for them.

Robot #1: Corners
Movement
The goCorner method handles the movement for the Corners robot. As its name implies, the robot will face perpendicular to the wall that is to the right of the corner that it chose to go to and then go to that wall. Then it will turn left ninety degrees and move to the chosen corner. It is worth mentioning that the number of pixels to move forward, which is specified in goCorner, is hard-coded, so if the battlefield size is gigantic (say, 20,000 x 20,000 pixels), the robot may not reach the chosen corner; in this case, it can easily be defeated by attacking it from behind.

Tracking
The robot swings its gun from zero to ninety degrees once it reaches the chosen corner; it does not rotate its gun from zero to 360 degrees continuously. If it makes radar contact with an enemy, it will try to track the enemy with its gun and fire at it both at the same time. However, if an enemy is to the rear of it and stays there all the time, and the latter never reached the chosen corner, the enemy will never be found because of the constricted movement of the robot's gun. Even worse, the enemy will have the perfect opportunity to destroy the robot without taking any hits.

Firing
The robot will open fire once radar contact is made. If the robot's energy is below a certain level, or if the enemy is very far away, it will use low power for its bullets. On the other hand, if the enemy is very close, it will use maximum power.

Robot #2: Crazy
Movement
Based on my observation of the Crazy robot in action, it appears that the waitFor method that is called in run will make the robot turn and move ahead at the same time. These two actions are accomplished by calling setTurnRight (and setTurnLeft) and setAhead, respectively, before calling waitFor. Also, it is important to note that the Crazy class extends AdvancedRobot, not Robot. In classes that extend Robot, one must call turnRight (or turnLeft) and ahead to make the robots turn and move forward, respectively; however, unlike the Crazy robot, they will not do these two actions concurrently, only sequentially. By turning and moving forward concurrently all the time, the Crazy robot appears to be moving around randomly.

Tracking
Because the robot's gun and radar are both stationary, and because of the way the robot moves, there is no tracking mechanism used to lock onto an enemy once radar contact is made; radar contact is made only when the robot is facing in the direction that the enemy is located, and radar contact is lost when the robot turns in another direction.

Firing
The robot uses low power for its bullets and opens fire at any enemy that comes into radar contact with it.

Robot #3: Fire
Movement
The code to make the Fire robot move is located in the onHitByBullet method; no other method contains code for movement. Thus, the robot will only move if a bullet hit it; the robot will turn perpendicular to where the bullet came from and move fifty pixels.

Tracking
The robot sits still and rotates its gun throughout the entire battle until an enemy hits it with a bullet. Once radar contact is made, the robot will track the enemy with its gun and open fire at it both at the same time; however, radar contact can easily be lost once the enemy fires a bullet at the robot and the latter moves as a result of being hit.

Firing
If an enemy comes into radar contact and is very close to the robot, and the amount of energy left in the latter is greater than fifty, the robot will use maximum power for its bullets against that particular enemy. Otherwise, the robot will use low power. Also, it will use maximum power against the enemy that comes into physical contact with it.

Robot #4: RamFire
Movement
The RamFire robot is similar to my Tracking01 robot; the former will rotate its entire body until it comes into radar contact with an enemy. Once radar contact is made, the robot will move to the enemy's location and attempt to ram it. If the robot arrives at the enemy's location but the enemy is not there, the robot will rotate its body again until an enemy comes into radar contact. Basically, the robot will follow the enemy and try to ram it.

Tracking
Both the robot's gun and radar remain stationary throughout the entire battle. Because the robot only moves to an enemy's location and does not track an enemy with its gun or radar, this strategy will be ineffective against enemies that move around a lot, e.g. Crazy and Walls, because the only way to fire at them is to come into physical contact with them (i.e. by ramming them).

Firing
The robot fires at the enemy only when the former makes physical contact with it. Despite this strategy's ineffectiveness when it comes to very mobile enemies, the robot makes up for it by using maximum power for its bullets when it fires.

Robot #5: Sitting Duck
Movement
The Sitting Duck robot sits still throughout the battle. In the code file, there is only one method, run, but no method is called that will make the robot move; the only things that are done in this method are reading in a file that contains the total number of rounds and battles that the robot has been in, incrementing the two numbers, and displaying the results to the screen.

Tracking
The robot does not move both its gun and radar at all during the battle. No methods are called in run that will make the robot move either of them.

Firing
The robot does not fire its gun at all during the battle. Surely, the robot is a sitting duck, perfect for target practice, because it does absolutely nothing at all.

Robot #6: SpinBot
Movement
The SpinBot robot moves in a circle throughout the entire battle. After examining the code file for the robot, I saw that, like the Crazy class, the SpinBot class also extends the AdvancedRobot class, and it uses the setTurnRight method, which, according to the API documentation, will execute when an action takes place or the execute method is called. In this case, ahead is the next method that causes the robot to take action, so both turning and moving ahead are executed at the same time, concurrently.

Tracking
The robot's gun and radar remain stationary throughout the battle, so no tracking mechanism is implemented.

Firing
Once radar contact is made with an enemy, the robot will open fire at it with maximum power. However, it is important to note that because the robot is firing with maximum power, if there are two or more enemies on the battlefield (say, two Sitting Duck robots) and are in close proximity to each other, not every enemy will be fired upon until the gun cools down.

Robot #7: Tracker
Movement
The Tracker robot will rotate its radar until radar contact is made. Like my Tracking02 robot, once radar contact is made, the robot will turn its body towards the enemy and move to the enemy's location, stopping when it is 150 pixels away from the enemy. If it gets too close, the robot will back up forty pixels.

Tracking
Once the robot arrives at a location 150 pixels away from the enemy but the latter moved to another location, the robot will try to find it again by moving its radar ten degrees to the left and right. If it did not find the enemy that it was tracking, it will rotate its radar until it makes radar contact, either with the same enemy or a different one. The tracking mechanism implemented here is similar to the one I used in my Tracking02 robot, but instead of using a string to keep track of an enemy and setting it to null once radar contact is lost, I used an integer, which I set to one once radar contact is made and zero once radar contact is lost or my robot is not tracking an enemy at the moment.

Firing
The robot will open fire with maximum power once it is 150 pixels away from an enemy's location. If another enemy bumps into the robot, the latter will back up, open fire with maximum power at that enemy, and track it until radar contact is lost.

Robot #8: Walls
Movement
The Walls robot will face perpendicular to a wall and then go to that wall. Then it will follow the edge of the wall in a clockwise fashion.

Tracking
The robot's gun and radar remain stationary throughout the entire battle, so no tracking mechanism is implemented.

Firing
Once the robot reaches the edge of the battlefield, its gun will be perpendicular to the wall, and it will open fire with medium power once radar contact is made.

My Final Analysis
The robots that remain stationary (Corners, Fire, and Sitting Duck) are more at risk than the other robots, all of which are mobile, no matter how good their tracking mechanisms are. Why? Think of battles involving three, four, or more robots. I do not think they would last very long.

The tracking mechanism that the Corners robot uses is not a good one because it does not cover a wide area--that is, its radar sweep only covers only one-fourth of the battlefield, not all of it--and like I mentioned before, the robot's most vulnerable area is its rear.

If no tracking mechanism is going to be implemented, the robot should be on the move at all times (Crazy, SpinBot, Tracker, and Walls); even better, the robot should move randomly (e.g. Crazy) and quickly.

Hopefully, I did not give away too much information... ;)

--BJ Peter DeLaCruz

0 comments:

Post a Comment