示例#1
0
    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)
示例#2
0
    def test_board_to_street(self):
        board = arg.IntTensor([]).to(arg.device)
        street = card_tools.board_to_street(board)
        self.assertEqual(street, 0)

        board = arg.IntTensor([2]).to(arg.device)
        street = card_tools.board_to_street(board)
        self.assertEqual(street, 1)
示例#3
0
 def test_build_tree(self):
     params = TreeParams()
     params.root_node = Node()
     params.root_node.board = card_to_string.string_to_cards('')
     params.root_node.board_string = ''
     params.root_node.street = 0
     params.root_node.current_player = constants.players.P1
     params.root_node.bets = arg.IntTensor([1, 1]).to(arg.device)
     root = tree_builder.build_tree(params)
     tree_visulizer.draw_tree(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 test_build_tree(self):
     params = TreeParams()
     params.root_node = Node()
     params.root_node.board = card_to_string.string_to_cards('')
     params.root_node.board_string = ''
     params.root_node.street = 0
     params.root_node.current_player = constants.players.P1
     params.root_node.bets = arg.IntTensor([1, 1]).to(arg.device)
     root = tree_builder.build_tree(params)
     self.terminal_node = 0
     self.chacne_node = 0
     self.else_node = 0
     self.dfs(root)
示例#6
0
import context
import torch
from base import TreeParams, Node
from settings import arg, constants
from game import card_to_string, card_tools
from tree import tree_builder, TreeCFR, tree_visulizer, tree_strategy_sl

params = TreeParams()
params.root_node = Node()
params.root_node.board_string = arg.board_string
params.root_node.board = card_to_string.string_to_cards(arg.board_string)
params.root_node.street = arg.street
params.root_node.current_player = constants.players.P1
params.root_node.bets = arg.IntTensor([100, 100]).to(arg.device)
root = tree_builder.build_tree(params)

starting_range = torch.zeros([constants.players_count, constants.card_count],
                             dtype=arg.dtype).to(arg.device)
starting_range[0] = card_tools.get_uniform_range(params.root_node.board)
starting_range[1] = card_tools.get_uniform_range(params.root_node.board)

tree_cfr = TreeCFR()
tree_cfr.run_cfr(root, starting_range)

tree_visulizer.draw_tree(root)

tree_strategy_sl.save_strategy(root)
示例#7
0
 def test_get_second_round_boards(self):
     boards = card_tools.get_second_round_boards()
     out = arg.IntTensor([[0], [1], [2], [3], [4], [5]]).to(arg.device)
     torch.testing.assert_allclose(boards, out)
示例#8
0
 def test_get_possible_hand_index(self):
     board = arg.IntTensor([5]).to(arg.device)
     possible_hand = card_tools.get_possible_hand_index(board)
     out = arg.IntTensor([1, 1, 1, 1, 1, 0]).to(arg.device)
     torch.testing.assert_allclose(possible_hand, out)
示例#9
0
 def test_get_hand_strength(self):
     board = arg.IntTensor([5]).to(arg.device)
     strength = card_tools.get_hand_strength(board)
     out = arg.IntTensor([1, 1, 2, 2, 4, 4]).to(arg.device)
     torch.testing.assert_allclose(strength, out)