예제 #1
0
def run_one_game_rebuys(deepbot, nb_hands = 500, ini_stack = 3000, sb_amount = 50, opponents = 'default', verbose=False, cst_decks=None):
    if opponents == 'default':
        opp_algos = [CallBot(), ConservativeBot(), EquityBot(), ManiacBot()]
        opp_names = ['call_bot','conservative_bot', 'equity_bot','maniac_bot']
    else:
        opp_algos = opponents['opp_algos']
        opp_names = opponents['opp_names']

    earnings = OrderedDict()
    ## for each bot to oppose
    for opp_algo, opp_name in zip(opp_algos, opp_names):

        #first match
        max_round = nb_hands
        my_game_result_1 = 0
        cst_deck_match=cst_decks.copy()
        deepbot.model.reset()
        while True:
            config = setup_config(max_round=max_round, initial_stack=ini_stack, small_blind_amount=sb_amount)
            config.register_player(name=deepbot.opponent, algorithm=opp_algo)
            config.register_player(name="deepbot", algorithm= deepbot)
            game_result_1 = start_poker(config, verbose=0, cheat = True, cst_deck_ids = cst_deck_match, return_last_two=False)
            #Hacky fix for missing last SB in some results
            if game_result_1['players'][1]['stack'] == 2*ini_stack-sb_amount:
                game_result_1['players'][1]['stack'] = 2*ini_stack
            my_game_result_1 += game_result_1['players'][1]['stack'] - ini_stack
            max_round-=(deepbot.round_count+1)
            if max_round<=0:
                break

        if verbose:
            print("Stack after first game: "+ str(game_result_1))

        #return match
        max_round = nb_hands
        my_game_result_2 = 0
        cst_deck_match=cst_decks.copy()
        deepbot.model.reset()
        while True:
            config = setup_config(max_round=max_round, initial_stack=ini_stack, small_blind_amount=sb_amount)
            config.register_player(name="deepbot", algorithm=deepbot)
            config.register_player(name=deepbot.opponent, algorithm=opp_algo)
            game_result_2 = start_poker(config, verbose=0, cheat = True, cst_deck_ids = cst_deck_match, return_last_two=False)
            #Hacky fix for missing last SB in some results
            if game_result_2['players'][0]['stack'] == 2*ini_stack-sb_amount:
                game_result_2['players'][0]['stack'] = 2*ini_stack
            my_game_result_2 += game_result_2['players'][0]['stack'] - ini_stack
            max_round-=(deepbot.round_count+1)
            if max_round<=0:
                break

        if verbose:
            print("return game: "+ str(game_result_2['players'][0]['stack']))

        earnings[opp_name] = my_game_result_1 + my_game_result_2


   # print('Done with game of bot number: '+ str(deepbot.id))

    return earnings
