-->
-->
The last time I mentioned the avoidance method, there is a problem. As soon as the other bullet was fired, my bot moved, and the move was regular and moving back and forth. If you move a short distance, you may hit each other's bullets when you come back, and if you move a long distance, you are doing a straight line motion, and the other side can easily compute the trajectory of the bot motion. There is also a problem, avoid the time is very likely to hit the wall ... (The wall is to reduce energy: ~ ()
In response to the above questions, I wrote another bot. The code is as follows:
Import robocode.*;
public class Hanicbot extends advancedrobot{private double edist;//each other's distance private double move;//moving distance private double Radarmove = 45; Angle of the radar movement private double dfirepower; Fire
/** * main func run () */ public void Run () { edist = 300; &nbs p; while (true) { //per cycle, motion random distance Double period = 4 * ((int) (EDIST/80)); //cycle; The closer the enemy, the shorter the cycle, the more frequent the movement //cycle begins, then move if (getTime ()%period = 0) { move = (Math.random () *2-1) * (period*8-25) ; setahead (move >= 0) ( -25)); } //Avoid hitting the wall double heading = Getheadingradians (); Get the number of radians in the bot direction Double x = GetX () + move*math.sin (heading); The x-coordinate double y = GetY () + move*math.cos (heading) that will be reached after moving the move. The y-coordinate to be reached after moving move double dwidth = getbattlefieldwidth (); //Battlefield width &nBsp Double dheight = getbattlefieldheight (); //Battlefield length ///When (x,y) exceeds the specified range, moves move backward if (x < | | | x > dWidth-30 | | | y < | | | y > dHeight-30) {   ; setback (move); } turnRadarLeft ( Radarmove); Rotary Radar } }//end run ()