X-Git-Url: https://git.ucc.asn.au/?p=progcomp2012.git;a=blobdiff_plain;f=progcomp%2Fjudge%2Fsimulator%2Fsimulate.py;h=9b79194e686c043a3ff47059eb4367c9b0111c25;hp=5ad64485a46f91ea9a8816840f47c4c7fb9e21ba;hb=6e5327743543d606ff88e4a8228989460f8a5a30;hpb=e1a5a224763b1374c8dff6dcc2f5d85c15335eae diff --git a/progcomp/judge/simulator/simulate.py b/progcomp/judge/simulator/simulate.py index 5ad6448..9b79194 100755 --- a/progcomp/judge/simulator/simulate.py +++ b/progcomp/judge/simulator/simulate.py @@ -65,10 +65,16 @@ if os.path.exists(managerPath) == False: if os.path.exists(resultsDirectory) == False: os.mkdir(resultsDirectory) #Make the results directory if it didn't exist +''' + Obselete older version doesn't work with new .html files #Identify the round number by reading the results directory totalRounds = len(os.listdir(resultsDirectory)) + 1 if totalRounds > 1: totalRounds -= 1 +''' + +totalRounds = 1 +#TODO: Fix this bit! if os.path.exists(logDirectory) == False: os.mkdir(logDirectory) #Make the log directory if it didn't exist @@ -85,7 +91,6 @@ if verbose: print "Identifying possible agents in \""+agentsDirectory+"\"" #Get all agent names from agentsDirectory -#TODO: Move this part outside the loop? It only has to happen once agentNames = os.listdir(agentsDirectory) agents = [] for name in agentNames: @@ -114,7 +119,7 @@ for name in agentNames: #Convert array of valid names into array of dictionaries containing information about each agent #I'm starting to like python... - agents.append({"name":name, "path":agentExecutable,"score":[0], "totalScore":0, "VICTORY":[], "DEFEAT":[], "DRAW":[], "ILLEGAL":[], "INTERNAL_ERROR":[], "ALL":[]}) + agents.append({"name":name, "path":agentExecutable, "score":[0], "VICTORY":[], "DEFEAT":[], "DRAW":[], "ILLEGAL":[], "DEFAULT":[], "INTERNAL_ERROR":[], "SURRENDER":[], "DRAW_DEFAULT":[], "BOTH_ILLEGAL":[], "BAD_SETUP":[], "ALL":[], "totalScore":0, "Wins":0, "Losses":0, "Draws":0, "Illegal":0, "Errors":0}) if len(agents) == 0: print "Couldn't find any agents! Check paths (Edit this script) or generate \"info\" files for agents." @@ -124,6 +129,8 @@ if verbose: print "" #Prepare the pretty .html files if they don't exist +if verbose: + print "Preparing .html results files..." htmlDir = resultsDirectory + "pretty/" if os.path.exists(htmlDir) == False: os.mkdir(htmlDir) @@ -139,16 +146,37 @@ for agent in agents: os.rename(htmlDir+agent["name"] + ".html", "tmpfile") - oldFile = open("tmpfile") + oldFile = open("tmpfile", "r") agentFile = open(htmlDir+agent["name"] + ".html", "w") - for line in oldFile: + line = oldFile.readline() + while line != "": + #if verbose: + # print "Interpreting line \"" + line.strip() + "\"" if line.strip() == "": break - agentFile.write(line.strip() + "\n") + elif line == " Score Wins Losses Draws Illegal Errors \n": + agentFile.write(line) + line = oldFile.readline() + + values = line.split(' ') + agent["totalScore"] += int(values[2].strip()) + agent["Wins"] += int(values[5].strip()) + agent["Losses"] += int(values[8].strip()) + agent["Draws"] += int(values[11].strip()) + agent["Illegal"] += int(values[14].strip()) + agent["Errors"] += int(values[17].strip()) + agentFile.write(line) + line = oldFile.readline() + + if verbose: + print "Prepared results file \"" + htmlDir+agent["name"] + ".html\"." oldFile.close() agentFile.close() os.remove("tmpfile") +if verbose: + print "" + #Do each round... totalGames = nGames/2 * len(agents) * (len(agents)-1) for roundNumber in range(totalRounds, totalRounds + nRounds): @@ -156,6 +184,9 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): if os.path.exists(logDirectory + "round"+str(roundNumber)) == False: os.mkdir(logDirectory + "round"+str(roundNumber)) #Check there is a directory for this round's logs + for agent in agents: + agent.update({"name":agent["name"], "path":agent["path"], "score":[0], "VICTORY":[], "DEFEAT":[], "DRAW":[], "ILLEGAL":[], "DEFAULT":[], "INTERNAL_ERROR":[], "SURRENDER":[], "DRAW_DEFAULT":[], "BOTH_ILLEGAL":[], "BAD_SETUP":[], "ALL":[]}) + print "Commencing ROUND " + str(roundNumber) + " combat!" print "Total: " + str(totalGames) + " games to be played. This could take a while... (Estimate 60s/game)" @@ -233,6 +264,8 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): print "" #We should now have complete score values. + ''' + Obselete, non prettified results if verbose: sys.stdout.write("Creating raw results files for ROUND " + str(roundNumber) + "... ") @@ -269,28 +302,27 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): sys.stdout.write(" Complete!\n") print "Finished writing results for ROUND " + str(roundNumber) print "" - + ''' if verbose: print "RESULTS FOR ROUND " + str(roundNumber) - totalFile = open(resultsDirectory+"total.scores", "w") #Recreate the file - for agent in agents: - totalFile.write(agent["name"] + " " + str(agent["totalScore"]) +"\n") #Write the total scores in descending order - if verbose: - print "Agent: " + str(agent) + #totalFile = open(resultsDirectory+"total.scores", "w") #Recreate the file + for agent in agents: + #totalFile.write(agent["name"] + " " + str(agent["totalScore"]) +"\n") #Write the total scores in descending order + #if verbose: + print "Agent: " + str(agent) + if verbose: print "Updating pretty .html files... " - - for agent in agents: agentFile = open(htmlDir + agent["name"]+".html", "a") agentFile.write("

