[Melbourne-pm] Timer::HiRes and alarms? (Was: AI Contest)
Nathan Bailey
nathan.bailey at monash.edu
Wed Nov 10 23:22:42 PST 2010
On 11/11/2010, at 5:46 PM, Toby Corkindale wrote:
> 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..)
Ahh, good point - the signals may be happening in some other scope.
> 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 :/ )
Despite having studied AI and neural nets, mine isn't that different.
Actually, this is a problem that lends itself very well to neural nets
(= finding out the optimal value for each target planet). But it's
been a while since I've done either - I don't even get to code perl
much these days :-)
> 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 output?
Cool, I might play with the C one. The (compiled) java version in your
repository doesn't provide any feedback, so when I crash/timeout, I
don't know where or why.
> 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.
Nice! What does this line do (Planet.pm and Fleet.pm)?
use overload '""' => sub { shift->PlanetID };
Is there a reason you don't cache the distances (eg. in a hash?) -
although I tried it, and NYTProf told me it was worse! :P
I also wonder how evil it is to dig into the object, eg. for GetPlanet:
return ${$self->{_planets}}[$planet_id];
(Okay, I know how evil it is, I just wonder if it's an appropriate
shortcut given the amount of time that code runs)
> 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 all.
> .. plus my code isn't very good yet, anyway.
*nod* I think strategy-oriented sub-routines should be private, but I
think closest planet is pretty global, ie. return either:
a) a list of planets in distance order
b) a list/hash of lists of planets indexed by distance
> 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?
Do you mean the 'while(1) { my $current_line = <STDIN> ... }' bit or
my own code in DoTurn()?
N
More information about the Melbourne-pm
mailing list