in reply to Perl meets CoreWars

I think my problem with warriors not getting a "turn" may have had to do with having $JProcRoutines::MaxProcs set too low ... i bumped it up to 20, and now it works great.

We can rebuild him, stronger, faster, better...

;predecl # hoss2 # # if there are less then $bromin brothers, spawn. # else: if pid is even, attack # if pid is odd, spawn # # only check our brother list periodicly to save time # use a wait counter if spawning was prevously unsuccesful # my $brothers = undef; my $bromin = 10; my $browait = 0; my $spawnwait = -1; # ;main # if ($browait <= 0) { $brothers = &JProcRoutines::FindBrotherWarriors(); $browait = 5; } if ( (0 > $spawnwait) and ((scalar(keys %$brothers) < $bromin) or ($$ % 2 == 1)) ) { # spawn if ( ! defined &JProcRoutines::Replicate()) { $spawnwait = 5; } } else { # attack! my $warriors = &JProcRoutines::FindEnemyWarriors(); if (keys %$warriors > 0) { # Pick a random enemy to hit my $rand_enemy = (keys %$warriors)[rand(keys %$warriors)]; # Hit them. &JProcRoutines::Hit($rand_enemy); } } # cycle counters... $spawnwait--; $browait--;