예제 #2
0
def run_one_game_reg(simul_id , gen_id, deepbot, verbose=False, cst_decks=None, nb_sub_matches =10):
    """old"""
    #CONFIGURATION
    nb_hands = 500
    ini_stack = 2000
    sb_amount = 50
    opp_algos = [CallBot(), ConservativeBot(), EquityBot(), ManiacBot()]
    opp_names = ['call_bot','conservative_bot', 'equity_bot','maniac_bot']

    earnings = OrderedDict()
    ## for each bot to oppose
    for opp_algo, opp_name in zip(opp_algos, opp_names):

        #first match
        my_game_result_1 = 0
        cst_deck_match=cst_decks.copy()
        deepbot.model.reset()
        for i in range(nb_sub_matches):
            config = setup_config(max_round=int(nb_hands/nb_sub_matches)-1, initial_stack=ini_stack, small_blind_amount=sb_amount)
            config.register_player(name=deepbot.opponent, algorithm=opp_algo)
            config.register_player(name="deepbot", algorithm= deepbot)
            game_result_1 = start_poker(config, verbose=0, cheat = True, cst_deck_ids = cst_deck_match, return_last_two=False)
            #Hacky fix for missing last SB in some results
            if game_result_1['players'][1]['stack'] == 2*ini_stack-sb_amount:
                game_result_1['players'][1]['stack'] = 2*ini_stack
            my_game_result_1 += game_result_1['players'][1]['stack']
        if verbose:
            print("Stack after first game: "+ str(game_result_1))

        #return match
        my_game_result_2 = 0
        cst_deck_match=cst_decks.copy()
        deepbot.model.reset()
        for i in range(nb_sub_matches):
            config = setup_config(max_round=int(nb_hands/nb_sub_matches)-1, initial_stack=ini_stack, small_blind_amount=sb_amount)
            config.register_player(name="deepbot", algorithm=deepbot)
            config.register_player(name=deepbot.opponent, algorithm=opp_algo)
            game_result_2 = start_poker(config, verbose=0, cheat = True, cst_deck_ids = cst_deck_match, return_last_two=False)
            ##Fixing issue with missing last SB in certain wins
            if game_result_2['players'][0]['stack'] == 2*ini_stack-sb_amount:
                game_result_2['players'][0]['stack'] = 2*ini_stack
            my_game_result_2 += game_result_2['players'][0]['stack']

        if verbose:
            print("return game: "+ str(game_result_2['players'][0]['stack']))

        earnings[opp_name] = my_game_result_1 + my_game_result_2 - 2*ini_stack

    return earnings
예제 #3
0
    def play_round(self, players):
        """
        Input:
            players: a list of 2 tuples- (player, num) where num is the index of player in self.pop
        Output:
            a list of the 2 players' payoffs
        """
        # if (len(players) != 2):
        # raise ValueError('The genetic algo fitness game has more than 2 players.')

        config = setup_config(max_round=MAX_ROUNDS,
                              initial_stack=INITIAL_STACK,
                              small_blind_amount=SMALL_BLIND_AMOUNT)
        # print("Setting up a new game")

        for player, num in players:
            # print("Registering player {0}".format(num))
            config.register_player(name=num, algorithm=player)

        results = start_poker(config, verbose=0)
        # print("The final results of the poker game are: ", results)

        fitnesses = [0] * self.size
        for player in results['players']:
            fitnesses[player['name']] = player['stack']

        return fitnesses
예제 #4
0
def trainingFactor(initialValue, adjustingSize, trainingTimes, numOfValues):

	RaisedPlayer.raiseThreshold = initialValue	
	maxValue = 0
	for j in range(0, numOfValues):
		totalResult = 0
		print("The factor:", RaisedPlayer.raiseThreshold)

		for k in range(0, trainingTimes):
			config = setup_config(max_round=100, initial_stack=10000, small_blind_amount=10)
			# config.register_player(name="call_player", algorithm=CallPlayer())
			# config.register_player(name="random", algorithm=RandomPlayer())
			config.register_player(name="runable", algorithm=RaisedPlayer())
			config.register_player(name="search", algorithm=SearchPlayer())
			game_result = start_poker(config, verbose=1)
			print game_result
			totalResult += game_result['players'][0]['stack'] 
			
			# To change the variables of the function	
	
		# print("The factor:", AlphaBeta.factors[0])
		aveResult = totalResult/trainingTimes
		print("The aveResult:", aveResult)
		maxValue = max(aveResult, maxValue)
		if (aveResult == maxValue): 
			optimalFactor = RaisedPlayer.raiseThreshold
		print("Current Max", maxValue, "current optimalFactor:", optimalFactor)
		trainingResult = "raiseThreshold value:" + str(RaisedPlayer.raiseThreshold) + "aveResult:" + str(aveResult) 
		import cPickle
		result = open('trainingResult' + ' raiseThreshold' + str(RaisedPlayer.raiseThreshold)+ '.pkl', 'w')
		cPickle.dump(trainingResult, result)
		print game_result
		RaisedPlayer.raiseThreshold += adjustingSize
	return optimalFactor
