home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume15 / xbomb / part03 / statistics < prev    next >
Text File  |  1993-01-27  |  1KB  |  59 lines

  1. #!/usr/local/bin/perl
  2.  
  3. #
  4. # output statistics about map
  5. # @(#)statistics    1.4 (UCLA) 10/15/92
  6. #
  7. # statistics is Copyright (C) 1992 by John Heidemann, Los Angeles, CA.
  8. # All rights reserved.  Permission is granted to freely distribute
  9. # this as long as this copyright message is retained intact.
  10. # Permission to distribute this as part of a commerical product
  11. # requires explicit permission of the author.
  12. #
  13. #
  14.  
  15.  
  16. $| = 1;   # no output buffering
  17.  
  18.  
  19.  
  20. #
  21. # loop reading boards
  22. #
  23.  
  24. for (;!eof(STDIN);) {
  25.  
  26.     # read in data
  27.     while (<STDIN>) {
  28.         chop;
  29.         if (/^numbombs (\d+)/) {
  30.             $numbombs = $1;
  31.         };
  32.         last if (/map/);
  33.     };
  34.     @map = ();
  35.     while (<STDIN>) {
  36.         last if (/^$/);
  37.         chop;
  38.         push (@map, $_);
  39.     };
  40.  
  41.     $bombsfound = $unknownfound = 0;
  42.     # figure stats
  43.     foreach (@map) {
  44.         $bombsfound += tr/X/X/;
  45.         $unknownfound += tr/././;
  46.     };
  47.  
  48.     # report stats
  49.     print STDERR "Bombs found: $bombsfound\n";
  50.     print STDERR "Unkowns found: $unknownfound\n";
  51.     printf STDERR "Guess chance: %.5f\n", ($numbombs-$bombsfound) / $unknownfound;
  52.     print STDERR "\n";
  53.     # we draw no conclusions
  54.     print "\n";
  55.  
  56. };
  57.  
  58. exit (0);
  59.