Exemplo n.º 1
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.º 2
0
def playgame(p1, p2):
    p1 = Pokerbot(p1)
    p2 = Pokerbot(p2)

    t = Table(p1, p2, False)

    while t.p1.stack > 0 and t.p2.stack > 0:
        t.play()
    return t.p2.stack == 0 #return 1 if p1 won, 0 if p2 won
Exemplo n.º 3
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.º 4
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.º 5
0
# 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:
            print "So far, of %s matches, %s won %s and %s won %s" % (
                i + 1,
                p1_name,
                p1_wins,
                p2_name,
                p2_wins,
Exemplo n.º 6
0
def rungames(my_id, MATCHES, in_q, out_q):
    match_count = 1
    for p1, p2 in iter(in_q.get, "STOP"):
        if p1 == p2:
            continue
        if not p1._lock._callmethod("acquire", (False,)):
            in_q.put((p1, p2))
            try:
                p1._lock._callmethod("release")
            except:
                pass
            try:
                p2._lock._callmethod("release")
            except:
                pass
            # print "core %d couldn't get lock for %16s" % (my_id,p1.name)
            time.sleep(1)
            continue
        elif not p2._lock._callmethod("acquire", (False,)):
            in_q.put((p1, p2))
            try:
                p1._lock._callmethod("release")
            except:
                pass
            try:
                p2._lock._callmethod("release")
            except:
                pass
            # print "core %d couldn't get lock for %16s" % (my_id,p2.name)
            time.sleep(1)
            continue
        print "core %d running %16s vs %16s" % (my_id, p1.name, p2.name)
        metrics = []
        log = []
        for i in range(1, MATCHES + 1):
            start_time = time.time()
            t = Table(p1, p2, False)
            while t.p1.stack > 0 and t.p2.stack > 0:
                t.play()
            end_time = time.time()
            if t.p1.stack == 0:
                winner = t.p2.name
                loser = t.p1.name
            else:
                winner = t.p1.name
                loser = t.p2.name
            stats = [
                t.p1.name,
                t.p2.name,
                str(i),
                str(end_time - start_time),
                str(t.hands_played),
                # str(float(t.p1.time)/t.p1.num_actions),
                # str(float(t.p2.time)/t.p2.num_actions),
                str(t.p1.num_actions),
                str(t.p2.num_actions),
                str(asizeof(t.p1.bot)),
                str(asizeof(t.p2.bot)),
                winner,
                loser,
            ]
            metrics.append(stats)
            # data.writerow(stats)
            print "Match #" + str(match_count) + " complete, " + winner + " beats " + loser
            output = [t.p1.name, t.p2.name, "True"]
            # out.writerow(output)
            match_count += 1
            try:
                match_count = match_count
            except:
                t.p1.stack = 0
                t.p2.stack = 0
                print "Match #" + str(match_count) + " failed"
                print "Offenders were " + t.p1.name + " & " + t.p2.name
                output = [t.p1.name, t.p2.name, "False"]
                stats = []
                # out.writerow(output)
                match_count += 1
            log.append(output)
        out_q.put((metrics, log))
        p1._lock._callmethod("release")
        p2._lock._callmethod("release")
Exemplo n.º 7
0
def playgame(p1, p2):
    t = Table(p1, p2, False)

    t.play_match()
    return t.p2.stack == 0 #return 1 if p1 won, 0 if p2 won
Exemplo n.º 8
0
STUB_OUT_LOGGER = True

p1_name = 'trickybot'
p2_name = 'trickybotB'
p1 = Pokerbot(p1_name)
p2 = Pokerbot(p2_name)
p1_wins = 0
p2_wins = 0
num_matches = 400

def stub(*args, **kwargs):
    pass

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
Exemplo n.º 9
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.º 10
0
import os

for bot in os.listdir("./pokerbots/player/"):
    f = bot.split(".")
    if len(f) == 2 and f[1] == "py" and f[0]:
        exec ("from pokerbots.player." + f[0] + " import *")

P1 = RockyBot2()
P2 = LukeBotAgg3()
p1 = Pokerbot(P1)
p2 = Pokerbot()
p1_wins = 0
p2_wins = 0
num_matches = 9

for i in range(num_matches):
    t = Table(p1, p2, True)
    start = time.time()
    t.play_match()
    print time.time() - start,
    if t.p1.stack == 0:
        print t.p2.name, "won",
        p2_wins += 1
    else:
        print t.p1.name, "won",
        p1_wins += 1
    print "game %d" % i

print t.p1.name, "won", p1_wins, "times"
print t.p2.name, "won", p2_wins, "times"