[Melbourne-pm] Timer::HiRes and alarms? (Was: AI Contest)

Toby Corkindale toby.corkindale at strategicdata.com.au
Wed Nov 10 22:46:38 PST 2010

On 11/11/10 17:21, Nathan Bailey wrote:
> I'm using the MyBot.pl from your git repository, which has:
> local $| = 1;
> at the top, so I presume that would make it autoflush, so the alarm
> could print.

The "local $| = 1;" was inherited from the original Perl starter 
package, which is of dubious quality; it might be better to make it "$| 
= 1;" instead. ie. Global, not local.. In case the alarm signal handler 
is occurring inside a different scope?
(That's clutching at straws, but worth a shot..)

> I gave up on trying to work out the SIG ALRM stuff. I don't think I've
> ever had a genuine timeout. The only times I see timeouts are:
> 1. Bad code (the engine doesn't like "stderr", despite the docs, so if I
> forget to tag a 'warn', it often fails; otherwise general crashes and bugs)
> 2. When I've had while loop where the exit condition wasn't reached
> (programmer error :-)

Likewise, I've found my code always has plenty of time to spare, apart 
from poor coding.. but then, my bot isn't that complicated either.
(He just runs through three phases - 1) global analysis; 2) per-planet 
defensive analysis; 3) per-planet further analysis and moves.
It's more like an interconnected heuristic system, rather than proper 
AI. Although I *want* to make it have more I and less A than it does 
currently.. when time allows :/ )

> I have written a simple engine that lets me trap most of my errors
> (although it doesn't reproduce the results of the java engine so
> presumably it has bugs too :-)
> I'm happy to share (eg. publish it in your git repository) it if no-one
> laughs at my code ;-) [ especially if people can fix its bugs! ]

Hmm, there's already source for the C and Java implementations of the 
engines. If you're worried about your implementation, maybe it would be 
better to just modify one of the stable engines to allow for more debug 

> When I started, I wasn't sure if I just submitted 'MyBot.pl' or all the
> .pms too, so I avoided putting code into modules and undid my initial
> changes to PlanetWars.pm
> I think PlanetWars.pm could be way more efficient and could have a
> number of other helper functions (eg. ClosestPlanet() would be an
> obvious one)

Yeah, it could definitely do with some improvements.
My Git repo holds a few by now, but only so far as improving the 
existing methods.
I've added various things (privately) such as locating nearby planets, 
summing fleet-effects and predicted planet populations, but kept them 
private. The published code is meant to just be a starter package, after 
.. plus my code isn't very good yet, anyway.

> Unfortunately I seem to be able to generate bugs that can't be
> reproduced with either the local java engine or my simple Perl engine,
> and are sometimes hard to even debug on the tcp server. At the moment, I
> issue some orders and finish the turn and end up in an endless loop of
> undefined input (ie. ' next unless defined($current_line); ') which is
> pretty hard to debug, beyond simply truncating my code to find a
> codebase that it doesn't happen to. Even if I send 'go' I still don't
> get any input back, and I never get the final 'you timed out, you lose'
> messages either.

That does sound odd; something must be quite broken if it's failing at 
that basic level of I/O! Can you write a simple test harness to operate 
on the methods parsing the game-state only?

More information about the Melbourne-pm mailing list