def compute_action(self, state): # convert tensor for rl builder = PokerTreeBuilder() state_tensor = builder.statenode_to_tensor(state) # !!!! the return action is a longTensor[[]] # action_id = (self.table_sl.select_action(state) if random.random() > arguments.eta \ # else self.dqn_optim.select_action(state_tensor))[0][0] # action_id = self.table_sl.select_action(state)[0][0] action_id = self.net_sl[state.node.current_player].select_action( state_tensor).item() # print('_____________') # print(action_id) # print('_____________') # action['action: ,'raise_amount': ] action = {} #fold if action_id == 0: action['action'] = constants.acpc_actions.fold # call elif action_id == 1 or action_id >= game_settings.actions_count: action['action'] = constants.acpc_actions.ccall #raise elif action_id > 1: # get possible to determine the raising size bet_sizding = BetSizing(arguments.Tensor(arguments.bet_sizing)) possible_bets = bet_sizding.get_possible_bets(state.node) if possible_bets.dim() != 0: possible_bet = possible_bets[:, state.node.current_player] else: action['action'] = constants.acpc_actions.ccall return action raise_action_id = action_id - 2 # to override fold and call action # node possible bet in this state so call action['action'] = constants.acpc_actions.rraise if (len(possible_bet) <= raise_action_id): action['raise_amount'] = possible_bet[len(possible_bet) - 1].item() else: action['raise_amount'] = possible_bet[raise_action_id].item( ) # to override fold and call action else: assert (False) #invaild actions return action
params['root_node']['board'] = card_to_string.string_to_board('') params['root_node']['street'] = 0 params['root_node']['current_player'] = constants.players.P1 params['root_node']['bets'] = arguments.Tensor([100, 100]) params['limit_to_street'] = False tree = builder.build_tree(params) table_sl = torch.load('/home/mjb/Nutstore/deepStack/Data/Model/Iter:' + str(model_num) + '.sl') dqn = DQN() if torch.cuda.is_available(): dqn.cuda() dqn.load_state_dict( torch.load('/home/mjb/Nutstore/deepStack/Data/Model/Iter:' + str(model_num) + '.rl')) #dfs_fill_table(tree, table_sl, dqn, builder) acc_list = [] acc_node = {} builder.acc_node(tree, acc_node, acc_list) state = GameState() state.private = [arguments.Tensor([0]), arguments.Tensor([2])] state.node = acc_node['858'] print(dqn(Variable(builder.statenode_to_tensor(state)))) #visualiser = TreeVisualiser() #visualiser.graphviz(tree,"table_sl:" + str(model_num))
#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ Created on Tue Aug 22 01:30:35 2017 @author: mjb """ import Settings.game_settings as game_settings import Game.card_to_string as card_to_string import Settings.arguments as arguments from Tree.tree_builder import PokerTreeBuilder from Tree.tree_visualiser import TreeVisualiser import Settings.constants as constants from nn.state import GameState from nn.env import Env builder = PokerTreeBuilder() env = Env() env.reset() tensor = builder.statenode_to_tensor(env.state) print(tensor.size(0))