use strict; use warnings; sub mean { my $sum = 0; foreach (@_) { $sum += $_; } return $sum / @_; } sub variance { my $total = 0; my $avg = mean(@_); foreach (@_) { $total += ($_ - $avg)*($_ - $avg); } return $total / (@_ - 1); } sub stdDev { return sqrt(variance(@_)); } my @botNames = ("dpp", "akuma", "dcu3pl", "HyperboreanRing-Eqm", "HyperboreanRing-BR", "Bluechip", "CMURingLimit"); my @team1 = (0, 1); my @team2 = (3, 4); my $numBotsLeft = 7; my $line; my @tokens; my $resfile; my $rowbot; my $bot2; my $bot3; print "Number of iterations: "; my $numIterations = <>; chomp($numIterations); print "\nUsing ", $numIterations, " iterations\n"; my $columnNumber; my @columnTitles; $columnNumber = -1; for ($bot2 = 0; $bot2 < $numBotsLeft; $bot2++) { for ($bot3 = $bot2+1; $bot3 < $numBotsLeft; $bot3++) { $columnNumber++; $columnTitles[$columnNumber] = $botNames[$bot2].", ".$botNames[$bot3]; } } print "There are ", $columnNumber+1, " columns\n"; #declare the results array here, where the rows are the bots and the columns how they did against all the possible matchups my @results; my @numMatchesPlayed; for ($rowbot = 0; $rowbot < $numBotsLeft; $rowbot++) { $columnNumber = -1; $numMatchesPlayed[$rowbot] = 0; my @columnResults; $results[$rowbot] = \@columnResults; for ($bot2 = 0; $bot2 < $numBotsLeft; $bot2++) { for ($bot3 = $bot2+1; $bot3 < $numBotsLeft; $bot3++) { #make sure these are three seperate bots if ($rowbot != $bot2 && $bot2 != $bot3 && $rowbot != $bot3) { $columnNumber++; #Tracks which column we're currently filling if ($rowbot == $team1[0] || $bot2 == $team1[0] || $bot3 == $team1[0]) { if ($rowbot == $team1[1] || $bot2 == $team1[1] || $bot3 == $team1[1]) { $columnResults[$columnNumber] = 0; next; } } if ($rowbot == $team2[0] || $bot2 == $team2[0] || $bot3 == $team2[0]) { if ($rowbot == $team2[1] || $bot2 == $team2[1] || $bot3 == $team2[1]) { $columnResults[$columnNumber] = 0; next; } } #different from columnNumber, indicates how many matches we played (didn't skip due to 2 from a team) #ALSO it starts at 1 instead of 0 for columnNumber $numMatchesPlayed[$rowbot]++; #Otherwise loop through all iterations adding up the result my @iterationResults; $columnResults[$columnNumber] = \@iterationResults; for (my $i = 0; $i < $numIterations; $i++) { $iterationResults[$i] = 0; #Now I need to get the results of all 6 configurations of these 3 bots $resfile = "ring".$i.".".$botNames[$rowbot].".".$botNames[$bot2].".".$botNames[$bot3].".res"; eval { open FILE, $resfile or die $!; }; if ($@) { print $resfile, " does not exist!!\n"; exit 0; } $line = ; chomp($line); #print($line, "\n"); @tokens = split(/\|+/, $line); $iterationResults[$i] += $tokens[0]; close(FILE); $resfile = "ring".$i.".".$botNames[$rowbot].".".$botNames[$bot3].".".$botNames[$bot2].".res"; eval { open FILE, $resfile or die $!; }; if ($@) { print $resfile, " does not exist!!\n"; exit 0; } $line = ; chomp($line); #print($line, "\n"); @tokens = split(/\|+/, $line); $iterationResults[$i] += $tokens[0]; close(FILE); $resfile = "ring".$i.".".$botNames[$bot2].".".$botNames[$rowbot].".".$botNames[$bot3].".res"; eval { open FILE, $resfile or die $!; }; if ($@) { print $resfile, " does not exist!!\n"; exit 0; } $line = ; chomp($line); #print($line, "\n"); @tokens = split(/\|+/, $line); $iterationResults[$i] += $tokens[1]; close(FILE); $resfile = "ring".$i.".".$botNames[$bot2].".".$botNames[$bot3].".".$botNames[$rowbot].".res"; eval { open FILE, $resfile or die $!; }; if ($@) { print $resfile, " does not exist!!\n"; exit 0; } $line = ; chomp($line); #print($line, "\n"); @tokens = split(/\|+/, $line); $iterationResults[$i] += $tokens[2]; close(FILE); $resfile = "ring".$i.".".$botNames[$bot3].".".$botNames[$rowbot].".".$botNames[$bot2].".res"; eval { open FILE, $resfile or die $!; }; if ($@) { print $resfile, " does not exist!!\n"; exit 0; } $line = ; chomp($line); #print($line, "\n"); @tokens = split(/\|+/, $line); $iterationResults[$i] += $tokens[1]; close(FILE); $resfile = "ring".$i.".".$botNames[$bot3].".".$botNames[$bot2].".".$botNames[$rowbot].".res"; eval { open FILE, $resfile or die $!; }; if ($@) { print $resfile, " does not exist!!\n"; exit 0; } $line = ; chomp($line); #print($line, "\n"); @tokens = split(/\|+/, $line); $iterationResults[$i] += $tokens[2]; close(FILE); #Now convert iteration results to small bets per hand, instead of small blinds per 6000 hands $iterationResults[$i] /= 12000; } #end loop over iterations } #if they're different bots } #bot3 } #bot2 print "Column number: $columnNumber\n"; print "Matches played: $numMatchesPlayed[$rowbot]\n"; #calculate the mean of this column my @finalRow; $results[$rowbot]->[$columnNumber+1] = \@finalRow; for (my $i = 0; $i < $numIterations; $i++) { $columnNumber = -1; #set $results[$rowbot]->[$columnNumber]->[$i] to the mean of iteration $i: $finalRow[$i] = 0; for ($bot2 = 0; $bot2 < $numBotsLeft; $bot2++) { for ($bot3 = $bot2+1; $bot3 < $numBotsLeft; $bot3++) { #make sure these are three seperate bots if ($rowbot != $bot2 && $bot2 != $bot3 && $rowbot != $bot3) { $columnNumber++; #Tracks which column we're currently filling if ($rowbot == $team1[0] || $bot2 == $team1[0] || $bot3 == $team1[0]) { if ($rowbot == $team1[1] || $bot2 == $team1[1] || $bot3 == $team1[1]) { $columnResults[$columnNumber] = 0; next; } } if ($rowbot == $team2[0] || $bot2 == $team2[0] || $bot3 == $team2[0]) { if ($rowbot == $team2[1] || $bot2 == $team2[1] || $bot3 == $team2[1]) { $columnResults[$columnNumber] = 0; next; } } $finalRow[$i] += $results[$rowbot]->[$columnNumber]->[$i]; } } } $finalRow[$i] /= $numMatchesPlayed[$rowbot]; } } #Now write the results to the html file open (HTMLFILE, '>>ringResults.html'); print HTMLFILE ("\n"); # first row print HTMLFILE ("\n"); foreach (@columnTitles) { print HTMLFILE ("\n"); } print HTMLFILE ("\n"); my $j; my $meanValue; my $estimateStdDev; # each row for (my $rowbot = 0; $rowbot < $numBotsLeft; $rowbot++) { $j = 0; print HTMLFILE (""); # each column print HTMLFILE (""); for ($bot2 = 0; $bot2 < $numBotsLeft; $bot2++) { for ($bot3 = $bot2+1; $bot3 < $numBotsLeft; $bot3++) { #make sure these are three seperate bots if (!($rowbot != $bot2 && $bot2 != $bot3 && $rowbot != $bot3)) { #Gray this out, this match doesn't exist print HTMLFILE (""); next; } if ($rowbot == $team1[0] || $bot2 == $team1[0] || $bot3 == $team1[0]) { if ($rowbot == $team1[1] || $bot2 == $team1[1] || $bot3 == $team1[1]) { print HTMLFILE (""); $j++; next; } } if ($rowbot == $team2[0] || $bot2 == $team2[0] || $bot3 == $team2[0]) { if ($rowbot == $team2[1] || $bot2 == $team2[1] || $bot3 == $team2[1]) { print HTMLFILE (""); $j++; next; } } $meanValue = mean(@{$results[$rowbot]->[$j]}); $estimateStdDev = stdDev(@{$results[$rowbot]->[$j]}) / sqrt($numIterations); my $colorSignificance = 1; if ($colorSignificance){ #my significance = Math.abs(meanValue)/estimateStdDev; #int colorSignificance = (int)(255.0 * (1.0-(significance/4.0))); if (abs($meanValue)<$estimateStdDev*2.0){ if( $meanValue > 0 ){ print HTMLFILE ( "\n"); $j++; }#bot3 }#bot2 $meanValue = mean(@{$results[$rowbot]->[$j]}); $estimateStdDev = stdDev(@{$results[$rowbot]->[$j]}) / sqrt($numIterations); $meanValue *= 1000; $meanValue = int($meanValue + 0.5); $meanValue /= 1000; $estimateStdDev *= 1000; $estimateStdDev = int($estimateStdDev + 0.5); $estimateStdDev /= 1000; print HTMLFILE ("\n\n"); print HTMLFILE ("\n"); } print HTMLFILE ("
" , $_ , "
" , $botNames[$rowbot], " "); } else { print HTMLFILE ( ""); } } else { if( $meanValue > 0 ){ print HTMLFILE ( ""); } else { print HTMLFILE ( ""); } } } else { if( $meanValue > 0 ){ print HTMLFILE ( ""); } else { print HTMLFILE ( ""); } } $meanValue *= 1000; $meanValue = int($meanValue + 0.5); $meanValue /= 1000; print HTMLFILE ($meanValue); $estimateStdDev *= 1000; $estimateStdDev = int($estimateStdDev + 0.5); $estimateStdDev /= 1000; print HTMLFILE ( " ± " , $estimateStdDev); print HTMLFILE ( " " , $meanValue); print HTMLFILE ( " ± " , $estimateStdDev); print HTMLFILE ( "
"); close(HTMLFILE);