Exemplo n.º 1
0
def face_off(p1_params, p2_params):
    p1_name = "tournament1"
    p2_name = "tournament2"
    p1_module_key = 'pokerbots.player.%s.%s' % (
        p1_name,
        p1_name,
    )
    p2_module_key = 'pokerbots.player.%s.%s' % (
        p2_name,
        p2_name,
    )
    p1_wins = 0
    p2_wins = 0
    generate_bot(p1_name, p1_params)
    generate_bot(p2_name, p2_params)
    # Must reload the bots, or you keep making the old ones
    # Must happen right after the code changes
    if p1_module_key in sys.modules:
        reload(sys.modules[p1_module_key])
    if p2_module_key in sys.modules:
        reload(sys.modules[p2_module_key])
    p1 = Pokerbot(p1_name)
    p2 = Pokerbot(p2_name)

    num_matches = 25
    start_time = time.time()
    for i in range(num_matches):
        t = Table(p1, p2)
        t.play_match()
        # To find the winner, read the state. Who has 800 chips?
        # TODO: We assume no timeout!
        state = t.state()
        if state['players'][0]['stack'] == 800:
            p1_wins += 1
        else:
            p2_wins += 1
        # Use this to show progress
        # if i > 0 and (i + 1) % 10 == 0:
        # print "So far, of %s matches, %s won %s and %s won %s" % \
        # (i + 1, p1_name, p1_wins, p2_name, p2_wins,)
    print "%s %s - %s %s (%s matches, %s sec)" % \
        ("(%.3f, %.3f, %.3f, %.3f)" % p1_params, p1_wins,
        p2_wins, "(%.3f, %.3f, %.3f, %.3f)" % p2_params,
        num_matches, round(time.time() - start_time, 2))
    if p1_wins > p2_wins:
        return p1_params
    else:
        return p2_params
Exemplo n.º 2
0
from pokerbots.engine.game import Table
from pokerbots.player.pokerbot import Pokerbot
import time
import sys

test_opponent_names = ['masterchefA', 'masterchefB', 'Template']

# okay, we should create an array of bots and play them against each other
# generate all the combinations we want to play
# then round robin them

for p1_name in test_opponent_names:
    p2_name = sys.argv[1]
    p1_wins = 0
    p2_wins = 0
    p1 = Pokerbot(p1_name)
    p2 = Pokerbot(p2_name)

    num_matches = 100

    for i in range(num_matches):
        t = Table(p1, p2)
        t.play_match()
        # To find the winner, read the state. Who has 800 chips?
        # TODO: We assume no timeout!
        state = t.state()
        if state['players'][0]['stack'] == 800:
            p1_wins += 1
        else:
            p2_wins += 1
        if i > 0 and (i + 1) % 25 == 0:
Exemplo n.º 3
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()
Exemplo n.º 4
0
def face_off(p1_params, p2_params, base_name):
    p1_name = base_name + "_1"
    p2_name = base_name + "_2"
    p1_module_key = 'pokerbots.player.%s.%s' % (
        p1_name,
        p1_name,
    )
    p2_module_key = 'pokerbots.player.%s.%s' % (
        p2_name,
        p2_name,
    )
    p1_wins = 0
    p2_wins = 0
    generate_bot(p1_name, p1_params)
    generate_bot(p2_name, p2_params)
    # Must reload the bots, or you keep making the old ones
    # Must happen right after the code changes
    if p1_module_key in sys.modules:
        reload(sys.modules[p1_module_key])
    if p2_module_key in sys.modules:
        reload(sys.modules[p2_module_key])
    p1 = Pokerbot(p1_name)
    p2 = Pokerbot(p2_name)

    num_matches = 25
    for i in range(num_matches):
        t = Table(p1, p2)
        if STUB_OUT_LOGGER:
            t.logger.action = stub
            t.logger.begin_hand = stub
            t.logger.blinds = stub
            t.logger.end = stub
            t.logger.file_one = stub
            t.logger.file_two = stub
            t.logger.preflop = stub
            t.logger.refund = stub
            t.logger.results = stub
            t.logger.showdown = stub
            t.logger.street = stub
            t.logger.time = stub
            t.logger.write_both = stub
            t.logger.write_one = stub
            t.logger.write_two = stub
        t.play_match()
        # To find the winner, read the state. Who has 800 chips?
        # TODO: We assume no timeout!
        state = t.state()
        if state['players'][0]['stack'] == 800:
            p1_wins += 1
        else:
            p2_wins += 1
        # Use this to show progress
        # if i > 0 and (i + 1) % 10 == 0:
        # print "So far, of %s matches, %s won %s and %s won %s" % \
        # (i + 1, p1_name, p1_wins, p2_name, p2_wins,)
    print "%s %s - %s %s (%s matches)" % \
        ("(%s, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f)" % p1_params, p1_wins,
        p2_wins, "(%s, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f)" % p2_params,
        num_matches)
    sys.stdout.flush()
    if p1_wins > p2_wins:
        return p1_params
    else:
        return p2_params
Exemplo n.º 5
0
    n = 200 #number of individuals
    m = 9#number of games to run for
    
    num_cpus = 1#cpu_count()

    test_bots = [Pokerbot(TheDerbs()),Pokerbot(LukeBotAgg1()),Pokerbot(MalcomXBot()),Pokerbot(ODoyleBot5())]
    #test_bots = [Pokerbot('TheBostonDerby4'),Pokerbot('TheBostonDerby8'),Pokerbot('TheBostonDerby5'),Pokerbot('TheBostonDerby'),Pokerbot('TheBostonDerby6'),Pokerbot('Flopallin')]
    use_lukes = True
    if use_lukes:
        vals = generate_vals()
    else:
        vals = generate_vals_boston()

    bots = []
    for i,genome in enumerate(vals):
        bot = Pokerbot(RockyBot2())
        bot.bot.bot.eq_ranges=genome
        bot.index = i
        bots.append(bot)
    score = [0]*n
    for bot in bots:
        score[bot.index] = [0,[0]*len(test_bots),bot.bot.bot.eq_ranges]
    begin = time.time()
    for i in range(n):
        start = time.time()
        p1 = bots[i]
        print "testing with bot",i,"using gene", p1.bot.bot.eq_ranges
        for j,p2 in enumerate(test_bots):
            now= time.time()
            games_to_run = m
            proc = []