Пример #1
0
    def __init__(self, starting_stack, small_blind):
        self.pok = PokerUtils()
        self.starting_stack = starting_stack
        self.small_blind = 10
        self.emulator = Emulator()
        self.emulator.set_game_rule(player_num=2,
                                    max_round=10,
                                    small_blind_amount=small_blind,
                                    ante_amount=0)

        self.hole_cards = {}
        self.players_info = {
            "bb_player": {
                "name": "bb_player",
                "stack": starting_stack
            },
            "sb_player": {
                "name": "sb_player",
                "stack": starting_stack
            },
        }

        self.initial_game_state = self.emulator.generate_initial_game_state(
            self.players_info)

        self.players_cards = [np.zeros(13), np.zeros(13)]
        self.suited = [0, 0]
        self.street = 'preflop'
        self.events = []
        self.game_state = []
Пример #2
0
    def __init__(self):
        self.emulator = Emulator()
        #try:
        self._sigma = pickle.load(open("strategy.pickle", "rb"))
        #except (OSError, IOError, EOFError) as e:
            #self._sigma = {}
            #pickle.dump(self._sigma, open("strategy.pickle", "wb"))

        self.cumulative_regrets = {}
        self.cumulative_sigma = {}
Пример #3
0
    def receive_game_start_message(self, game_info):
        player_num = game_info["player_num"]
        max_round = game_info["rule"]["max_round"]
        small_blind_amount = game_info["rule"]["small_blind_amount"]
        ante_amount = game_info["rule"]["ante"]
        blind_structure = game_info["rule"]["blind_structure"]

        self.emulator = Emulator()
        self.emulator.set_game_rule(player_num, max_round, small_blind_amount,
                                    ante_amount)
        self.emulator.set_blind_structure(blind_structure)
Пример #4
0
 def __init__(self, hole_card, player, state, num_rounds, valid_actions,
              round_state, weights):
     self.hole_card = hole_card
     self.player = player
     self.init_state = state
     self.emulator = Emulator()
     self.num_rounds = num_rounds
     self.valid_actions = valid_actions
     self.weights = weights
     self.round_state = round_state
     self.emulator.set_game_rule(2, self.num_rounds, 10, 0)
Пример #5
0
    def __init__(self):
        self.table = {}
        self.table1 = {}
        self.belief = {}
        # self.opponent_belief ={}
        self.uuid = None
        self.opponent = None
        self.emulator = Emulator()
        self.emulator.set_game_rule(2, 1, 10, 0)

        self.current_cost = 10
        self.random_game_state = None
Пример #6
0
    def receive_game_start_message(self, game_info):
        self.my_model = MyModel()
        nb_player = game_info['player_num']
        max_round = game_info['rule']['max_round']
        sb_amount = game_info['rule']['small_blind_amount']
        ante_amount = game_info['rule']['ante']

        self.emulator = Emulator()
        self.emulator.set_game_rule(nb_player, max_round, sb_amount, ante_amount)
        for player_info in game_info['seats']:
            uuid = player_info['uuid']
            player_model = self.my_model if uuid == self.uuid else self.opponents_model
            self.emulator.register_player(uuid, player_model)
Пример #7
0
    def receive_game_start_message(self, game_info):
        player_num = game_info["player_num"]
        max_round = game_info["rule"]["max_round"]
        small_blind_amount = game_info["rule"]["small_blind_amount"]
        ante_amount = game_info["rule"]["ante"]
        blind_structure = game_info["rule"]["blind_structure"]

        self.emulator = Emulator()
        self.emulator.set_game_rule(player_num, max_round, small_blind_amount,
                                    ante_amount)
        self.emulator.set_blind_structure(blind_structure)

        # Register algorithm of each player which used in the simulation.
        for player_info in game_info["seats"]["players"]:
            self.emulator.register_player(player_info["uuid"], RandomPlayer())
Пример #8
0
    def receive_game_start_message(self, game_info):
        self.my_model = MyModel()
        self.n
        community_card = round_state['community_card']b_player = game_info['player_num']
        max_round = game_info['rule']['max_round']
        sb_amount = game_info['rule']['small_blind_amount']
        ante_amount = game_info['rule']['ante']

        self.emulator = Emulator()
        self.emulator.set_game_rule(nb_player, max_round, sb_amount, ante_amount)
        for player_info in game_info['seats']:
            uuid = player_info['uuid']
            player_model = self.my_model if uuid == self.uuid else FishPlayer()
            #
            #for player_info in game_info["seats"]["players"]:
            #    self.emulator.register_player(player_info["uuid"], HonestPlayer())
            self.emulator.register_player(uuid, player_model)
Пример #9
0
    def receive_game_start_message(self, game_info):
        self.nb_player = game_info['player_num']
        global PLAYER_NUM
        PLAYER_NUM = game_info["player_num"]
        max_round = game_info["rule"]["max_round"]
        small_blind_amount = game_info["rule"]["small_blind_amount"]
        ante_amount = game_info["rule"]["ante"]
        blind_structure = game_info["rule"]["blind_structure"]

        for i in range(0, len(game_info['seats'])):
            if (game_info['seats'][i]['name'] == 'q-learning'):
                self._uuid = game_info['seats'][i]['uuid']

        self.emulator = Emulator()
        self.emulator.set_game_rule(PLAYER_NUM, max_round, small_blind_amount,
                                    ante_amount)
        self.emulator.set_blind_structure(blind_structure)
