The Secret of Robocode master

Source: Internet
Author: User
Tags radar

Before I show you this technique, you must understand some of Robocode's basics. First, it uses an energy silo for attacking and defending. This brings an interesting game decision: you have to decide when to use energy to fire your opponents and when to conserve energy to cope with possible losses.

Second, robots have very limited knowledge of their surroundings. It can know the distance, azimuth, direction, speed and energy level of other robots. However, it does not see the bullets, but perhaps based on these clues, you can guess how to find other robots are firing at it.

The Dodgebot is stationary and keeps track of the opponent's previous energy level. When its energy drops a certain amount, Dodgebot thinks it is firing and moving to the left or right. Surprisingly, this will confuse most robots ' targeting methods. They either shoot directly at the target or try to calculate the position according to your speed and direction. If your robot doesn't move, both algorithms will be firing at the robot. And your robot guessed this, and leaped a small step to the side, but the bullets were still in the same direction. Figure 1 shows the actual Dodgebot.

Figure 1. Dodgebot to Tracker (fooled!) )

Listing 1 shows the code for Dodgebot. Executes the main code section whenever the radar perceives an enemy. Dodgebot maintains his right angle, plus 30 degrees in favor of the opponent. At a 90-degree angle, the robot has the greatest ability to avoid bullets. The additional 30-degree tilt makes the robot have a certain attack, and gradually approach the target. Then there is the key part of the code: If the robot perceives that the energy is falling between 0.1 and 3.0 (the range of Fire), the robot will immediately switch direction, moving left or right. Very simple. It switches the direction of the cannon and radar scans, assuming that if it sees a robot in the last scan, it will find it again when it sweeps the same area again. Then the robot will fire its cannon. Because I linked the cannon to the radar and the scanner was called at the moment it was facing the opponent, the cannon was firing at the opponent. Finally, I'll write down the opponent's energy for the next round.

Listing 1. Dodgebot's Code

Import robocode.*
public class Dodgebot extends Advancedrobot
Double previousenergy =;
int movementdirection = 1;
int gundirection = 1;  
public void Run () {
Setturngunright (99999);
   
public void Onscannedrobot (
scannedrobotevent e) {
///Stay in right angles to the opponent
Setturnright (e.getbearing () +90-
30*movementdirection);

//If The bot has small energy drop,
//Assume it fired
double changeinenergy =
Previousene Rgy-e.getenergy ();      
if (changeinenergy>0 &&
changeinenergy<=3) {
//dodge!
      Movementdirection =
-movementdirection;
Setahead ((E.getdistance ()/4+25) movementdirection);   
}
//When a bot is spotted,
//sweep the gun and radar
Gundirection =-gundirection;
Setturngunright (99999*gundirection);

//Fire directly at Target
F i r e (2 ) ;  

//Track The energy level
Previousenergy = E.getenergy ();
}
}

I used this technique on a robot called Wolverine, which uses some sensor information to make it feel more accurate. When the opponent hits my robot, the opponent has to recharge his energy. When my robot hits an opponent, the energy level drops. The robot may feel both of these things at the same time, so Wolverine uses this information to counteract the equivalent energy fluctuations.

There are still problems with this technique. As soon as the bullet is fired, the robot moves, so it may eventually move back into the trajectory of the projectile. It is better to move the bullets when they are expected to arrive.

A more serious problem is that even if you are able to confuse the usual aim, it is easy to predict the movement to the next step. The best way to use this technique may be to let the information guide your movement rather than let it control it.

You might think that this technique is so simple that you would have wanted it yourself. Not bad. This is how the game is played, and that's why it's so appealing. Robocode on chess games, every new step will be a new idea.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.