Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.99 KB | None | 0 0
  1. use List::MoreUtils 'uniq';
  2.  
  3. foreach(@Species) { ANTZ-Create($_); }
  4.  
  5. {
  6.     foreach(@Species) {
  7.         while($C{$_."Alive"} == 1) {
  8.             @Species = uniq(@Species);
  9.             $TDays++;
  10.             &TS;
  11.             $Next = $CurSec + 1;
  12.             #while ($CurSec < $Next) {&TS;}
  13.             $Inter = $Species[rand(@Species)];
  14.             Do($Com."Day ".$TDays.". ".$Inter." meets ".$_."...");
  15.            
  16.             if($C{$_."Pred"} == $C{$Inter."Pred"}) {
  17.                 if(rand(100) > 50) {
  18.                     Do($Com."They mate");
  19.                     @First = split //, $_;
  20.                     @Second = split //, $Inter;
  21.                     $Half = int(@First / 2);
  22.                    
  23.                     while($Half > 0) { $Half--; pop(@First); }
  24.                     $Half = int(@Second / 2);
  25.                    
  26.                     while($Half > 0) { $Half--; shift(@Second); }
  27.                    
  28.                     $Out = (join "", @First).(join "", @Second);
  29.                     ANTZ-Create($Out) if($Inter !~ /^$_$/i);
  30.                     push(@Species, $Out) if($Inter !~ /^$_$/i);
  31.                     $C{$_."Life"} = $C{$_."Life"} + 2;
  32.                 }
  33.             }
  34.            
  35.             if(($C{$_."Pred"} == 0) && ($C{$Inter."Pred"} == 1)) {
  36.                 $Rand = int(rand(3));
  37.                 if($Rand == 0) {
  38.                     Do($Com.$_." runs away and survives...");
  39.                 }
  40.                 if($Rand == 1) {
  41.                     Do($Com.$Inter." attacked ".$_." and killed off the ".$_." species.");
  42.                     Do($Com.ANTZ-Destroy($_));
  43.                     last;
  44.                 }
  45.                 if($Rand == 2) {
  46.                     Do($Com.$Inter." attacked ".$_." but the ".$_." managed to fight back and survive.");
  47.                 }
  48.             }
  49.             if(($C{$_."Pred"} == 1) && ($C{$Inter."Pred"} == 0)) {
  50.                 $Rand = int(rand(3));
  51.                 if($Rand == 0) {
  52.                     Do($Com.$Inter." runs away and survives...");
  53.                 }
  54.                 if($Rand == 1) {
  55.                     Do($Com.$_." attacked ".$Inter." and killed off the ".$Inter." species.");
  56.                     Do($Com.ANTZ-Destroy($Inter));
  57.                     last;
  58.                 }
  59.                 if($Rand == 2) {
  60.                     Do($Com.$_." attacked ".$Inter." but the ".$Inter." managed to fight back and survive.");
  61.                 }
  62.             }
  63.             if(($C{$_."Pred"} == 1) && ($C{$Inter."Pred"} == 1)) {
  64.                 $Rand = int(rand(3));
  65.                 if($Rand == 0) {
  66.                     Do($Com."They avoid eachother");
  67.                 }
  68.                 if(($Rand == 1) && ($_ !~ /^$Inter$/i)) {
  69.                     $Out = $C{$_."Size"} - $C{$Inter."Size"};
  70.                     if($Out <= 0) {
  71.                         Do($Com.$Inter." attacked ".$_." and killed off the ".$_." species.") if($_ !~ /$Inter/i);
  72.                         Do($Com.ANTZ-Destroy($_)) if($_ !~ /$Inter/i);
  73.                         last;
  74.                     }
  75.                     else {
  76.                         Do($Com.$_." attacked ".$Inter." and killed off the ".$Inter." species.") if($_ !~ /$Inter/i);
  77.                         Do($Com.ANTZ-Destroy($Inter)) if($_ !~ /$Inter/i);
  78.                         last;
  79.                     }
  80.                 }
  81.             }
  82.            
  83.             $Rand = int(rand(4));
  84.             if($Rand == 0) {
  85.                 $Rand = int(rand(2));
  86.                 Do($Com.$_." found food.");
  87.                 if($Rand == 0) {
  88.                     Do($Com."It was safe to eat!");
  89.                     $C{$_."Size"} = $C{$_."Size"} + 10;
  90.                     $C{$_."Life"} = $C{$_."Life"} + .1;
  91.                 }
  92.                 elsif($Rand == 1) {
  93.                     Do($Com."It shrank the ".$_." species!");
  94.                     $C{$_."Size"} = $C{$_."Size"} - 20;
  95.                     $C{$_."Life"} = $C{$_."Life"} + 1;
  96.                 }
  97.                 elsif($Rand == 2) {
  98.                     Do($Com."It was poisonous, lifespan decreased!");
  99.                     $C{$_."Life"} = $C{$_."Life"} - 3;
  100.                 }
  101.             }
  102.            
  103.            
  104.             if($C{$_."Life"} <= 0) {
  105.                 Do($Com.$_." has died from not breeding enough/old age.");
  106.                 Do($Com.ANTZ-Destroy($_));
  107.                 $C{$_."Alive"} = 0;
  108.             }
  109.             $C{$_."Day"}++;
  110.             $C{$_."Life"}--;
  111.         }
  112.     }
  113.     redo if(@Species > 1);
  114.     Do($Com."Total Created".(join ", ", @ANTZ-Created));
  115. }
  116. sub ANTZ-Create {
  117.     push(@ANTZ-Created, $_[0]);
  118.     @ANTZ-Created = uniq(@ANTZ-Created);
  119.     $C{$_[0]."Alive"} = 1;
  120.     $C{$_[0]."Life"} = int(rand(10));
  121.     $C{$_[0]."Pred"} = (0,1)[int(rand(2))];
  122.     $C{$_[0]."Size"} = int(rand(100));
  123.     $C{$_[0]."Day"} = 1;
  124.     print $_[0]." is a predator. " if($C{$_[0]."Pred"} == 1);
  125.     print $_[0]." is small. " if($C{$_[0]."Size"} <= 50);
  126.     print $_[0]." is Large." if($C{$_[0]."Size"} > 50);
  127.     print "";
  128. }
  129. sub ANTZ-Destroy {
  130.     @Species = grep(!/^$_[0]$/, @Species);
  131.     $tmp = $C{$_[0]."Day"};
  132.     $C{$_[0]."Alive"} = undef;
  133.     $C{$_[0]."Life"} = undef;
  134.     $C{$_[0]."Pred"} = undef;
  135.     $C{$_[0]."Size"} = undef;
  136.     $C{$_[0]."Day"} = undef;
  137.     return $_[0]." has gone extinct. They lasted ".$tmp." days."."Species left : ".(join ", ", @Species)."";
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement