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

Mathew Robertson mathew.blair.robertson at gmail.com
Thu Nov 4 20:48:46 PDT 2010


Works for me, although if you want a repetitive timer, you need:

setitimer(ITIMER_REAL, 0.9, 1)

or similar.

cheers,
Mathew Robertson

On 5 November 2010 14:20, Nathan Bailey <nathan.bailey at monash.edu> wrote:

> So the contest requires each turn to be submitted within one second. So
> logically, one would endeavour to use Time::HiRes and an alarm to make sure
> that you submit a turn no matter what happens, but I seem to have the syntax
> for Timer::HiRes/alarm's wrong. I would expect that this:
>    eval {
>       local $SIG{ALRM} = sub { warn "Alarm initiated\n"; print "go\n"; };
>       setitimer(ITIMER_REAL, 0.9);
>       while(1) { ; }
>    };
>    if ($@) {
>       warn "Alarm happened?";
>       die $@;
>    }
> would:
>  a) initiate an alarm event 900ms after the setitimer statement is run
>  b) submit an end turn command ('go') to stdout/the server = successful
> turn completion
>  b) make the $@ block run when it does time out (as it will, with our
> while(1))
>
> So the above code should successfully submit empty turns every turn.
>
> 'Alarm initiated' does get printed, but 'go' doesn't seem to go to the
> server. Am I using alarm wrong or is this a contest-specific issue?
>
> thanks for your help :-)
> Nathan
>
> On 4 November 2010 19:19, Toby Corkindale <
> toby.corkindale at strategicdata.com.au> wrote:
>
>> On 03/11/10 14:56, Toby Corkindale wrote:
>>
>>> On 03/11/10 12:47, Toby Corkindale wrote:
>>>
>>>> Google is running an AI challenge - write bots to fight a (simple) game.
>>>> http://ai-contest.com/
>>>>
>>>> It supports Perl! (Albeit, only version 5.8.8! aaargh! Why so many
>>>> versions behind?)
>>>>
>>>> I thought some of you might be interested in giving it a go.. Maybe we
>>>> could have a mini-scoreboard just for Melbourne Perlmongers?
>>>>
>>>> I've signed up as "wintrmute".
>>>>
>>>
>>> Also, if you're having trouble finding the Perl starter package.. I've
>>> combined a couple of the existing resources and put them into this Git
>>> repo to make it easier for you to get started.
>>>
>>> https://github.com/TJC/planetwars
>>>
>>
>> So far it's just Justin (tardisx) from the Adelaide Perlmongers and I
>> (wintrmute) holding up the Aussie flag in the Perl rankings.. We're being
>> overrun by Russians and Ukrainians though!
>> Won't anyone else come in to help us?
>>
>> http://ai-contest.com/language_profile.php?lang=Perl
>>
>> Toby
>> _______________________________________________
>> Melbourne-pm mailing list
>> Melbourne-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/melbourne-pm
>>
>
>
> _______________________________________________
> Melbourne-pm mailing list
> Melbourne-pm at pm.org
> http://mail.pm.org/mailman/listinfo/melbourne-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/melbourne-pm/attachments/20101105/610b357b/attachment.html>


More information about the Melbourne-pm mailing list