#!/afs/athena/contrib/perl/perl

$warriordir = '/afs/sipb/user/mkgray/redcode/';
@warriors = @ARGV;
@opponents = ('all/eclipse', 'all/herem', 'all/imprimis', 'all/leprechaun', 'all/moonstone', 'all/agony4', 'all/medusa', 'all/stormbringer', 'all/sphinx', 'all/sucker5', 'all/paratroops', 'all/newshears');
$m = `machtype`;
chop($m);
$m .= 'bin';

foreach $warrior (@warriors) {
    foreach $owarrior (@opponents){
	print("Battling $warrior vs. $owarrior\n");
	$battle = `/afs/sipb/project/corewars/koth/$m/koth -rounds 100 $warrior $warriordir$owarrior`;
	@scores=split(/[ \n]/, $battle);
	$wins = $scores[0];
	$ties = $scores[1];
	$owins = $scores[3];
	print("$warrior: $wins, $owarrior: $owins, tie: $ties\n");
	$rating{$warrior} += (3*int($wins));
	$n = (3*int($wins));
	$rating{$warrior} += (int($ties));
	$rating{$owarrior} += (int($ties));
	$rating{$owarrior} += (3*int($owins));
	$t++;
    }
}
for $w (@warriors){
    $score = $rating{$w};
    $score /= ($t*3);
    $score = int($score);
    print("$w: $score\n");
}