예제 #5
0
def create_bachtes(num, num_players):
    # check if their are already existing saves
    if (os.path.exists(path + state_to_save + "/save0.pickle")):
        files = (glob.glob(path + state_to_save + "/save*.pickle"))
        last_number = []
        for l in range(len(files)):
            last_number.append(int(files[l].split('.pic')[0].split('save')[-1]))
        # if so set the the save numer to the highest existing savenumber + 1
        last_number = max(last_number) + 1
    else:
        last_number = 0
    # notice each game lasts only one round and a new game starts. This should be okay, since most cash players
    # usually top their chip amount up if they lost either way (e.g.will always play with a minimum of 50€)
    for i in range(num):
        config = setup_config(max_round=1, initial_stack=100, small_blind_amount=5)
        # determine the seat of the player randomly
        own_seat = randint(1, num_players)
        for x in range(1, own_seat):
            # the current algorithm(fishPlayer) will always call, hence we will definetly reach the end state
            # of the game if the TrainingsGenerator won't go all-in
            config.register_player(name=("p", x), algorithm=FishPlayer())
        config.register_player("trainingsGenerator", algorithm=TrainingsGenerator(-1, state_to_save,
                               path, last_number))
        for x in range(own_seat+1, num_players+1):
            config.register_player(name=("p", x), algorithm=FishPlayer())
        # if set to 1 the winner of each game will be printed with some additionally information
        game_result = start_poker(config, verbose = 0)
        # print("I: ", i)
        last_number += 1
예제 #6
0
def play_round(players):
    """
    Input:
        players: a list of PLAYERS_PER_TABLE tuples- (player, num) where num is the index of player in population
    Output:
        - order of the players
        - their corresponding payoff probabilities
    """
    config = setup_config(max_round=MAX_GAME_ROUNDS,
                          initial_stack=INITIAL_STACK,
                          small_blind_amount=SMALL_BLIND_AMOUNT)
    # print("Setting up a new game")

    for player, num in players:
        config.register_player(name=num, algorithm=player)

    results = start_poker(config, verbose=0)
    # print("The final results of the poker game are: ", results)

    playerOrder = []
    fitnesses = []

    for player in results['players']:
        playerOrder.append(player['name'])
        fitnesses.append(player['stack'])

    return playerOrder, normalize_list(fitnesses)
예제 #7
0
def init():
    print("hello world")
    qtable = make_table()
    config = setup_config(max_round=10,
                          initial_stack=10000,
                          small_blind_amount=10)

    player = LearningPlayer()

    config.register_player(name="rand", algorithm=RandomPlayer())
    config.register_player(name="learn", algorithm=player)

    game_result = start_poker(config, verbose=1)
    for k in range(len(player.gameHistory)):
        game = player.gameHistory[k]
        print(("=" * 5 + " Game {} " + "=" * 5).format(k + 1))
        for n in range(len(game['action_history'])):
            i = game['action_history'][n]
            print(
                ("{:<10} {:<4} {:<2} {:<2} - {:<20} ({:<4}) {:<5} {}").format(
                    i['street'], i['pot'], i['hole_cards'][0],
                    i['hole_cards'][1], " ".join(i['community_cards']),
                    i['ehs'], i['action'], i['valid_actions']))
        # print("\n".join(list(map(lambda p: "{}: {}".format(p['name'], p['stack']), game_result['players']))))
        print(game['result']['name'], 'won pot of', game['pot'])
        print("stack sizes: {} {}".format(game['self_stack'],
                                          game['opp_stack']))
예제 #8
0
 def test_set_blind_structure(self):
     config = G.setup_config(1, 100, 10)
     config.register_player("p1", FoldMan())
     config.register_player("p2", FoldMan())
     config.set_blind_structure({ 1: { "ante":5, "small_blind":10 } })
     result = G.start_poker(config)
     p1, p2 = [result["players"][i] for i in range(2)]
     self.eq(115, p1["stack"])
     self.eq(85, p2["stack"])
