+ if verbose:
+ sys.stdout.write(" Valid! (To run: \""+agentExecutable+"\")\n")
+
+ #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":[]})
+ if len(agents) == 0:
+ print "Couldn't find any agents! Check paths (Edit this script) or generate \"info\" files for agents."
+ sys.exit(0)
+ if verbose:
+ print "Total: " + str(len(agents)) + " valid agents found (From "+str(len(agentNames))+" possibilities)"
+ print ""
+ print "Commencing ROUND " + str(roundNumber) + " combat! This could take a while... "
+
+
+ normalGames = 0
+ draws = 0
+ aiErrors = 0
+ managerErrors = 0
+ #This double for loop simulates a round robin, with each agent getting the chance to play as both red and blue against every other agent.
+ gameID = 0
+ for red in agents: #for each agent playing as red,
+ for blue in agents: #against each other agent, playing as blue
+ if red == blue:
+ continue #Exclude battles against self
+ gameID += 1
+ for i in range(1, nGames/2 + 1):
+ #Play a game and read the result. Note the game is logged to a file based on the agent's names
+ if verbose:
+ sys.stdout.write("Agents: \""+red["name"]+"\" and \""+blue["name"]+"\" playing game " + str(i) + "/"+str(nGames/2) + "... ")
+ logFile = logDirectory + "round"+str(roundNumber) + "/"+red["name"]+".vs."+blue["name"]+"."+str(i)
+ outline = os.popen(managerPath + " -o " + logFile + " " + red["path"] + " " + blue["path"], "r").read()
+ results = outline.split(' ')
+
+ if len(results) != 6:
+ if verbose:
+ sys.stdout.write("Garbage output! \"" + outline + "\"\n")
+ red["manager_errors"].append((gameID, blue["name"]))
+ managerErrors += 1
+ else:
+
+ if results[1] == "RED":
+ endColour = red
+ otherColour = blue
+ elif results[1] == "BLUE":
+ endColour = blue
+ otherColour = red
+ if results[1] == "BOTH":
+ pass
+ else:
+ endColour["score"].insert(0,endColour["score"][0] + scores[results[2]][0])
+ endColour[results[2]].append((otherColour["name"], gameID, scores[results[2]][0]))
+ otherColour["score"].insert(0, otherColour["score"][0] + scores[results[2]][1])
+ otherColour[scores[results[2]][2]].append((endColour["name"], gameID, scores[results[2]][1]))
+
+ if verbose:
+ sys.stdout.write(" Result \"")
+ for ii in range(1, len(results)):
+ sys.stdout.write(results[ii].strip())
+ if ii < (len(results) - 1):
+ sys.stdout.write(" ")
+ sys.stdout.write("\"\n")