Game times out strangely


#1

I have a weird problem with random time outs. I monitored different parts of my code and I noticed that sometimes it spends 1.7 seconds just to update the game frame at the beginning of a new turn, and this is the main reason for my issue. I basically run out of almost all my time without even starting to do anything. Did anyone else encounter a similar situation? I also noticed that my CPU tends to favour some bots more than the others in terms of percentage allocation when running locally (which is the main cause). Not sure if the same thing happens on the halite servers

(I am using python3)


#2

From having seen other players with this issue, my guess is that you are starting your timer before calling game.update_frame(). Since other players might not have sent their turn to the engine for that turn yet, you’re including all that time as being spent for your next turn when you actually start your turn.

The simple fix is just start your timer when game.update_frame() returns. (This is still not quite the technically correct point for the timer to start, but makes no practical difference and is much easier.)


#3

Thanks @Janzert, I was indeed making that mistake :slight_smile:. I thought reading the game state was part of the 2s time limit and the other players had already submitted commands by then. It looks to be more robust now. Cheers


#4

If I start the timer after the engine sends me the new turn number (which I think is the first input I get on a new turn), will the rest of the input from the engine follow directly afterwards?

Is this very close to the technically correct point to start the timer, or is it better to wait until the engine finishes sending the whole state?


#5

Yes, starting the timer as soon as you receive the first output from the engine (which IIRC you are correct is the new turn number) should be at least technically slightly more accurate. It may even be the theoretically best point, but I don’t have the inclination right now to study the engine code to check that. :wink:

Overall though I doubt you’ll see a significant difference, in the start kits at least, from just starting it after game.update_frame() returned.


#6

Great, thank you for clarifying. :slight_smile:
As long as what I’m doing doesn’t produce the timeout behaviour described above, I’m happy. :slight_smile: