Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use List::MoreUtils 'uniq';
- foreach(@Species) { ANTZ-Create($_); }
- {
- foreach(@Species) {
- while($C{$_."Alive"} == 1) {
- @Species = uniq(@Species);
- $TDays++;
- &TS;
- $Next = $CurSec + 1;
- #while ($CurSec < $Next) {&TS;}
- $Inter = $Species[rand(@Species)];
- Do($Com."Day ".$TDays.". ".$Inter." meets ".$_."...");
- if($C{$_."Pred"} == $C{$Inter."Pred"}) {
- if(rand(100) > 50) {
- Do($Com."They mate");
- @First = split //, $_;
- @Second = split //, $Inter;
- $Half = int(@First / 2);
- while($Half > 0) { $Half--; pop(@First); }
- $Half = int(@Second / 2);
- while($Half > 0) { $Half--; shift(@Second); }
- $Out = (join "", @First).(join "", @Second);
- ANTZ-Create($Out) if($Inter !~ /^$_$/i);
- push(@Species, $Out) if($Inter !~ /^$_$/i);
- $C{$_."Life"} = $C{$_."Life"} + 2;
- }
- }
- if(($C{$_."Pred"} == 0) && ($C{$Inter."Pred"} == 1)) {
- $Rand = int(rand(3));
- if($Rand == 0) {
- Do($Com.$_." runs away and survives...");
- }
- if($Rand == 1) {
- Do($Com.$Inter." attacked ".$_." and killed off the ".$_." species.");
- Do($Com.ANTZ-Destroy($_));
- last;
- }
- if($Rand == 2) {
- Do($Com.$Inter." attacked ".$_." but the ".$_." managed to fight back and survive.");
- }
- }
- if(($C{$_."Pred"} == 1) && ($C{$Inter."Pred"} == 0)) {
- $Rand = int(rand(3));
- if($Rand == 0) {
- Do($Com.$Inter." runs away and survives...");
- }
- if($Rand == 1) {
- Do($Com.$_." attacked ".$Inter." and killed off the ".$Inter." species.");
- Do($Com.ANTZ-Destroy($Inter));
- last;
- }
- if($Rand == 2) {
- Do($Com.$_." attacked ".$Inter." but the ".$Inter." managed to fight back and survive.");
- }
- }
- if(($C{$_."Pred"} == 1) && ($C{$Inter."Pred"} == 1)) {
- $Rand = int(rand(3));
- if($Rand == 0) {
- Do($Com."They avoid eachother");
- }
- if(($Rand == 1) && ($_ !~ /^$Inter$/i)) {
- $Out = $C{$_."Size"} - $C{$Inter."Size"};
- if($Out <= 0) {
- Do($Com.$Inter." attacked ".$_." and killed off the ".$_." species.") if($_ !~ /$Inter/i);
- Do($Com.ANTZ-Destroy($_)) if($_ !~ /$Inter/i);
- last;
- }
- else {
- Do($Com.$_." attacked ".$Inter." and killed off the ".$Inter." species.") if($_ !~ /$Inter/i);
- Do($Com.ANTZ-Destroy($Inter)) if($_ !~ /$Inter/i);
- last;
- }
- }
- }
- $Rand = int(rand(4));
- if($Rand == 0) {
- $Rand = int(rand(2));
- Do($Com.$_." found food.");
- if($Rand == 0) {
- Do($Com."It was safe to eat!");
- $C{$_."Size"} = $C{$_."Size"} + 10;
- $C{$_."Life"} = $C{$_."Life"} + .1;
- }
- elsif($Rand == 1) {
- Do($Com."It shrank the ".$_." species!");
- $C{$_."Size"} = $C{$_."Size"} - 20;
- $C{$_."Life"} = $C{$_."Life"} + 1;
- }
- elsif($Rand == 2) {
- Do($Com."It was poisonous, lifespan decreased!");
- $C{$_."Life"} = $C{$_."Life"} - 3;
- }
- }
- if($C{$_."Life"} <= 0) {
- Do($Com.$_." has died from not breeding enough/old age.");
- Do($Com.ANTZ-Destroy($_));
- $C{$_."Alive"} = 0;
- }
- $C{$_."Day"}++;
- $C{$_."Life"}--;
- }
- }
- redo if(@Species > 1);
- Do($Com."Total Created".(join ", ", @ANTZ-Created));
- }
- sub ANTZ-Create {
- push(@ANTZ-Created, $_[0]);
- @ANTZ-Created = uniq(@ANTZ-Created);
- $C{$_[0]."Alive"} = 1;
- $C{$_[0]."Life"} = int(rand(10));
- $C{$_[0]."Pred"} = (0,1)[int(rand(2))];
- $C{$_[0]."Size"} = int(rand(100));
- $C{$_[0]."Day"} = 1;
- print $_[0]." is a predator. " if($C{$_[0]."Pred"} == 1);
- print $_[0]." is small. " if($C{$_[0]."Size"} <= 50);
- print $_[0]." is Large." if($C{$_[0]."Size"} > 50);
- print "";
- }
- sub ANTZ-Destroy {
- @Species = grep(!/^$_[0]$/, @Species);
- $tmp = $C{$_[0]."Day"};
- $C{$_[0]."Alive"} = undef;
- $C{$_[0]."Life"} = undef;
- $C{$_[0]."Pred"} = undef;
- $C{$_[0]."Size"} = undef;
- $C{$_[0]."Day"} = undef;
- return $_[0]." has gone extinct. They lasted ".$tmp." days."."Species left : ".(join ", ", @Species)."";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement