+ 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) + "... ")
+
+ agents.sort(key = lambda e : e["score"], reverse=True) #Sort the agents based on score
+
+ resultsFile = open(resultsDirectory+"round"+str(roundNumber)+".results", "w") #Create a file to store all the scores for this round
+ for agent in agents:
+ resultsFile.write(agent["name"] + " " + str(agent["score"]) +"\n") #Write the agent names and scores into the file, in descending order
+
+ if verbose:
+ sys.stdout.write(" Complete!\n")
+ sys.stdout.write("Updating total scores... ");
+
+ #Now update the total scores
+ if os.path.exists(resultsDirectory+"total.scores"):
+ if verbose:
+ sys.stdout.write(" Reading from \""+resultsDirectory+"total.scores\" to update scores... ")
+ totalFile = open(resultsDirectory+"total.scores", "r") #Try to open the total.scores file
+ for line in totalFile: #For all entries,
+ data = line.split(' ')
+ for agent in agents:
+ if agent["name"] == data[0]:
+ agent["totalScore"] = int(data[1]) + agent["score"][0] #Simply increment the current score by the recorded total score of the matching file entry
+ break
+ totalFile.close() #Close the file, so we can delete it
+ os.remove(resultsDirectory+"total.scores") #Delete the file
+ #Sort the agents again
+ agents.sort(key = lambda e : e["totalScore"], reverse=True)
+
+ else:
+ if verbose:
+ sys.stdout.write(" First round - creating \""+resultsDirectory+"total.scores\"... ")
+ if verbose:
+ 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)
+
+
+ if verbose:
+ print "Updating pretty .html files... "
+
+ for agent in agents:
+ agentFile = open(resultsDirectory + agent["name"]+".html", "a")
+ agentFile.write("<h2> Round " + str(roundNumber) + "</h2>\n")
+ agentFile.write("<h3> Round Overview </h3>\n")
+ agentFile.write("<table border=\"0\" cellpadding=\"10\">\n")
+ agentFile.write("<tr> <th> Score </th> <th> Wins </th> <th> Losses </th> <th> Draws </th> <th> Illegal </th> <th> Errors </th></tr>\n")
+ agentFile.write("<tr> <td> "+str(agent["score"][0])+" </td> <td> "+str(len(agent["VICTORY"]) + len(agent["DEFAULT"]))+" </td> <td> "+str(len(agent["DEFEAT"]) + len(agent["SURRENDER"]))+" </td> <td> "+str(len(agent["DRAW"]) + len(agent["DRAW_DEFAULT"]))+" </td> <td> "+str(len(agent["ILLEGAL"]) + len(agent["BOTH_ILLEGAL"]) + len(agent["BAD_SETUP"]))+" </td> <td> " +str(len(agent["INTERNAL_ERROR"]))+" </td> </tr>\n")
+
+ agentFile.write("</table>\n")
+ agentFile.write("<p> <a href=round"+str(roundNumber)+".html>Round "+str(roundNumber) + " Scoreboard</a></p>\n")
+
+ agentFile.write("<h3> Detailed </h3>\n")
+ agentFile.write("<table border=\"0\" cellpadding=\"10\">\n")
+ agentFile.write("<tr> <th> Game ID </th> <th> Opponent </th> <th> Played as </th> <th> Outcome </th> <th> Score </th> <th> Accumulated Score </th> </tr> </th>\n")
+
+
+
+ for index in range(0, len(agent["ALL"])):
+ if agent["ALL"][index][4] == "RED":
+ logFile = logDirectory + "round"+str(roundNumber) + "/"+agent["name"]+".vs."+agent["ALL"][index][0]+"."+str(agent["ALL"][index][1])
+ else:
+ logFile = logDirectory + "round"+str(roundNumber) + "/"+agent["ALL"][index][0]+".vs."+agent["name"]+"."+str(agent["ALL"][index][1])
+ agentFile.write("<tr> <td> <a href="+logFile+">" + str(agent["ALL"][index][1]) + " </a> </td> <td> <a href="+agent["ALL"][index][0]+".html>"+agent["ALL"][index][0] + " </a> </td> <td> " + agent["ALL"][index][4] + " </td> <td> " + agent["ALL"][index][3] + " </td> <td> " + str(agent["ALL"][index][2]) + "</td> <td> " + str(agent["score"][len(agent["score"])-index -2]) + " </td> </tr> </th>\n")
+ agentFile.write("</table>\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("<h3> Accumulated Results </h3>\n")
+ agentFile.write("<table border=\"0\" cellpadding=\"10\">\n")
+ agentFile.write("<tr> <th> Score </th> <th> Wins </th> <th> Losses </th> <th> Draws </th> <th> Illegal </th> <th> Errors </th></tr>\n")
+ agentFile.write("<tr> <td> "+str(agent["totalScore"])+" </td> <td> "+str(agent["Wins"])+" </td> <td> "+str(agent["Losses"])+" </td> <td> "+str(agent["Draws"])+" </td> <td> "+str(agent["Illegal"])+" </td> <td> " +str(agent["Errors"])+" </td> </tr>\n")
+
+ agentFile.write("</table>\n")
+
+
+ agentFile.close()
+
+ #Update round file
+ roundFile = open(resultsDirectory + "round"+str(roundNumber)+".html", "w")
+ roundFile.write("<html>\n<head>\n <title> Round " +str(roundNumber)+ " Overview </title>\n</head>\n<body>\n")
+ roundFile.write("<h1> Round " +str(roundNumber)+ " Overview </h1>\n")
+ roundFile.write("<table border=\"0\" cellpadding=\"10\">\n")
+ roundFile.write("<tr> <th> Name </th> <th> Score </th> <th> Total Score </th> </tr>\n")
+ agents.sort(key = lambda e : e["score"][0], reverse=True)
+ for agent in agents:
+ roundFile.write("<tr> <td> <a href="+agent["name"]+".html>"+agent["name"] + " </a> </td> <td> " + str(agent["score"][0]) + " </td> <td> " + str(agent["totalScore"]) + " </td> </tr>\n")
+ roundFile.write("</table>\n")
+ roundFile.write("<p> <a href=total.html>Current Scoreboard</a></p>\n")
+ roundFile.write("</body>\n<!-- Results file for Round " + str(roundNumber) + " autogenerated by \"" + sys.argv[0] + "\" at time " + str(time()) + " -->\n</html>\n\n")
+ roundFile.close()
+
+
+
+
+