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
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
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
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, ) print "Out of %s matches, %s won %s and %s won %s" % ( num_matches,
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 t.logger.write_two = stub t.play_match() 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,)
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