예제 #9
0
 def test_set_blind_structure(self):
     config = G.setup_config(1, 100, 10)
     config.register_player("p1", FoldMan())
     config.register_player("p2", FoldMan())
     config.set_blind_structure({1: {"ante": 5, "small_blind": 10}})
     result = G.start_poker(config)
     p1, p2 = [result["players"][i] for i in range(2)]
     self.eq(115, p1["stack"])
     self.eq(85, p2["stack"])
예제 #10
0
 def test_set_blind_structure(self):
     config = G.setup_config(1, 100, 10)
     config.register_player('p1', FoldMan())
     config.register_player('p2', FoldMan())
     config.set_blind_structure({1: {'ante': 5, 'small_blind': 10}})
     result = G.start_poker(config)
     p1, p2 = [result['players'][i] for i in range(2)]
     self.eq(115, p1['stack'])
     self.eq(85, p2['stack'])
예제 #11
0
def play_game(agentOne, agentTwo, rounds):
    # Game Settings
    config = setup_config(max_round=rounds,
                          initial_stack=10000,
                          small_blind_amount=20)
    config.register_player(name="Player 1 ", algorithm=agentOne)
    config.register_player(name="Player 2 ", algorithm=agentTwo)
    game_result = start_poker(config, verbose=0)
    return game_result
예제 #12
0
 def test_start_poker(self):
     config = G.setup_config(1, 100, 10)
     config.register_player("p1", FoldMan())
     config.register_player("p2", FoldMan())
     result = G.start_poker(config)
     p1, p2 = [result["players"][i] for i in range(2)]
     self.eq("p1", p1["name"])
     self.eq(110, p1["stack"])
     self.eq("p2", p2["name"])
     self.eq(90, p2["stack"])
예제 #13
0
 def test_start_poker(self):
     config = G.setup_config(1, 100, 10)
     config.register_player('p1', FoldMan())
     config.register_player('p2', FoldMan())
     result = G.start_poker(config)
     p1, p2 = [result['players'][i] for i in range(2)]
     self.eq('p1', p1['name'])
     self.eq(110, p1['stack'])
     self.eq('p2', p2['name'])
     self.eq(90, p2['stack'])
예제 #14
0
 def test_start_poker(self):
     config = G.setup_config(1, 100, 10)
     config.register_player("p1", FoldMan())
     config.register_player("p2", FoldMan())
     result = G.start_poker(config)
     p1, p2 = [result["players"][i] for i in range(2)]
     self.eq("p1", p1["name"])
     self.eq(110, p1["stack"])
     self.eq("p2", p2["name"])
     self.eq(90, p2["stack"])
예제 #15
0
    def simulate(self, nGames, nRounds, initial_stack, small_blind_amount):
        # since no api is provided for simulate games with known hole_card value, we just simulate nRounds using random player for convenience purpose
      results = []
      config = setup_config(max_round=nRounds, initial_stack=initial_stack, small_blind_amount=small_blind_amount)
      config.register_player(name="f1", algorithm=RandomPlayer())
      config.register_player(name="FT2", algorithm=RandomPlayer())

      for i in range(nGames):
          game_result = start_poker(config, verbose=0)
          results.append(game_result['players'][0]['stack'] - game_result['rule']['initial_stack'])

      print(sum(results)/len(results))
예제 #16
0
def play_game(agent_one, agent_two, rounds):
    # Game Settings
    agent_one_name = agent_one[0]
    agent_one_player = agent_one[1].getPlayer()
    agent_two_name = agent_one[0]
    agent_two_player = agent_two[1].getPlayer()

    config = setup_config(max_round=rounds, initial_stack=10000, small_blind_amount=20)
    config.register_player(name=agent_one_name, algorithm=agent_one_player)
    config.register_player(name=agent_two_name, algorithm=agent_two_player)
    game_result = start_poker(config, verbose=0)
    return game_result
