+ 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)"
+
+
+
+ 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.
+ gameNumber = 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
+ gameNumber += 1
+ gameID = str(roundNumber) + "." + str(gameNumber)
+ 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 (ID: " + gameID + ") ... ")
+ 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["INTERNAL_ERROR"].append((blue["name"], gameID, scores["INTERNAL_ERROR"][0]))
+ blue["INTERNAL_ERROR"].append((red["name"], gameID, scores["INTERNAL_ERROR"][0]))
+ red["ALL"].append((blue["name"], gameID, scores["INTERNAL_ERROR"][0], "INTERNAL_ERROR"))
+ blue["ALL"].append((red["name"], gameID, scores["INTERNAL_ERROR"][0], "INTERNAL_ERROR"))
+ managerErrors += 1
+ else:
+
+ if results[1] == "RED":
+ endColour = red
+ otherColour = blue
+ endStr = "RED"
+ otherStr = "BLUE"
+ elif results[1] == "BLUE":
+ endColour = blue
+ otherColour = red
+ endStr = "BLUE"
+ otherStr = "RED"
+
+
+ if results[1] == "BOTH":
+ red["INTERNAL_ERROR"].append((blue["name"], gameID, scores["INTERNAL_ERROR"][0]))
+ blue["INTERNAL_ERROR"].append((red["name"], gameID, scores["INTERNAL_ERROR"][0]))
+ red["ALL"].append((blue["name"], gameID, scores["INTERNAL_ERROR"][0], "INTERNAL_ERROR", "RED"))
+ blue["ALL"].append((red["name"], gameID, scores["INTERNAL_ERROR"][0], "INTERNAL_ERROR", "BLUE"))
+ managerErrors += 1
+ else:
+ endColour["score"].insert(0,endColour["score"][0] + scores[results[2]][0])
+ endColour[results[2]].append((otherColour["name"], gameID, scores[results[2]][0]))
+ endColour["ALL"].append((otherColour["name"], gameID, scores[results[2]][0], results[2], endStr))
+ otherColour["score"].insert(0, otherColour["score"][0] + scores[results[2]][1])
+ otherColour[scores[results[2]][2]].append((endColour["name"], gameID, scores[results[2]][1]))
+ otherColour["ALL"].append((endColour["name"], gameID, scores[results[2]][1], scores[results[2]][2], otherStr))
+
+
+ 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")
+