Esempio n. 1
0
def run_tournament(s1, s2):
    f1 = open("scrim_" + str(s1) + "_" + str(s2) + ".csv", "wb")
    f2 = open("log_" + str(s1) + "_" + str(s2) + ".csv", "wb")
    data = csv.writer(f1, delimiter=",")
    data.writerow(
        [
            "Seat 1",
            "Seat 2",
            "Match",
            "Duration",
            "Hands",
            "Seat 1 Response",
            "Seat 2 Response",
            "Seat 1 Actions",
            "Seat 2 Actions",
            "Seat 1 Memory",
            "Seat 2 Memory",
            "Winner",
            "Loser",
        ]
    )
    out = csv.writer(f2, delimiter=",")
    out.writerow(["Seat 1", "Seat 2", "Success"])

    MATCHES = 2

    submissions = [
        TheDerbs(),
        ODoyleBot3(),
        ODoyleBot2(),
        ODoyleBot1(),
        ODoyleBot4(),
        ODoyleBot5(),
        RockyBot2(),
        RockyBot4(),
        RockyBot3(),
        ManBearPigBot(),
        ManBearPigBot1(),
        ManBearPigBot2(),
        LukeBotAgg(),
        LukeBotAgg1(),
        LukeBotAgg2(),
        LukeBotAgg3(),
        MLKBot2(),
        MLKBot2Cool4U(),
        MalcomXBot(),
        MalcomXBot1(),
        MalcomXBot2(),
        TheBostonDerbyA(),
        TheBostonDerbyB(),
        TheBostonDerbyC(),
        LukesDerby(),
        LukesDerby1(),
        LukesDerby2(),
        LukesDerby3(),
        LukesDerby4(),
        LukesDerby5(),
        LukesDerby6(),
        LukesDerby7(),
        LukesDerby8(),
        TheBostonDerby0(),
        TheBostonDerby1(),
        TheBostonDerby2(),
        TheBostonDerby3(),
        TheBostonDerby4(),
        TheBostonDerby5(),
        TheBostonDerby6(),
        TheBostonDerby7(),
        TheBostonDerby8(),
    ]
    print len(submissions)
    num_cpus = cpu_count()
    match_queue = Queue()
    result_queue = Queue()
    manager = Manager()

    bots = []

    # instantiate all bots
    for i, team in enumerate(submissions):
        bot = Pokerbot(team)
        bot._lock = manager.RLock()
        bot._index = i
        bots.append(bot)

    print "finished instantiating bots"

    matchups = []
    for p1 in bots[:-1]:
        for p2 in bots:
            if p2._index <= p1._index:
                continue
            matchups.append((p1, p2))

    random.shuffle(matchups)
    for match in matchups:
        match_queue.put(match)

    proc = []
    for l in range(num_cpus):
        p = Process(target=rungames, args=(l, MATCHES, match_queue, result_queue))
        proc.append(p)
        p.start()

    for i in range(len(matchups)):
        while True:
            try:
                metrics, logs = result_queue.get(False, 0.2)
                break
            except Empty:
                time.sleep(0.1)
        for stat in metrics:
            data.writerow(stat)
        for output in logs:
            out.writerow(output)

    for l in range(num_cpus):
        match_queue.put("STOP")

    for p in proc:
        p.join()

    f1.close()
    f2.close()