예제 #17
0
def trail_play():
    from pypokerengine.api.game import setup_config, start_poker

    config = setup_config(max_round=10,
                          initial_stack=100,
                          small_blind_amount=5)
    config.register_player(name="p1", algorithm=FishPlayer())
    config.register_player(name="p2", algorithm=FishPlayer())
    config.register_player(name="p3", algorithm=FishPlayer())
    game_result = start_poker(config, verbose=1)

    print(game_result)
	def play_round(self, players):
		## Input: players is a list of tuples (player, num) where num is the index of player in self.pop
		## Output: a list of their payoffs
		config = setup_config(max_round=20, initial_stack=200, small_blind_amount=1)
		print("Setting up a new table")
		for player, num in players:
			print("Welcoming player {0}".format(num))
			config.register_player(name=num, algorithm=player)
		results = start_poker(config, verbose=0)
		print("The final results of the poker tournament are: ", results)
		fitnesses = [0] * self.size
		for player in results['players']:
			fitnesses[player['name']] = player['stack']
		return fitnesses
예제 #19
0
def init():
    config = setup_config(max_round=MAX_ROUND, initial_stack=10000, small_blind_amount=10)

    player = LearningPlayer(LOG_LEVEL)
    player.load_qtable_from_file("q-table-rvp-400.txt")
    player2 = RVPlayer()
    # player2.load_qtable_from_file("gen-0-700-fixed.txt")
    atexit.register(exithandler, player, player2)

    config.register_player(name="RVPlayer", algorithm=player2)
    config.register_player(name="learn1", algorithm=player)
    total_start_time = time.time()
    total_rounds = 0

    last_unseen = 0
    last_seen = 0
    for i in range(NUM_GAMES):
        start_time = time.time()
        game_result = start_poker(config, verbose=LOG_LEVEL)
        window['game_count'] += 1

        num_rounds = player.num_rounds_this_game
        total_rounds += num_rounds
        print("Game #{} {} rounds - {}s".format(i + 1, num_rounds, time.time() - start_time))
        # print("Unseen hands: {}".format(player.unseen_hands))
        print("Seen/Unseen states: {} {}".format(player.seen_states - last_seen, player.unseen_states - last_unseen))

        last_unseen = player.unseen_states
        last_seen = player.seen_states
        print("\n".join(list(map(lambda p: "{}: {}".format(p['name'], p['stack']), game_result['players']))))
        print()
        if i > 0 and i % DUMP_INTERVAL == 0:
            player.write_table(i)


    print("Unseen hands: {}".format(player.unseen_hands))
    print("Unseen states: {}".format(player.unseen_states))
    print("Total - {} games, {} rounds, {}s".format(NUM_GAMES, total_rounds, time.time() - total_start_time))

    for k in range(len(player.gameHistory)):
        game = player.gameHistory[k]
        print(("=" * 5 + " Game {} " + "=" * 5).format(k + 1))
        for n in range(len(game['action_history'])):
            i = game['action_history'][n]
            print("{:<10} {:<4} {:<2} {:<2} - {:<20} ({:<4}) {:<5} {} {}".format(i['street'], i['pot'], i['hole_cards'][0], i['hole_cards'][1], " ".join(i['community_cards']), i['ehs'], i['action'], i['decision'], i['choices']))
        # print("\n".join(list(map(lambda p: "{}: {}".format(p['name'], p['stack']), game_result['players']))))
        print(game['result']['name'], 'won pot of', game['pot'])
        print("stack sizes: {} {}".format(game['self_stack'], game['opp_stack']))
예제 #20
0
def initiate_game(config):
    # Init pot of players
    win_cnt = 0
    for game in range(1, 2):
        print "Game number: %d" % (game)
        start = time.time()
        game_result = start_poker(config, verbose=0)
        end = time.time()
        print "Time take to play: %.4f seconds" % (end - start)
        agent1_pot = game_result['players'][0]['stack']
        agent2_pot = game_result['players'][1]['stack']
        print 'Player 1 pot: %d' % (agent1_pot)
        print 'Player 2 pot: %d' % (agent2_pot)
        if agent1_pot > agent2_pot:
            win_cnt += 1
    return win_cnt