Пример #10
0
def emulate(hole_card, round_state):
      # 1. Set game settings in Emulator
      emulator = Emulator()
      sb_amount = round_state['small_blind_amount']
      # emulator(nb_player,max_rounds,sb_amount,ante)
      emulator.set_game_rule(2, 10, sb_amount, 1)
          
      # 2. Setup Gamestate object      

      game_state = restore_game_state(round_state)
      
      # Attach hole_cards for each player (at random for opponent)
      game_state = attach_hole_card(game_state,round_state['seats'][0]['uuid'], gen_cards(hole_card))
      game_state = attach_hole_card_from_deck(game_state,round_state['seats'][1]['uuid'])
      
      # 3. Run simulation and get updated GameState object
      # updated_state, events = emulator.apply_action(game_state, "call", 10)
        
      return game_state, emulator
Пример #11
0
    def __init__(self,
                 final_round=max_round,
                 scale_reward=False,
                 lose_penalty=False,
                 shuffle_position=False,
                 action_record=False):
        self.final_round = final_round
        self.scale_reward = scale_reward
        self.lose_penalty = lose_penalty
        self.shuffle_position = shuffle_position
        self.action_record = action_record
        self.emulator = Emulator()
        self.emulator.set_game_rule(nb_player, final_round, sb_amount, ante)
        self.emulator.set_blind_structure(blind_structure)
        self.opponent_value_functions = {}
        if shuffle_position:
            print "Warning: shuffle_position is set True. Are you sure?"

        for uuid in players_info:
            self.emulator.register_player(uuid, DummyPlayer())
            if uuid != my_uuid: self.opponent_value_functions[uuid] = None
Пример #12
0
    def receive_game_start_message(self, game_info):
        self.nb_player = game_info['player_num']
        self.small_blind_amount = game_info['rule']['small_blind_amount']
        self.Opponent_Model.set_nb_player(self.nb_player)
        self.my_model = MyModel()
        max_round = game_info['rule']['max_round']
        sb_amount = game_info['rule']['small_blind_amount']
        ante_amount = game_info['rule']['ante']

        for player in game_info['seats']:
            if player['uuid'] == self.uuid:
                self.seat = game_info['seats'].index(player)
                break
            else:
                raise ('not participating!')

        self.emulator = Emulator()
        self.emulator.set_game_rule(self.nb_player, max_round, sb_amount,
                                    ante_amount)
        for player_info in game_info['seats']:
            uuid = player_info['uuid']
            player_model = self.my_model if uuid == self.uuid else self.Opponent_Model
            self.emulator.register_player(uuid, player_model)
Пример #13
0
    def receive_game_start_message(self, game_info):
        # self.my_name = game_info['seats'][self.my_seat]['name']
        if self.study_mode:
            self.uuid = game_info["seats"][self.my_seat]['uuid']
        self.stats.init_player_names(game_info)
        self.player_num = game_info["player_num"]
        self.max_round = game_info["rule"]["max_round"]
        self.small_blind_amount = game_info["rule"]["small_blind_amount"]
        self.ante_amount = game_info["rule"]["ante"]
        # self.blind_structure = game_info["rule"]["blind_structure"]

        self.emulator = Emulator()
        self.emulator.set_game_rule(self.player_num, self.max_round,
                                    self.small_blind_amount, self.ante_amount)
        # self.emulator.set_blind_structure(blind_structure)

        if self.study_mode:
            # Register algorithm of each player which used in the simulation.
            for i in np.arange(self.player_num):
                self.emulator.register_player(
                    uuid=game_info["seats"][i]["uuid"],
                    player=self.players[i]
                    if self.players[i] is not None else self)
Пример #14
0
 def __init__(self):
     self.game_states_ = dict()  # maps history to node
     self.emulator = Emulator()
Пример #15
0
def initialize_new_emulator(player_num, max_round, small_blind_amount, ante_amount):
    emulator = Emulator()
    emulator.set_game_rule(player_num=player_num, max_round=max_round, small_blind_amount=small_blind_amount, ante_amount=ante_amount)
    return emulator
Пример #16
0
 def setUp(self):
     self.emu = Emulator()
