Пример #1
0
def parse_matchstate(ms, p):
    global priv_types
    global pub_types
    ms_spl = ms.split(":")
    #print >>sys.stderr,  ms_spl
    cmd, pos, hand_n, betting, cards = ms_spl
    bets = betting.split("/")
    #print >>sys.stderr,  bets
    hi = dt.hand_info()
    hi.root_us = C.pointer(p.root_state.unique_root_node)
    hi.cur_us = C.pointer(p.root_state.unique_root_node)
    
    for i in xrange(4):
        hi.acts_i[i] = 0
    lzp.add_action_to_hi(C.pointer(hi), 0)
    lzp.add_action_to_hi(C.pointer(hi), 0)

    #test_path = np.zeros(256, dtype=np.int8)
    #test_path_i = 2


    for i, street in enumerate(bets):
        for act in street:
            act_i = 1
            if act == "r":
                act_i = 0
            elif act == "c":
                act_i = 1
            elif act == "f":
                act_i = 2
            lzp.add_action_to_hi(C.pointer(hi), act_i)
            #test_path[test_path_i] = act_i
            #test_path_i+=1
            #us = p.get_unique_state_from_path(bets)
    if not hi.cur_us or hi.cur_us.contents.gamestate == 4:
        #print >>sys.stderr,  "No unique state"
        return None
    pos = int(pos)
    hand_n = int(hand_n)

    if hi.cur_us.contents.root_idx == 2:
        #new hand
        pub_types = np.zeros(p.zp.i.n_type_types[1], dtype=np.int16)
        pub_types.fill(-1)
        #test_pub_types = np.zeros(p.zp.i.n_type_types[1], dtype=np.int16)
        priv_types = np.zeros(p.zp.i.n_type_types[0], dtype=np.int16)
        priv_types.fill(-1)
    else:
        pub_types[:7] = -1

    if hi.cur_us.contents.cur_seat != pos:
        #print >>sys.stderr,  "NOT MY TURN"
        return None
    print >>sys.stderr
    print >>sys.stderr,  "ACTS", bets
    #print >>sys.stderr,  "MY TURN"
    cards_spl = cards.split("/")
    hole_cards = cards_spl[0]
    board = cards_spl[1:]
    bc = []
    print >>sys.stderr,  "BOARD",
    for b in board:
        print >>sys.stderr,  b,
        while len(b) >= 2:
            bc.append(ct.stoi[b[:2]])
            b = b[2:]
    print >>sys.stderr

    for i, c in enumerate(bc):
        hi.board[i] = c
    
    hole_spl = hole_cards.split("|")
    self_hand = hole_spl[pos]

    print >>sys.stderr,  "HOLE", self_hand

    assert(len(self_hand) == 4)
    self_hand = [ct.stoi[self_hand[:2]], ct.stoi[self_hand[2:]]]

    for i, c in enumerate(self_hand):
        hi.hole_cards[i] = c

    lzp.set_st_from_hand_info(C.pointer(p.zp.i), C.pointer(hi), pub_types.ctypes.data_as(C.POINTER(C.c_int16)),priv_types.ctypes.data_as(C.POINTER(C.c_int16)))
    #lzp.set_mutable_types_from_path(test_pub_types.ctypes.data_as(C.POINTER(C.c_int16)), test_path.ctypes.data_as(C.c_char_p), test_path_i, C.pointer(p.root_state.unique_root_node))
    #print >>sys.stderr,  pub_types
    #print >>sys.stderr,  test_pub_types
    action_odds = p.us_by_id(hi.cur_us.contents.root_idx).get_action_odds_from_file(p.model_path, pub_types, priv_types, src)

    #print >>sys.stderr,  self_hand, board
    print >>sys.stderr,  "ACTION ODDS", action_odds
#    hs = p.zp.get_hand_slot(bc, self_hand)
#    print >>sys.stderr,  "self hand", self_hand, hs
#    board_slots = p.zp.get_board_slots_all_gs(bc)
#    print >>sys.stderr,  board_slots
    
#    us = p.get_unique_state_from_path(bets)    
    return action_odds
Пример #2
0
zp.load_diffs_for_all_types()
zp.load_slots_for_all_types()
zp.set_info_pointers()

board_combo_types = np.fromfile(sys.argv[1], dtype=np.int16).reshape(
    (16384, 3))

b_diffs = [None] * 4
max_diff = np.zeros(4, dtype=np.float32)
for i in xrange(1, 4):
    b_diffs[i] = np.ctypeslib.as_array(zp.i.b_diffs[i], shape=(1024, 1024))
    b_diffs[i][np.where(b_diffs[i] > 100000000)] = 0
    max_diff[i] = b_diffs[i].max()
    #b_diffs[i]/=max_diff[i]

hi = dt.hand_info()
pub_types = np.zeros(zp.i.n_type_types[1], dtype=np.int16)
pub_types.fill(0)
#test_pub_types = np.zeros(p.zp.i.n_type_types[1], dtype=np.int16)
priv_types = np.zeros(zp.i.n_type_types[0], dtype=np.int16)
priv_types.fill(0)

combo_dict = {}

random.seed(1234)