예제 #21
0
def play_game(max_round, names, value_functions, with_me=False, verbose=1):
    if with_me:
        assert len(value_functions) == 9
    else:
        assert len(value_functions) == 10
    task = TexasHoldemTask()
    config = setup_config(max_round=max_round,
                          initial_stack=10000,
                          small_blind_amount=25)
    config.set_blind_structure(blind_structure)
    for name, value_func in zip(names, value_functions):
        config.register_player(
            name, PokerPlayer(task, value_func, debug=verbose == 1))
    if with_me:
        config.register_player("console", ConsolePlayer())
    return start_poker(config, verbose=verbose)
예제 #22
0
def train(rank, shared_model, optimizer):
    my_player = A3Cplayer(rank, shared_model, optimizer)

    config = setup_config(max_round=50,
                          initial_stack=1500,
                          small_blind_amount=15)
    config.register_player(name="p1", algorithm=my_player)
    config.register_player(name="p2", algorithm=HonestPlayer())
    config.register_player(name="p3", algorithm=AggressivePlayer())
    config.register_player(name="p4", algorithm=RandomPlayer())
    config.register_player(name="p5", algorithm=CallerPlayer())

    for i_episode in range(1000000):
        game_result = start_poker(config, verbose=0)
        if my_player.epsilon > 0:
            my_player.epsilon -= 0.05
예제 #23
0
def main(coef_raise, coef):
    model1 = NN_3J()
    model1.load_state_dict(torch.load('model_hyppo_3J.pth'))
    model1.eval()
    mean3J = np.asarray([
        25.62989439, 506.31789281, 500.85171349, 492.83039371, 8.46048567,
        29.11114304, 35.52415763, 127.08888929
    ])
    var3J = np.asarray([
        77.21836346, 20549.21166419, 23143.48462078, 23994.43942467,
        208.35494771, 6671.09516214, 8899.36275071, 22232.29371878
    ])

    model2 = NN_2J()
    model2.load_state_dict(torch.load('model_hyppo_2J.pth'))
    model2.eval()
    mean2J = np.asarray([
        37.99850064, 665.80849344, 692.35777389, 15.20394244, 56.24048568,
        160.47079922
    ])
    var2J = np.asarray([
        226.25168453, 59823.15358233, 91017.39574507, 440.05912923,
        23585.63323956, 41242.62439903
    ])

    config = setup_config(max_round=1000,
                          initial_stack=500,
                          small_blind_amount=10)
    config.register_player(name="h1",
                           algorithm=HipoPlayer(model3J=model1,
                                                mean3J=mean3J,
                                                var3J=var3J,
                                                model2J=model2,
                                                mean2J=mean2J,
                                                var2J=var2J,
                                                coef_raise=coef_raise,
                                                coef=coef))
    #config.register_player(name="r1", algorithm=RandomPlayer())
    config.register_player(name="f1", algorithm=CallBot())
    config.register_player(name="f2", algorithm=CallBot())

    game_result = start_poker(config, verbose=0)

    if (game_result["players"][0]["stack"] > 1000):
        return 1
    else:
        return 0
예제 #24
0
    def start_real_game(self, players, ai_version='5'):
        ai_params = {
            '3': {
                'class': DQNPlayerV3And4,
                'model': '3200'
            },
            '4': {
                'class': DQNPlayerV3And4,
                'model': '9999'
            },
            '5': {
                'class': DQNPlayerV5,
                'model': '19999'
            },
        }
        path = './models/v' + ai_version + '/model_v' + ai_version + '-' + ai_params[
            ai_version]['model'] + '.ckpt'
        tf.reset_default_graph()
        main_qn = ai_params[ai_version]['class'](
            learning_rate=self.learning_rate,
            discount=self.y,
            nb_players=self.nb_players,
            start_stack=self.start_stack,
            max_round=self.max_rounds)

        init = tf.global_variables_initializer()
        self.saver = tf.train.Saver()

        with tf.Session() as sess:
            sess.run(init)
            main_qn.set_session(sess)
            self.saver.restore(sess, path)
            config = setup_config(max_round=self.max_rounds,
                                  initial_stack=self.start_stack,
                                  small_blind_amount=5)
            i = 1
            for player in players:
                config.register_player(
                    name='p' + str(i),
                    algorithm=player['class'](**player['kwargs']))
                i += 1
            config.register_player(name='p' + str(i), algorithm=main_qn)
            game_result = start_poker(config, verbose=0)
            return game_result
