home *** CD-ROM | disk | FTP | other *** search
/ Powerdrive 1997 February / POWERDRIVE0297.ISO / share / rollen / nethack / misc / nhk < prev    next >
Encoding:
Text File  |  1994-12-13  |  2.9 KB  |  101 lines

  1. #!/usr/exp/bin/perl
  2.  
  3. # nhk - nethack monster high scores (version 1.0)
  4. #
  5. # Copyright (C) 1993 by John J. Chew, III <jjchew@math.utoronto.ca>
  6. # Heavily edited by Boudewijn Wayers <dedos4@win.tue.nl>
  7. #
  8. # DESCRIPTION
  9. #
  10. # This program lists high scores for monsters, either by the number of
  11. # players that they have managed to kill, or by the total score of 
  12. # their victims.  
  13. #
  14. # BUGS
  15. #
  16. # - nhk has been tested only on our local files and may not correctly
  17. #   format unusual killers.  Please report bugs to the address above.
  18. # - nhk stands, for historical reasons, for NetHack Killers.  It does
  19. #   not stand for Nihon Housou Kyoku.
  20. #
  21. # The output looks like:
  22. #
  23. # 15 1218362 corpse
  24. #  2  229752 starvation
  25. #  2  189090 cockatrice
  26. #  3  164639 magic bolt
  27. #  1  134738 vampire lord
  28. #  2   73613 black pudding
  29. # 10   46236 rothe
  30. #  1   34126 death ray
  31. #  2   11243 Woodland-elf
  32. #  1    6460 giant beetle
  33. #  1    2529 burning book
  34. #  1    1454 iguana
  35.  
  36. # configuration variables
  37.  
  38. $CV_DEFAULT_DIRECTORY = '/home/svin04d/dedos4/bin/nethackdir';
  39. $CV_LOGFILE_NAME = 'logfile';
  40. $CV_RECORD_NAME = 'record';
  41.  
  42. sub usage {
  43.   warn "Usage: $0 [ -f file | -l | -r ] [ -n | -s ]\n\n";
  44.   warn "  -f  use indicated file\n";
  45.   warn "  -l  use logfile\n";
  46.   warn "  -r  use record (high score file) [default]\n";
  47.   warn "  -n  sort by number of kills\n";
  48.   warn "  -s  sort by aggregate victim score [default]\n";
  49.   exit 1;
  50.   }
  51.  
  52. require 'getopts.pl';
  53. &Getopts('f:lnrs') || &usage;
  54. (defined $opt_f) && $opt_l && $opt_r && &usage;
  55. $opt_n && $opt_s && &usage;
  56. $opt_n || $opt_s || ($opt_s = 1);
  57. $FILE = (defined $opt_f) ? $opt_f : 
  58.   $CV_DEFAULT_DIRECTORY . '/' . ($opt_l ? $CV_LOGFILE_NAME : $CV_RECORD_NAME);
  59.  
  60. (defined $opt_f) || $opt_l || ($opt_r = 1);
  61.  
  62. open(FILE, "<$FILE") || die "$0: cannot open $FILE";
  63. @file = <FILE>;
  64. close(FILE);
  65.  
  66. $killlen = 1;
  67. $scorelen = 1;
  68. for $_ (@file) {
  69.   chop;
  70.   # date uid deathdnum deathlev maxlvl hp maxhp points plchar sex name death
  71.   split(/ /, $_, 10); $_ = $_[9]; 
  72.   s/, the shopkeeper//;
  73.   s/.*,//;
  74.   s/(killed by|choked on|poisoned by|drowned in|crushed to death by|petrified by)( an?)? //; # see topten.c
  75.   s/hallucinogen-distorted |invisible //;
  76.   s/ called .*//;
  77.   s/priest(ess)?.*/priest(ess)/;
  78.   s/.* corpse/corpse/;
  79.   s/bolt of .*/magic bolt/;
  80.   s/fall onto |moat by a |.* of //;
  81.   $count{$_}++;
  82.   $killlen = length($count{$_}) if length($count{$_}) > $killlen;
  83.   $score{$_} += $_[7];
  84.   $scorelen = length($score{$_}) if length($score{$_}) > $scorelen;
  85.   }
  86.  
  87. sub mysort { 
  88.   ($A = $a) =~ tr/A-Z/a-z/; ($B = $b) =~ tr/A-Z/a-z/;
  89.   (($opt_n) ? $count{$b} <=> $count{$a} : $score{$b} <=> $score{$a}) 
  90.     || $A cmp $B;
  91.   }
  92.  
  93. for $key (sort mysort keys %count)
  94.   {
  95.   printf "%${killlen}d %${scorelen}d %${scorelen}d %s\n", $count{$key}, $score{$key}, $score{$key}/$count{$key}, $key;
  96.   }
  97.  
  98. exit 0;
  99. __END__
  100.  
  101.