#!/usr/pkg/bin/perl
# $Id: player_info.in,v 1.4 1996/07/21 09:16:26 suz Exp $
## result format
##      NO  PNT  TN PN RN NN    TUMO        RON       FURI
#result: 3  -15  -3  9  3  0    5000  1   11600  2   10300  2

$filter = "cat";
$dir = "/usr/pkg/lib/netmaj";
$dir = $ENV{'NETMAJ_LIB'} if ($ENV{'NETMAJ_LIB'});
$player = $ENV{'LOGNAME'};
while($ARGV[0] ne "") {
	if ($ARGV[0] =~ /^(-[0-9]+)$/) {
		$tmp = $1 * 2;
		$filter = "tail $tmp";
	} elsif ($ARGV =~ /^(-directry|-d)$/) {
		$dir = $ARGV[1];
		shift(@ARGV);
	} else {
		$player = "$ARGV[0]" if ($ARGV[0]);
	}
	shift(@ARGV);
}


$yaku_name[0]="役満";
$yaku_name[1]="国士無双";
$yaku_name[2]="大三元";
$yaku_name[3]="四暗刻";
$yaku_name[4]="四槓子";
$yaku_name[5]="小四喜";
$yaku_name[6]="大四喜";
$yaku_name[7]="字一色";
$yaku_name[8]="緑一色";
$yaku_name[9]="九連宝燈";
$yaku_name[10]="天和";
$yaku_name[11]="地和";
$yaku_name[12]="清老頭";
$yaku_name[13]="人和(倍満)";
$yaku_name[14]="流し満貫";
$yaku_name[15]="ダブリー";
$yaku_name[16]="リーチ";
$yaku_name[17]="一発";
$yaku_name[18]="ツモ";
$yaku_name[19]="平和";
$yaku_name[20]="タンヤオ";
$yaku_name[21]="イイペイコ";
$yaku_name[22]="ハイテイ";
$yaku_name[23]="自風";
$yaku_name[24]="場風";
$yaku_name[25]="白";
$yaku_name[26]="発";
$yaku_name[27]="中";
$yaku_name[28]="チャンカン";
$yaku_name[29]="リンシャン";
$yaku_name[30]="三色(1)";
$yaku_name[31]="一通(1)";
$yaku_name[32]="チャンタ(1)";
$yaku_name[33]="三色(2)";
$yaku_name[34]="一通(2)";
$yaku_name[35]="チャンタ(2)";
$yaku_name[36]="三暗刻(2)";
$yaku_name[37]="三槓子(2)";
$yaku_name[38]="対々(2)";
$yaku_name[39]="小三元(2)";
$yaku_name[40]="混老頭";
$yaku_name[41]="三色同刻";
$yaku_name[42]="混一(2)";
$yaku_name[43]="純チャン(2)";
$yaku_name[44]="混一(3)";
$yaku_name[45]="純チャン(3)";
$yaku_name[46]="二ペイコウ(3)";
$yaku_name[47]="清一(5)";
$yaku_name[48]="清一(6)";
$yaku_name[49]="七対子(2)";
$yaku_name[50]="フリテン";
$yaku_name[51]="同順";
$yaku_name[52]="九種九牌";
$yaku_name[53]="四風連打";
$yaku_name[54]="四槓流れ";
$yaku_name[55]="三家和";
$yaku_name[56]="ノーテンリーチ";

opendir(DIR,$dir);
while ($file = readdir(DIR)) {
  if ($file =~ /(.*)\.pf/) {
    $name = $1;
    if ("$player" eq "ALL" || "$player" eq "$name") {
	  open(F,"$filter $dir/$file |");
	  $game = 0;
	  $juni[1] = 0;
	  $juni[2] = 0;
	  $juni[3] = 0;
	  $juni[4] = 0;
	  $pnt = 0;
	  $tn = 0;
	  $pn = 0;
	  $rn = 0;
	  $nn = 0;
	  $tumo_pnt = 0;
	  $tumo_cnt = 0;
	  $ron_pnt = 0;
	  $ron_cnt = 0;
	  $furi_pnt = 0;
	  $furi_cnt = 0;
	  for ($i=0; $i<60; $i++) {
		$yakus[$i] = 0;
	  }
	  while (<F>) {
		chop;
		if (/^result: /) {
			@r = split("[: \t]+");
			$game ++;
			$juni[$r[1]]++;
			$pnt += $r[2];
			$tn += $r[3];
			$pn += $r[4];
			$rn += $r[5];
			$nn += $r[6];
			$tumo_pnt += $r[7];
			$tumo_cnt += $r[8];
			$ron_pnt += $r[9];
			$ron_cnt += $r[10];
			$furi_pnt += $r[11];
			$furi_cnt += $r[12];
		}
		if (/^yaku: /) {
			@tmp = split('',$');
			for ($i=0; $i<60; $i++) {
				$yakus[$i] += $tmp[$i];
			}
		}
	  }
	  if ($pn > 0) {
	    printf("player name    : %s\n",$name);
	    printf("total game     : %d\n",$game);
	    printf("total play     : %d\n",$pn);
	    printf("total point    : %d\n",$pnt);
	    printf("total tip      : %d\n",$tn);
	    printf("total money    : %d\n",($pnt * 100) + ($tn * 500));
	    printf("#1 cnt         : %5.2f %%\n",(100.0 * $juni[1]) / $game);
	    printf("#2 cnt         : %5.2f %%\n",(100.0 * $juni[2]) / $game);
	    printf("#3 cnt         : %5.2f %%\n",(100.0 * $juni[3]) / $game);
	    printf("#4 cnt         : %5.2f %%\n",(100.0 * $juni[4]) / $game);
	    printf("reach cnt      : %5.2f %%\n",(100.0 * $rn) / $pn);
	    printf("naki  cnt      : %5.2f %%\n",(100.0 * $nn) / $pn);
	    printf("tumo  cnt      : %5.2f %%\n",(100.0 * $tumo_cnt) /$pn);
	    printf("ron   cnt      : %5.2f %%\n",(100.0 * $ron_cnt) /$pn);
	    printf("furi  cnt      : %5.2f %%\n",(100.0 * $furi_cnt) /$pn);
	    printf("tumo point(ave): %d\n",$tumo_pnt/$tumo_cnt) if ($tumo_cnt > 0);
	    printf("ron  point(ave): %d\n",$ron_pnt/$ron_cnt) if ($ron_cnt > 0);
	    printf("furi point(ave): %d\n",$furi_pnt/$furi_cnt) if ($furi_cnt > 0);
	    for ($i = 0; $i < 60; $i++) {
		if ($yakus[$i] > 0) {
			printf("\t%-16s: %d\n",$yaku_name[$i],$yakus[$i]);
			}
	    }
	    printf("%s\n","-" x 60);
	}
    }
  }
}
closedir(DIR);