예제 #25
0
def eval_player(num_evals=5, other_bots=[HonestPlayer(1000) for _ in range(8)],
                my_bot=HonestPlayer2(1000)):
    config = setup_config(max_round=50, initial_stack=1500, small_blind_amount=15)
    # add my player
    config.register_player(name="my_bot", algorithm=my_bot)
    # add other players
    for i, b in enumerate(other_bots):
        config.register_player(name="other_{}".format(i + 1), algorithm=b)

    result_dict = {}
    for _ in range(num_evals):
        game_result = start_poker(config, verbose=0)

        # add results
        for k in game_result['players']:
            result_dict.setdefault(k['name'], 0)
            result_dict[k['name']] += k['stack'] / num_evals

    return result_dict
예제 #26
0
def init():
    config = setup_config(max_round=MAX_ROUND,
                          initial_stack=10000,
                          small_blind_amount=10)

    player = LearningPlayer(LOG_LEVEL)
    player.load_qtable_from_file("gen-2-100.txt")
    player2 = RVPlayer()
    # player2.load_qtable_from_file("gen-0-700-fixed.txt")
    atexit.register(exithandler, player, player2)

    config.register_player(name="RVPlayer", algorithm=player2)
    config.register_player(name="learn1", algorithm=player)
    total_start_time = time.time()
    total_rounds = 0

    last_unseen = 0
    for i in range(NUM_GAMES):
        start_time = time.time()
        game_result = start_poker(config, verbose=LOG_LEVEL)
        window['game_count'] += 1

        num_rounds = player.num_rounds_this_game
        total_rounds += num_rounds
        print("Game #{} {} rounds - {}s".format(i + 1, num_rounds,
                                                time.time() - start_time))
        print("Unseen hands: {}".format(player.unseen_hands))
        print("Unseen states: {}".format(player.unseen_states - last_unseen))
        last_unseen = player.unseen_states
        print("\n".join(
            list(
                map(lambda p: "{}: {}".format(p['name'], p['stack']),
                    game_result['players']))))
        print()
        if i > 0 and i % DUMP_INTERVAL == 0:
            player.write_table(i)

    print("Unseen hands: {}".format(player.unseen_hands))
    print("Unseen states: {}".format(player.unseen_states))
    print("Total - {} games, {} rounds, {}s".format(
        NUM_GAMES, total_rounds,
        time.time() - total_start_time))
예제 #27
0
def play_game(game_no, conf):
    n_players = conf['n_players']

    config = setup_config(
        max_round=conf['max_round'],
        initial_stack=conf['initial_stack'],
        small_blind_amount=conf['small_blind_amount'],
        summary_file=None)

    bots = list()
    for bot in conf['bots']:
        m = importlib.import_module(bot['module'])
        cl = getattr(m, bot['class'])
        props = bot.get('properties', dict())
        bots.append((cl, props))

    players = np.random.choice(len(bots), n_players, replace=False)

    for idx in players:
        pl_cls, pl_props = bots[idx]
        pl = pl_cls(pl_props)
        config.register_player(name=pl.__class__.__name__, algorithm=pl)

    print('Starting game {}'.format(game_no))
    game_result = start_poker(config, verbose=0)
    pre_result = dict()
    for p in game_result['players']:
        nm = p['name']
        stack = p['stack']
        if nm in pre_result:
            pre_result[nm] = (pre_result[nm][0] + stack, pre_result[nm][1] + 1)
        else:
            pre_result[nm] = (stack, 1)

    result = dict((nm, stat[0]/float(stat[1])) for nm, stat in pre_result.items())

    for name, score in result.items():
        print('Game #{}, {}: {}'.format(game_no, name, score))

    return result
