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

push(@INC, "/mit/mkgray/project/prisoner/strategies");

foreach $strat (@ARGV){
    require $strat;
    $sn = substr($strat, 0, length($strat)-3);
    push(@s, $strat);
    $name{$strat} = $sn;
}

foreach $strategy1 (@s){
    foreach $strategy2 (@s){
	$s1o = $name{$strategy1};
	$s2o = $name{$strategy2};
	print "Running dilemma for $s1o and $s2o\n";
	$s1 = new $s1o;
	$s2 = new $s2o;

	$s1score = $s2score = 0;
	for (1..200){
	    $s1play = $s1->choose();
	    $s2play = $s2->choose();
	    
	    if($s1play eq "DEFECT"){
		if($s2play eq "COOPERATE"){
		    $s1score+=5;
		}
		else{
		    $s1score++;
		    $s2score++;
		}
	    }
	    else {
		if($s2play eq "COOPERATE"){
		    $s1score +=3;
		    $s2score +=3;
		}
		else {
		    $s2score+=5;
		}
	    }
		
	    $s1->record($s2play);
	    $s2->record($s1play);
	}
	$matches{$strategy1}++;
	$matches{$strategy2}++;
	$score{$strategy1} += $s1score;
	$score{$strategy2} += $s2score;
	if($s1score > $s2score){
	    $wins{$strategy1}++;
	}
	elsif($s2score > $s1score){
	    $wins{$strategy2}++;
	}
	foreach $st (@s){
	    print("$st ".($score{$st}/$matches{$st})."\n") unless $matches{$st} == 0;
	}
    }
}
