Novice always encounters the problem of robot DISABLE, actually because of the use of the Robocode system time, so there is such a test.
In the Robocode system, the robot must do it in a certain Tick time period, otherwise the system will set the robot to the Disable status, I will call these operations "effective operation". That then is the function call is "effective operation" Test found that the basic functions of Robot (including AdvanceDRobot) are valid :-)
The longer the next question, the more "effective operation"? All the robots want to do more calculations in order to grasp the battlefield information. Most new people (including me :-() will find AdvanceDrobot more Efficiency, so there is the following code:
While (true) {
setxx ();
...
setxx ();
...
}
But misfortune happened, our robot disable!
Between two executers (or the blocking function call is neither "set" call), our robot can call the non-block calls that cannot be operated 1000, this value should be set by the Robocode system, my version is 1.0 I don't know if it will change with the system's upgrade. Theset function is returned immediately, and our code segment has a while! The speed of the machine is fast enough, can be called in a millisecond Thousands of thousands of times, far more than our 1000. This is the execute () function used to use Wu Zhi. He can inform the system to block himself. At the same time, the non-blocking call is executed, the system will only think that the robot works normally, naturally Will disable.
At this time, there is a problem. What time to call EXECUTE () is right? Look at some articles, basically say "as soon as possible". That is to say, don't do complex calculations, more complicated from FAQ should not see More than 15 milliseconds of calculation time, this time is enough for us to do a lot of things, but I think especially in multiplayer, it is not a good master of all robots and doing related processing. It can only be "as soon as possible" For example, we only deal with the information of a robot, but in fact, we can do 3 or more, so we waste our precious calculation time!
The following test is based on this situation.
Private int setcount = 0;
Private long begintime = 0;
PRIVATE long endtime = 0;
Privat int waitTime = 20;
While (true) {
IF (0 == begintime) {
SetCount ;
Begintime = getTime ();
}
EndTime = getTime () - Begintime;
SetCount ;
Try {
Thread.sleep (1);
}
Catch (InterruptedException E) {
}
IF ((setCount> = 1000) || (endtime> waittime)) {
EXECUTE ();
P.rintln ("endtime:" endtime);
P.RINTLN ("setcount:" setcount);
Begintime = 0;
SetCount = 0;
}
In the case of a default 30 frame, 48 frames are timed.
Waittime is equal to 10, the robot can be managed normally
Waittime is equal to 20, the robot can be normal
Waittime is equal to 30, the robot is DISABLE
SetCount is basically around 460 times
Description:
1.Setcount is used to count the number of non-blocking times, otherwise it will exceed 1000 first.
2.Thread.sleep (1); is used for simulation calculation time, I have to make each of our computers very fast (1 millisecond, or to say slower for higher performance)
3. Setting the frame rate is also the same as the same result, it should be related to the machine performance (P3 mobile 900; 256m; SIS630 graphics), no higher :-( 4.gettime also calculates a count, testing If you are on While Only the GetTime is only called, the system will also prompt to exceed the total number of calls 1000.
Combined with FAQ, Tick Time is about 15 milliseconds, I want WaitTime set to 10 is safe.
I don't know what the situation in Waittime is in other systems, and this value cannot be dynamically calculated, and there will be some problems in actual use. But I really give us a message, we can do it in a system-conscious time period More things, especially for multi-person fighting (or Team mode) may not think about the effect.
I think my own robot will use the basic structure below. Of course, each basic information calculation function should be very fast.
Run () {
While (true) {
While (SetCount <1000) && (endtime <= waittime)) {
IF (there is no completed calculation) {
// Basic information calculation function
}
Else
Break;
}
EXECUTE ();
}
}
ONXXXEVENT {
// Only set state
}