Skipped Turns ... what to know about?

Jump to navigation Jump to search
Revision as of 11 June 2012 at 16:08.
The highlighted comment was created in this revision.

Skipped Turns ... what to know about?

Hi mates. I'm quite new to the 'skipped turn' behavior and would appreciate a little heads up.

I just put this on my robot:

public void onStatus(..)
{
    start = System.nanoTime();
}

public run()
{
     .....
     while(true)
     {
           .....
           System.out.format("[%d] %d \n",getTime(),System.nanoTime() - start);
           excecute();
     }
}

This is what i get and i'm not sure how to interpret it:

[203] 7260000 
[204] 4098000 
SYSTEM: TassieDevil* (1) skipped turn 205
SYSTEM: TassieDevil* (1) skipped turn 206
[205] 7443000 
SYSTEM: TassieDevil* (1) skipped turn 207
[206] 8137000 
SYSTEM: TassieDevil* (1) skipped turn 208
[207] 8656000 
[208] 7771000 
[209] 4019000 
SYSTEM: TassieDevil* (1) skipped turn 210
SYSTEM: TassieDevil* (1) skipped turn 211
[210] 7488000 

To me it looks like that the turn counter is not incremented on skipped turns and the next turn after the skipped gets the time++. Normally this would have no influence on my bot, but i send some stats to another team bot who needs to know when the stats are gathered. I don't believe that it works like this and i'm very sure i missing out some here. My thought was that if i skip a turn it shouldn't reach the printout line. Is there a way to get the time i can spend until i get a skipped turn?

thanks in advance and take care

    Wompi12:08, 11 June 2012

    I think I understand what's going on here. When you go over your time limit for a turn, you skip the next one or more turns. But this probably means that none of the events are fired or anything else when you call execute(), and the while loop still runs.

    If you think about what code is actually executing from your bot, there's the main while loop, and whenever you call execute, Robocode processes the setXXX stuff you've called and fires all your events. There's no way really for Robocode to make your main while loop skip ahead a couple of iterations. But presumably, no events are being fired for that tick, and any "actions" you take in the while loop are not happening when you call execute().

      Voidious16:44, 11 June 2012
       

      Hmm, actually, you're right, I'm still confused. Maybe if you also print the time from onScannedRobot we could see more clearly what's going on? Eg, maybe after turn 209, it decides you skip 2 turns and prints about them, but the while loop still happens for those turns, but execute() does nothing for the next 2 calls to it.

        Voidious16:48, 11 June 2012
         

        Actually... I was pretty sure this lag in "getTime()" wasn't the case in the past. I suspect this may be a Robocode bug that explains the unusual observations you were reporting elsewhere Voidious...

          Rednaxela16:55, 11 June 2012
           

          So is this what we think should happen here?

          • You call execute() on turn t. You've taken <math>turnTime * 3.5</math> since your last execute call started, so you need to skip 3 turns.
          • Your turn t processes normally, execute() hangs while Robocode processes 3 more turns, events are fired to your bot for turn t+4, and control returns to the run loop with time t+4.

          Alternatively, and this would explain the above output:

          • Instead of execute() hanging while Robocode processes 3 more turns, your calls to execute() just do nothing for 3 turns, but your main loop still runs.

          That would be unfortunate, since you might do significant processing in run() with no effect, and several iterations of run() might count against your next turn's time allotment, causing you to skip more turns.

            Voidious18:08, 11 June 2012