예제 #28
0
def test(rank, shared_model):
    torch.manual_seed(123)
    my_player = A3Cplayer(rank, shared_model, training=False)
    my_player.epsilon = 0

    config = setup_config(max_round=50,
                          initial_stack=1500,
                          small_blind_amount=15)
    config.register_player(name="p1", algorithm=my_player)
    config.register_player(name="p2", algorithm=HonestPlayer())
    config.register_player(name="p3", algorithm=AggressivePlayer())
    config.register_player(name="p4", algorithm=RandomPlayer())
    config.register_player(name="p5", algorithm=CallerPlayer())

    for i_episode in range(1000000):
        game_result = start_poker(config, verbose=0)
        print(
            rank, game_result['players'][0],
            "random {} real {}".format(my_player.random_action,
                                       my_player.real_action))
        my_player.random_action = 0
        my_player.real_action = 0
예제 #29
0
    def run_evaluation(self, verbose: int = 0) -> Dict[str, int]:
        if len(self.config.players_info) <= 1:
            raise AssertionError("At least two players have to be seated.")

        game_result = start_poker(self.config,
                                  verbose=verbose,
                                  cashgame=True,
                                  log_file_location=self.log_file_location)

        # Prettify game result:
        for player in game_result['players']:
            self.player_final_stack[player['name']] = player['cashgame_stack']
        self.player_final_stack = {
            k: v
            for k, v in sorted(self.player_final_stack.items(),
                               key=lambda item: item[1],
                               reverse=True)
        }

        # Print out game result
        for rank, (name, stack) in enumerate(self.player_final_stack.items()):
            print(f"{rank + 1:2}. Player: {name:>25}, Stack: {stack:n}")

        return self.player_final_stack
예제 #30
0
 def test_start_poker_validation_when_one_player(self):
     config = G.setup_config(1, 100, 10)
     config.register_player("p1", FoldMan())
     with self.assertRaises(Exception) as e:
         result = G.start_poker(config)
     self.assertIn("only 1 player", str(e.exception))
예제 #31
0
 def test_start_poker_validation_when_one_player(self):
     config = G.setup_config(1, 100, 10)
     config.register_player('p1', FoldMan())
     with self.assertRaises(Exception) as e:
         result = G.start_poker(config)
     self.assertIn('only 1 player', str(e.exception))
예제 #32
0
 def test_start_poker_validation_when_no_player(self):
     config = G.setup_config(1, 100, 10)
     with self.assertRaises(Exception) as e:
         result = G.start_poker(config)
     self.assertIn('no player', str(e.exception))
예제 #33
0
from pypokerengine.api.game import setup_config, start_poker

from NNPlayer import NNPlayer

config = setup_config(max_round=10, initial_stack=100, small_blind_amount=5)
config.register_player(name="p1", algorithm=NNPlayer())
config.register_player(name="p2", algorithm=NNPlayer())
game_result = start_poker(config, verbose=1)
예제 #34
0
 def test_start_poker_validation_when_no_player(self):
     config = G.setup_config(1, 100, 10)
     with self.assertRaises(Exception) as e:
         result = G.start_poker(config)
     self.assertIn("no player", str(e.exception))
예제 #35
0
파일: simulate.py 프로젝트: wennho/mysite
import numpy as np
from pypokerengine.api.game import start_poker, setup_config

from .players.fish_player import FishPlayer
from .players.monte_carlo_player import MonteCarloPlayer

if __name__ == '__main__':
    blogger_bot = MonteCarloPlayer()

    # The stack log contains the stacks of the Data Blogger bot after each game (the initial stack is 100)
    stack_log = []
    for round in range(1000):
        p1, p2 = blogger_bot, FishPlayer()

        config = setup_config(max_round=5, initial_stack=100, small_blind_amount=5)
        config.register_player(name="p1", algorithm=p1)
        config.register_player(name="p2", algorithm=p2)
        game_result = start_poker(config, verbose=0)

        stack_log.append([player['stack'] for player in game_result['players'] if player['uuid'] == blogger_bot.uuid])
        print('Avg. stack:', '%d' % (int(np.mean(stack_log))))