#!/usr/bin/perl my $save_dir = "test"; my @ROUNDS = @ARGV; if(@ROUNDS < 1){ print "Usage: score-noise.pl <# rounds> [<# rounds> ...]\n"; print "Ex: score-noise.pl 20, 40, 80, 160, 320, 640, 1280, 2560\n"; exit; } print "Testing: "; for $rnd (@ROUNDS){ print "$rnd, "; } print "Rounds\n"; printf("Opening directory: $save_dir\n"); opendir(DIR, $save_dir); @BENCH = grep { !(/^\./) && -f "$save_dir/$_" } readdir(DIR); close DIR; $bench = @BENCH; printf("Got %d entries from $save_dir\n", $bench); if($bench < 1) { print "No warriors to test!\n"; exit; } $ps = &perfect_bench_warrior($BENCH[0], \@BENCH); print "Got PS of $ps\n"; foreach $nrnds (@ROUNDS){ for($j = 0; $j < 100; $j++){ $ns += abs(&noisy_bench_warrior($BENCH[0], \@BENCH, $nrnds) - $ps); } $ns = $ns / 100; print "Rnds: $nrnds Noise: $ns\n"; } sub perfect_bench_warrior{ my ($name, $BENCH) = @_; for(my $j = 0; $j < @$BENCH; $j++){ my $first = 0; open(PMARS,"./pmars -s 80 -c 800 -p 80 -d 5 -l 5 -P -b -k $save_dir/$name $save_dir/$$BENCH[$j]|"); while () { #Get scores chomp; my($Wins, $Ties) = split; if($first == 0){ $owin = $Wins; $otie = $Ties; $owin = ($owin * 3) + $otie; $first++; } else { $bwin = $Wins; $btie = $Ties; $bwin = ($bwin * 3) + $btie; last; } } $score += $owin; close(PMARS); } $score = $score / @$BENCH; return $score; } sub noisy_bench_warrior{ my ($name, $BENCH, $rounds) = @_; $score = 0; for(my $j = 0; $j < @$BENCH; $j++){ my $first = 0; open(PMARS,"./pmars -s 80 -c 800 -p 80 -d 5 -l 5 -r $rounds -b -k $save_dir/$name $save_dir/$$BENCH[$j]|"); while () { #Get scores chomp; my($Wins, $Ties) = split; if($first == 0){ $owin = $Wins; $otie = $Ties; $owin = ($owin * 3) + $otie; $first++; } else { $bwin = $Wins; $btie = $Ties; $bwin = ($bwin * 3) + $btie; last; } } $score += $owin; close(PMARS); } $score = $score / @$BENCH; $score = $score / $rounds; $score = $score * 142; return $score; }