Advertisement
ZaynerTech

Baseball/Softball Simulator in Perl

Jan 17th, 2013
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.85 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. # Simulate a baseball or softball game
  4. #
  5. # Change Out percentage by changing this line:
  6. # if(int(rand(10)) >= 7){ print "OUT $batter\n"; $out++; $batter++;}
  7. #
  8. #
  9.  
  10.  
  11. $out = 0;
  12. $inning = 1;
  13. $batter = 1;
  14. $totalbatters = 13;
  15.  
  16. for($sim = 0; $sim <= $ARGV[0]; $sim++)
  17. {
  18. $inning = 1;
  19. $batter = 1;
  20.  
  21. for(; $inning < 7; $inning++)
  22. {
  23.  $out = 0;
  24.  print "Inning: $inning\n";
  25.  while($out < 3)
  26.  {
  27.    
  28.   if(int(rand(10)) >= 7){ print "OUT $batter\n"; $out++; $batter++;}
  29. else
  30.   {
  31.     print "Safe:$batter\n";
  32.     $batter++;
  33.  
  34.   }
  35.   if($batter == ($totalbatters + 1))
  36.   { $batter = 1;}
  37.  }
  38.  
  39. }
  40. $finalbatter = ($batter - 1);
  41. $tots[$finalbatter] = $tots[$finalbatter] + 1;
  42. print "Final Batter: $finalbatter\n";
  43. }
  44. for($batt = 0; $batt < 13; $batt++)
  45. {
  46.    $realbatt = $batt +1;
  47.    print "Outs: $realbatt: $tots[$batt]\n";
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement