Monday, September 21, 2009

Let's fight smartly

After working on RoboCode for a week, it is the time to start implementing my own strategy. This time, I will try to create a robot (YichiSpecialBot) that can beat the sample robots (Crazy, Corner, Fire, Sitting Duck, Spin Bot, Ram Fire, Tracker, and Wall) that come with the robocode package. Following is my strategy.
1.Movement
To win a battle, you have to survive first. Movement is a very important part in the battle strategy. After playing around with the sample robots, I figure that "Wall" is the one that can survive most of the time. Why it can survive? I think it is because Wall is moving constantly so that it can dodge the bullet effectively. Therefore, I am going to use the same strategy as Wall. However, if I do the exactly same as Wall, I probably cannot beat it. Instead of moving on the edge of the battlefield, I decide to make my robot follow the diagonal of the battlefield if it is moving horizontally and follow the edge if it is moving vertically. In this case, when my robot played against the Wall, it can reach the corner earlier than Wall so that it can set an ambush.
2.Targeting
Since my robot keeps moving during the battle, it will not try to track any enemy. It will fire at any one it scans. However, At the beginning of each turn, it will turn the gun a little bit so that it can scan a different area. Also if it hit by another robot or bullets, it will turn its gun to the direction that the event happened.
3.Firing
It is not smart to fire all the time. I set my robot only fire if the enemy is within 500 pixels and fire hard if the enemy is within 100 pixels. I also tried to implement a perdicting function in my robot so that it can perdict the enemy movement according to the distance of the enemy, heading of the enemy, and the velocity of the enemy, but it does not work properly so far:(

Testing Result for YichiSpecialBot (10 battles):
vs Sitting Duck: 10 wins
vs Crazy: 10 wins
vs Fire: 10 wins
vs Corner: 8 wins
vs Ram Fire: 4 wins
vs Tracker: 7 wins
vs Wall: 7 wins
vs Spin Bots: 7 wins

The result is reasonable. It can reliablly beat Sitting Duck, Crazy and Fire. It has some advantages when fighting with Corner, Wall, Tracker and Spin Bots. It does not work well when fighting against Ram Fire. I think the problem is my robot does not run a way when hit by a robot. Therefore, Ram Fire can take advantage because it is design for short distance battle. I should probably find a solution to that later on.

Here is my code for YichiSpecialBots:
http://www2.hawaii.edu/~yichi/xyc.YichiSpecialBot.1.0.jar

No comments:

Post a Comment