Round " + str(roundNumber) + "

\n") - agentFile.write("

Summary

\n") + agentFile.write("

Round Overview

\n") agentFile.write("\n") agentFile.write("\n") - agentFile.write("\n") + agentFile.write("\n") agentFile.write("
Score Wins Losses Draws Illegal Errors
"+str(agent["score"][0])+" "+str(len(agent["VICTORY"]))+" "+str(len(agent["DEFEAT"]))+" "+str(len(agent["DRAW"]))+" "+str(len(agent["ILLEGAL"]))+" " +str(len(agent["INTERNAL_ERROR"]))+"
"+str(agent["score"][0])+" "+str(len(agent["VICTORY"]) + len(agent["DEFAULT"]))+" "+str(len(agent["DEFEAT"]) + len(agent["SURRENDER"]))+" "+str(len(agent["DRAW"]) + len(agent["DRAW_DEFAULT"]))+" "+str(len(agent["ILLEGAL"]) + len(agent["BOTH_ILLEGAL"]) + len(agent["BAD_SETUP"]))+" " +str(len(agent["INTERNAL_ERROR"]))+"
\n") @@ -301,16 +333,62 @@ for roundNumber in range(totalRounds, totalRounds + nRounds): for index in range(0, len(agent["ALL"])): agentFile.write(" " + str(agent["ALL"][index][1]) + " "+agent["ALL"][index][0] + " " + agent["ALL"][index][4] + " " + agent["ALL"][index][3] + " " + str(agent["ALL"][index][2]) + " " + str(agent["score"][len(agent["score"])-index -2]) + " \n") agentFile.write("\n") + + agent["totalScore"] += agent["score"][0] + agent["Wins"] += len(agent["VICTORY"]) + len(agent["DEFAULT"]) + agent["Losses"] += len(agent["DEFEAT"]) + len(agent["SURRENDER"]) + agent["Draws"] += len(agent["DRAW"]) + len(agent["DRAW_DEFAULT"]) + agent["Illegal"] += len(agent["ILLEGAL"]) + len(agent["BOTH_ILLEGAL"]) + len(agent["BAD_SETUP"]) + agent["Errors"] += len(agent["INTERNAL_ERROR"]) + + agentFile.write("

Accumulated Results

\n") + agentFile.write("\n") + agentFile.write("\n") + agentFile.write("\n") + + agentFile.write("
Score Wins Losses Draws Illegal Errors
"+str(agent["totalScore"])+" "+str(agent["Wins"])+" "+str(agent["Losses"])+" "+str(agent["Draws"])+" "+str(agent["Illegal"])+" " +str(agent["Errors"])+"
\n") agentFile.close() + + #Update round file + roundFile = open(htmlDir + "round"+str(roundNumber)+".html", "w") + roundFile.write("\n\n Round " +str(roundNumber)+ " Overview \n\n\n") + roundFile.write("

Round " +str(roundNumber)+ " Overview

\n") + roundFile.write("\n") + roundFile.write("\n") + agents.sort(key = lambda e : e["score"][0], reverse=True) + for agent in agents: + roundFile.write("\n") + roundFile.write("
Name Score Total Score
"+agent["name"] + " " + str(agent["score"][0]) + " " + str(agent["totalScore"]) + "
\n\n\n\n\n") + roundFile.close() + + + if verbose: print "Finalising .html files... " for agent in agents: agentFile = open(htmlDir + agent["name"]+".html", "a") + + #Write the "total" statistics + agentFile.write("\n\n\n\n") agentFile.close() + if os.path.exists(htmlDir + "total.html") == True: + os.remove(htmlDir + "total.html") #Delete the file + +totalFile = open(htmlDir + "total.html", "w") +totalFile.write("\n\n Total Overview \n\n\n") +totalFile.write("

Total Overview

\n") +totalFile.write("\n") +totalFile.write("\n") +agents.sort(key = lambda e : e["totalScore"], reverse=True) +for agent in agents: + totalFile.write("\n") +totalFile.write("
Name Total Score
"+agent["name"] + " " + str(agent["totalScore"]) + "
\n\n\n\n\n") +totalFile.close() + if verbose: print "Done!"