def test_get_possible_bets(self): node = Node() node.current_player = constants.players.P1 node.street = 0 node.bets = arg.IntTensor([1, 1]).to(arg.device) node.num_bets = 0 possible_bets = bet_sizing.get_possible_bets(node) out = arg.IntTensor([3, 1]).to(arg.device) torch.testing.assert_allclose(possible_bets, out) node = Node() node.current_player = constants.players.P1 node.street = 1 node.bets = arg.IntTensor([3, 5]).to(arg.device) node.num_bets = 0 possible_bets = bet_sizing.get_possible_bets(node) out = arg.IntTensor([9, 5]).to(arg.device) torch.testing.assert_allclose(possible_bets, out) node = Node() node.current_player = constants.players.P1 node.street = 1 node.bets = arg.IntTensor([3, 5]).to(arg.device) node.num_bets = 2 possible_bets = bet_sizing.get_possible_bets(node) out = torch.empty([0, 2], dtype=arg.int_dtype).to(arg.device) torch.testing.assert_allclose(possible_bets, out)
def build_tree(self, params): root = Node() root.street = params.root_node.street root.bets = params.root_node.bets.clone() root.current_player = params.root_node.current_player root.board = params.root_node.board.clone() root.board_string = params.root_node.board_string self.build_tree_dfs(root) return root
def test_get_children_chance_nodes(self): node = Node() node.board_string = '' node.board = card_to_string.string_to_cards(node.board_string) node.street = 0 node.num_bets = 0 node.current_player = constants.players.P1 node.bets = arg.IntTensor([1, 1]).to(arg.device) children = tree_builder.get_children_chance_nodes(node) for child in children: pass
def get_children_player_nodes(self, parent_node): children = [] # fold action fold_node = Node(parent_node) fold_node.terminal = True fold_node.action = "fold" fold_node.node_type = constants.node_types.terminal_fold children.append(fold_node) # P1 start check action if (parent_node.current_player == constants.players.P1 and parent_node.bets[0] == parent_node.bets[1]): check_node = Node(parent_node) check_node.action = "check" children.append(check_node) # raise -> ( P1 / P2 call ) -> chance # P1 check -> (P2 check ) -> chance elif parent_node.street == 0 and ( parent_node.bets[0] != parent_node.bets[1] or parent_node.bets[0] == parent_node.bets[1] and parent_node.current_player == constants.players.P2 ): chance_node = Node(parent_node) chance_node.current_player = constants.players.chance chance_node.bets[:] = chance_node.bets.max() chance_node.action = "call" if parent_node.bets[0] != parent_node.bets[1] else "check" children.append(chance_node) # call -> terminal else: terminal_call_node = Node(parent_node) terminal_call_node.current_player = 1 - constants.players.P2 terminal_call_node.terminal = True terminal_call_node.node_type = constants.node_types.terminal_call terminal_call_node.bets[:] = terminal_call_node.bets.max() terminal_call_node.action = "call" children.append(terminal_call_node) # raise action possible_bets = bet_sizing.get_possible_bets(parent_node) for possible_bet in possible_bets: raise_node = Node(parent_node) raise_node.bets = possible_bet raise_node.num_bets += 1 raise_node.action = "raise" children.append(raise_node) return children