def main(): global MINGAMES trueskill.SetParameters(beta=25.0/3.0, draw_probability=0.3) with open(sys.argv[1], 'r') as filp: settings = json.load(filp) if "mingames" in settings: MINGAMES = settings["mingames"] maps = helpers.listmaps(settings["ants"] + "maps") gameid = getfirstgameid() staticbots = [StaticBot(cmd) for cmd in settings["static"]] tunegroups = [TuneGroup(group) for group in settings["tune"]] while True: seedbot = tunegroups[0].run() otherbots = staticbots + [bot for group in tunegroups for bot in group.population if bot != seedbot] maprec = random.choice(maps) print "Game {gameid}: {maprec[players]} player map {maprec[path]}".format(**locals()) mapbots = [seedbot] + random.sample(otherbots, maprec["players"] - 1) botcmds = [bot.getcmd() for bot in mapbots] for idx in range(len(botcmds)): cmd = botcmds[idx] skill = mapbots[idx].skill print " ", "({mu:3}, {sigma:3}):".format(mu=skill[0], sigma=skill[1]), cmd[cmd.rfind('/')+1:] args = [ settings["ants"] + "playgame.py", "--turns", "1000", "--turntime", "500", "--log_dir", "tune_logs", "--nolaunch", "--serial", "-g", str(gameid), "--map", maprec["path"], ] + botcmds subprocess.check_call(args) with open('tune_logs/{0}.replay'.format(gameid), 'r') as filp: replay = json.load(filp) if "error" in replay: print "An error occurred" print replay["error"] return rank = replay["rank"] print " Ranks:", ', '.join([str(r) for r in rank]) for idx in range(len(rank)): mapbots[idx].rank = rank[idx] mapbots[idx].nrgames += 1 trueskill.AdjustPlayers(mapbots) print " ", ', '.join("{name} ({mu:3}, {sigma:3})".format(name=bot.getname(), mu=bot.skill[0], sigma=bot.skill[1]) for bot in mapbots) gameid += 1
def main(): with open('bots.json', 'r') as filp: settings = json.load(filp) maps = [ maprec for maprec in helpers.listmaps(settings["ants"] + "maps") if maprec["players"] <= len(settings["bots"]) ] allbots = [(name, name[name.rfind('/') + 1:]) for name in settings["bots"]] gameid = getfirstgameid() while True: maprec = random.choice(maps) print "Game {gameid}: {maprec[players]} player map {maprec[path]}".format( **locals()) mapbots = random.sample(allbots, maprec["players"]) for i in range(len(mapbots)): print " {i}: {bot}".format(i=i + 1, bot=mapbots[i][1]) args = [ settings["ants"] + "playgame.py", "--turns", "1000", "--turntime", "500", "--log_dir", "game_logs", "--log_input", "--nolaunch", "--serial", "-g", str(gameid), "--map", maprec["path"], ] + [bot[0] for bot in mapbots] subprocess.check_call(args) with open('game_logs/{0}.replay'.format(gameid), 'r') as filp: replay = json.load(filp) if "error" in replay: print "An error occurred" print replay["error"] return score = replay["score"] status = replay["status"] print "Outcome after {0} turns".format(max(replay["playerturns"])) for i in range(len(mapbots)): print " {i}: {name} score: {score} status: {status}".format( i=i + 1, name=replay["playernames"][i], score=score[i], status=status[i]) gameid += 1
def main(): with open('bots.json', 'r') as filp: settings = json.load(filp) maps = [maprec for maprec in helpers.listmaps(settings["ants"] + "maps") if maprec["players"] <= len(settings["bots"])] allbots = [ (name, name[name.rfind('/')+1:]) for name in settings["bots"] ] gameid = getfirstgameid() while True: maprec = random.choice(maps) print "Game {gameid}: {maprec[players]} player map {maprec[path]}".format(**locals()) mapbots = random.sample(allbots, maprec["players"]) for i in range(len(mapbots)): print " {i}: {bot}".format(i=i+1, bot=mapbots[i][1]) args = [ settings["ants"] + "playgame.py", "--turns", "1000", "--turntime", "500", "--log_dir", "game_logs", "--log_input", "--nolaunch", "--serial", "-g", str(gameid), "--map", maprec["path"], ] + [bot[0] for bot in mapbots] subprocess.check_call(args) with open('game_logs/{0}.replay'.format(gameid), 'r') as filp: replay = json.load(filp) if "error" in replay: print "An error occurred" print replay["error"] return score = replay["score"] status = replay["status"] print "Outcome after {0} turns".format(max(replay["playerturns"])) for i in range(len(mapbots)): print " {i}: {name} score: {score} status: {status}".format( i=i+1, name=replay["playernames"][i], score=score[i], status=status[i]) gameid += 1
def main(): global MINGAMES trueskill.SetParameters(beta=25.0 / 3.0, draw_probability=0.3) with open(sys.argv[1], 'r') as filp: settings = json.load(filp) if "mingames" in settings: MINGAMES = settings["mingames"] maps = helpers.listmaps(settings["ants"] + "maps") gameid = getfirstgameid() staticbots = [StaticBot(cmd) for cmd in settings["static"]] tunegroups = [TuneGroup(group) for group in settings["tune"]] while True: seedbot = tunegroups[0].run() otherbots = staticbots + [ bot for group in tunegroups for bot in group.population if bot != seedbot ] maprec = random.choice(maps) print "Game {gameid}: {maprec[players]} player map {maprec[path]}".format( **locals()) mapbots = [seedbot] + random.sample(otherbots, maprec["players"] - 1) botcmds = [bot.getcmd() for bot in mapbots] for idx in range(len(botcmds)): cmd = botcmds[idx] skill = mapbots[idx].skill print " ", "({mu:3}, {sigma:3}):".format( mu=skill[0], sigma=skill[1]), cmd[cmd.rfind('/') + 1:] args = [ settings["ants"] + "playgame.py", "--turns", "1000", "--turntime", "500", "--log_dir", "tune_logs", "--nolaunch", "--serial", "-g", str(gameid), "--map", maprec["path"], ] + botcmds subprocess.check_call(args) with open('tune_logs/{0}.replay'.format(gameid), 'r') as filp: replay = json.load(filp) if "error" in replay: print "An error occurred" print replay["error"] return rank = replay["rank"] print " Ranks:", ', '.join([str(r) for r in rank]) for idx in range(len(rank)): mapbots[idx].rank = rank[idx] mapbots[idx].nrgames += 1 trueskill.AdjustPlayers(mapbots) print " ", ', '.join("{name} ({mu:3}, {sigma:3})".format( name=bot.getname(), mu=bot.skill[0], sigma=bot.skill[1]) for bot in mapbots) gameid += 1