# def rnd_func():
#     c = random.sample(range(52), 5)
#     hi.board[0] = c[0]
#     hi.board[1] = c[1]
#     hi.board[2] = c[2]
Пример #3
0
def parse_matchstate(ms, p):
    global priv_types
    global pub_types
    ms_spl = ms.split(":")
    #print ms_spl
    cmd, pos, hand_n, betting, cards = ms_spl
    bets = betting.split("/")
    #print bets
    hi = dt.hand_info()
    hi.root_us = C.pointer(p.root_state.unique_root_node)
    hi.cur_us = C.pointer(p.root_state.unique_root_node)
    
    for i in xrange(4):
        hi.acts_i[i] = 0
    lzp.add_action_to_hi(C.pointer(hi), 0)
    lzp.add_action_to_hi(C.pointer(hi), 0)

    #test_path = np.zeros(256, dtype=np.int8)
    #test_path_i = 2
    for i, street in enumerate(bets):
        for act in street:
            print act,
            act_i = 1
            if act == "r":
                act_i = 0
            elif act == "c":
                act_i = 1
            elif act == "f":
                act_i = 2
            lzp.add_action_to_hi(C.pointer(hi), act_i)
            #test_path[test_path_i] = act_i
            #test_path_i+=1
            #us = p.get_unique_state_from_path(bets)
        print "|",
    print 
    if not hi.cur_us or hi.cur_us.contents.gamestate == 4:
        #print "No unique state"
        return None
    pos = int(pos)
    hand_n = int(hand_n)

    #   if hi.cur_us.contents.root_idx == 2:
    #   #new hand
    #   pub_types = np.zeros(p.zp.i.n_type_types[1], dtype=np.int16)
    #   pub_types.fill(-1)
    #   #test_pub_types = np.zeros(p.zp.i.n_type_types[1], dtype=np.int16)
    #   priv_types = np.zeros(p.zp.i.n_type_types[0], dtype=np.int16)
    #   priv_types.fill(-1)
    #else:
    #    pub_types[:7] = -1

    if hi.cur_us.contents.cur_seat != pos:
        #print "NOT MY TURN"
        return None

    #print "MY TURN"
    cards_spl = cards.split("/")
    hole_cards = cards_spl[0]
    board = cards_spl[1:]
    bc = []
    print cards_spl
    for b in board:
        while len(b) >= 2:
            if b[:2] == "10":
                bc.append(ct.stoi[b[:3]])
                b = b[3:]
            else:
                bc.append(ct.stoi[b[:2]])
                b = b[2:]
            #print 

    for i, c in enumerate(bc):
        hi.board[i] = c
        
    hole_spl = hole_cards.split("|")
    self_hand = hole_spl[pos]
    assert(len(self_hand) == 4)
    self_hand = [ct.stoi[self_hand[:2]], ct.stoi[self_hand[2:]]]

    for i, c in enumerate(self_hand):
        hi.hole_cards[i] = c

    
    pub_types.fill(-1)
    priv_types.fill(-1)
    lzp.set_st_from_hand_info(C.pointer(p.zp.i), C.pointer(hi), pub_types.ctypes.data_as(C.POINTER(C.c_int16)),priv_types.ctypes.data_as(C.POINTER(C.c_int16)))
    #lzp.set_mutable_types_from_path(test_pub_types.ctypes.data_as(C.POINTER(C.c_int16)), test_path.ctypes.data_as(C.c_char_p), test_path_i, C.pointer(p.root_state.unique_root_node))
    #print pub_types
    #print test_pub_types
    #print pub_types, priv_types
    pub_types[0] = 0
    #action_odds = p.us_by_id(hi.cur_us.contents.root_idx).get_action_odds_from_file(p.model_path, pub_types, priv_types, src)
    us = p.us_by_id(hi.cur_us.contents.root_idx)
    pmn = lzp.get_first_matching_situ_weighed_random(us.unique_root_node.model_tree, pub_types.ctypes.data_as(C.POINTER(C.c_int16)), 0, rng, 0)
    slot_i = lzp.get_closest_local_type(pmn, priv_types[hi.cur_us.contents.gamestate])
    lzp.
    #print pmn.contents.data_index, slot_i
    #    pdb.set_trace()

    # r = us.avg_odds_mmap[pmn.contents.data_index*3+slot_i]
    # c = us.avg_odds_mmap[pmn.contents.data_index*3+pmn.contents.len+slot_i]
    # f = us.avg_odds_mmap[pmn.contents.data_index*3+pmn.contents.len*2+slot_i]

    # tot = r+c+f
    # r/=tot
    # c/=tot
    # f/=tot
    # action_odds_avg = (r,c,f)
    r = float(us.byte_odds_mmap[pmn.contents.data_index*2+ slot_i*2])
    c = float(us.byte_odds_mmap[pmn.contents.data_index*2+ slot_i*2+1])
    f = 255.0-r-c
    if f >= 0:
        #r*=2
        tot = r+c+f
        r/=tot
        c/=tot
        f/=tot
    else:
        print >>sys.stderr, "ZERO INFO", r,c,f, ms
        r = 0.0
        c = 1.0
        f = 0.0
    # pdb.set_trace()
    # if us.gamestate == 3:
    #     td = np.zeros(1, dtype=dt.types_data_np)
    #     deck = np.array(bc, dtype=np.int8)
    #     lzp.gen_types_data(C.pointer(p.zp.i), deck[:5].ctypes.data_as(C.POINTER(C.c_int8)), td.ctypes.data)
    #     assert(tuple(td["public_types"][0][7:10]) == tuple(pub_types[7:10]))
    #     pdb.set_trace()


    action_odds = (r,c,f)

    #print action_odds_avg
    #print action_odds
    #print
    #print self_hand, board
    #print action_odds
#    hs = p.zp.get_hand_slot(bc, self_hand)
#    print "self hand", self_hand, hs
#    board_slots = p.zp.get_board_slots_all_gs(bc)
#    print board_slots
    
#    us = p.get_unique_state_from_path(bets)    
    return action_odds