Пример #17
0
def run_episode(agents):
    emulator = Emulator()
    temp_final_state = {}
    winner_counts = [0] * N_AGENTS
    n_games_played = 0
    for game in range(GAMES_PER_EPISODE):
        wrappers = []
        player_info = {}
        for i, agent in enumerate(agents):
            if PERSISTENT_STACKS:
                if temp_final_state:
                    for seat in temp_final_state:
                        player_info[seat.uuid] = {'name': 'Player ' + str(seat.uuid),
                                                  'stack': seat.stack if seat.stack else STACK_SIZE}
                else:
                    player_info[i] = {'name': 'Player ' + str(i), 'stack': STACK_SIZE}
            else:
                player_info[i] = {'name': 'Player ' + str(i), 'stack': STACK_SIZE}

            wrappers.append(DQNAgentWrapper(agent, STACK_SIZE))
            emulator.register_player(uuid=i, player=wrappers[-1])
        emulator.set_game_rule(N_AGENTS, 2, BB_SIZE / 2, 0)
        initial_game_state = emulator.generate_initial_game_state(player_info)

        game_state, events = emulator.start_new_round(initial_game_state)
        game_finish_state, events = emulator.run_until_round_finish(game_state)

        # import json
        # if game == 0 or game == 1:
        #     print('dumping')
        #     with open('event_dump_' + str(game), 'w') as f:
        #         json.dump(events, f, indent=2)
        if 'winners' not in events[-1]:
            events.pop()

        winner = events[-1]['winners'][0]['uuid']
        winner_counts[winner] += 1
        n_games_played += 1

        for i in range(N_AGENTS):
            new_stack_size = game_finish_state['table'].seats.players[i].stack
            reward = (new_stack_size - wrappers[i].prev_stack_size) / BB_SIZE
            #print('Remembering {} reward for {} action'.format(reward, wrappers[i].prev_action))
            wrappers[i].agent.remember(wrappers[i].prev_state, wrappers[i].prev_action, reward, None, 1)

        temp_final_state = game_finish_state['table'].seats.players

        # print('====')
        print('\rGame:{}, epsilon:{}'.format(game, wrappers[0].agent.epsilon), end='')
        # print(game_finish_state)
        # print('\n')
        # print(events[-5:])
        # print('====')

        if (game % REPLAY_EVERY_N_GAMES == 0) or (game == GAMES_PER_EPISODE - 1):
            # replay memory for every agent
            # for agent in agents:
            #     agent.replay(BATCH_SIZE)
            agents[0].replay(BATCH_SIZE)

        for i in range(N_AGENTS):
            agents[i].model.reset_states()

    clear_memory()
    return agents[0], temp_final_state, winner_counts, n_games_played
Пример #18
0
 def __init__(self, game_state, hole_card, player):
     self.player = player
     self.initial_state = game_state
     self.hole_card = hole_card
     self.emulator = Emulator()
     self.emulator.set_game_rule(2, 10, 10, 0)
Пример #19
0
 def __init__(self, model_player, my_model):
     super(EmulatorPlayer, self).__init__()
     self.opponents_model = model_player
     self.my_model = my_model
     self.emulator = Emulator()
Пример #20
0
from pypokerengine.api.emulator import Emulator
from honest_player_og import HonestPlayer
from random_player import RandomPlayer
from risky_player import RiskyPlayer
from qlearner import RLPlayer
import pandas as pd
import numpy as np

# 1. Set game settings on emulator
n_players = 2
emulator = Emulator()
quuid = "uuid-q"
qlearner_player = RLPlayer(n_players, quuid)
df1 = pd.DataFrame(columns=['uuid', 'win_ratio', 'stack-diff'])
df2 = pd.DataFrame(columns=['uuid', 'win_ratio', 'stack-diff'])
df3 = pd.DataFrame(columns=['uuid', 'win_ratio', 'stack-diff'])
df4 = pd.DataFrame(columns=['uuid', 'win_ratio', 'stack-diff'])
max_round = 50
learning_rates = np.arange(0.1, 1, 0.1)
#learning_rates = [0.3]
for j in learning_rates:
    qlearner_player = RLPlayer(n_players, quuid, j)
    for i in range(0, 150):
        emulator.register_player(uuid="uuid-1", player=HonestPlayer(n_players))
        #emulator.register_player(uuid="uuid-2", player=RiskyPlayer(n_players))
        emulator.register_player(uuid=quuid, player=qlearner_player)
        emulator.set_game_rule(player_num=n_players,
                               max_round=max_round,
                               small_blind_amount=20,
                               ante_amount=0)
        players_info = {
Пример #21
0
from console_player import ConsolePlayer
from pypokerengine.api.emulator import Emulator
from bot import PGBot
from pypokerengine.utils.game_state_utils import attach_hole_card_from_deck, attach_hole_card, replace_community_card
from pypokerengine.utils.card_utils import gen_cards

SAVE_PATH = 'saved_models/second_test/policy_net_after'

STACK = 1000
N_PLAYER = 2
MAX_ROUND = 2
SMALL_BLIND_AMOUNT = 5
ANTE_AMOUNT = 1

if __name__ == '__main__':
    emul = Emulator()
    emul.set_game_rule(N_PLAYER, MAX_ROUND, SMALL_BLIND_AMOUNT, ANTE_AMOUNT)
    console = ConsolePlayer()
    bot = PGBot("bot", pickle.load(open(SAVE_PATH + "105980", "rb")))
    emul.register_player("target", bot)
    emul.register_player("baseline", console)
    players_info = {
        "target": {
            "name": "PGBot",
            "stack": STACK
        },
        "baseline": {
            "name": "console",
            "stack": STACK
        }
    }