当前位置: 首页>>代码示例>>Python>>正文


Python Card.new方法代码示例

本文整理汇总了Python中deuces.Card.new方法的典型用法代码示例。如果您正苦于以下问题:Python Card.new方法的具体用法?Python Card.new怎么用?Python Card.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在deuces.Card的用法示例。


在下文中一共展示了Card.new方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
    def __init__(self):
        
        card = {}
        deck = []
        ranked_hands = []

        n = 0
        for i in ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']:
            for j in ['s', 'h', 'c', 'd']:
                card[i+j] = Card.new(i+j)
                deck.append(Card.new(i+j))
                n += 1

        for hand in combinations([card['As'], card['Ad'], card['Ac'], card['Ah']], 2):
            ranked_hands.append(set(hand))

        for hand in combinations([card['Ks'], card['Kd'], card['Kc'], card['Kh']], 2):
            ranked_hands.append(set(hand))

        for hand in combinations([card['Qs'], card['Qd'], card['Qc'], card['Qh']], 2):
            ranked_hands.append(set(hand))

        ranked_hands.append(set((card['As'], card['Ks'])))
        ranked_hands.append(set((card['Ad'], card['Kd'])))
        ranked_hands.append(set((card['Ac'], card['Kc'])))
        ranked_hands.append(set((card['Ah'], card['Kh'])))

        for hand in combinations([card['Js'], card['Jd'], card['Jc'], card['Jh']], 2):
            ranked_hands.append(set(hand))

        ranked_hands.append(set((card['As'], card['Qs'])))
        ranked_hands.append(set((card['Ad'], card['Qd'])))
        ranked_hands.append(set((card['Ac'], card['Qc'])))
        ranked_hands.append(set((card['Ah'], card['Qh'])))

        ranked_hands.append(set((card['Ks'], card['Qs'])))
        ranked_hands.append(set((card['Kd'], card['Qd'])))
        ranked_hands.append(set((card['Kc'], card['Qc'])))
        ranked_hands.append(set((card['Kh'], card['Qh'])))

        ranked_hands.append(set((card['As'], card['Js'])))
        ranked_hands.append(set((card['Ad'], card['Jd'])))
        ranked_hands.append(set((card['Ac'], card['Jc'])))
        ranked_hands.append(set((card['Ah'], card['Jh'])))


        ranked_hands.append(set((card['Ks'], card['Js'])))
        ranked_hands.append(set((card['Kd'], card['Jd'])))
        ranked_hands.append(set((card['Kc'], card['Jc'])))
        ranked_hands.append(set((card['Kh'], card['Jh'])))

        for hand in combinations([card['Ts'], card['Td'], card['Tc'], card['Th']], 2):
            ranked_hands.append(set(hand))

        self.ranked_hands = ranked_hands
        self.card_dict = card
        self.deck = deck
        self.evaluator = Evaluator()
开发者ID:edouardswiac,项目名称:PokerBot,代码行数:60,代码来源:PokerMath.py

示例2: encode

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
    def encode(self, plyr_board, oppo_board, current_card,
               plyr_cards, game_over, score):
        current_card = [Card.new(current_card)]
        plyr_cards = [Card.new(x) for x in plyr_cards]

        plyr_front_ranks = self.cards_to_ranks(plyr_board.front.cards, 3)
        plyr_mid_ranks = self.cards_to_ranks(plyr_board.mid.cards, 5)
        plyr_back_ranks = self.cards_to_ranks(plyr_board.back.cards, 5)

        oppo_front_ranks = self.cards_to_ranks(plyr_board.front.cards, 3)
        oppo_mid_ranks = self.cards_to_ranks(plyr_board.mid.cards, 5)
        oppo_back_ranks = self.cards_to_ranks(plyr_board.back.cards, 5)

        plyr_front_suits = self.cards_to_suits(plyr_board.front.cards)
        plyr_mid_suits = self.cards_to_suits(plyr_board.mid.cards)
        plyr_back_suits = self.cards_to_suits(plyr_board.back.cards)

        oppo_front_suits = self.cards_to_suits(plyr_board.front.cards)
        oppo_mid_suits = self.cards_to_suits(plyr_board.mid.cards)
        oppo_back_suits = self.cards_to_suits(plyr_board.back.cards)

        current_card_rank = self.cards_to_ranks(current_card, 1)
        current_card_suit = self.cards_to_suits(current_card)

        remaining_card_ranks = self.cards_to_ranks(plyr_cards, 4)
        remaining_card_suits = self.cards_to_suits(plyr_cards)

        free_streets = np.array(plyr_board.get_free_streets())
        free_streets_std = (free_streets - 0.5) * 2  # Hacky "standardisation"

        encoding = np.hstack([
            plyr_front_ranks,
            plyr_mid_ranks,
            plyr_back_ranks,
            plyr_front_suits,
            plyr_mid_suits,
            plyr_back_suits,
            oppo_front_ranks,
            oppo_mid_ranks,
            oppo_back_ranks,
            oppo_front_suits,
            oppo_mid_suits,
            oppo_back_suits,
            current_card_rank,
            current_card_suit,
            remaining_card_ranks,
            remaining_card_suits,
            free_streets_std
        ])

        return encoding
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:53,代码来源:gamestate_encoder.py

示例3: getRank

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def getRank(num_player,card_player,board_player):
	playerrank=[[]for row in range(num_player)]
	hand=[]*2
	board=[]*5
	for i in range(num_player):
		for t in range(len(card_player[i])):
			hand=[Card.new(card_player[i][t][0]),Card.new(card_player[i][t][1])]
			evaluator=Evaluator()
			board=[Card.new(board_player[i][0]),Card.new(board_player[i][1]),Card.new(board_player[i][2]),Card.new(board_player[i][3]),Card.new(board_player[i][4])]
			rank=evaluator.evaluate(board,hand)
			playerrank[i].append(rank)
			print hand,rank,playerrank[i]
	print playerrank
	return playerrank
开发者ID:gyh2556406,项目名称:cards2,代码行数:16,代码来源:scripttest.py

示例4: test_front_royalties

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def test_front_royalties():
    front = [Card.new(x) for x in ['2h', '2c', '3d']]
    assert RoyaltyCalculator.score_front_royalties(front) == 0

    front = [Card.new(x) for x in ['6h', '6c', '3d']]
    assert RoyaltyCalculator.score_front_royalties(front) == 1

    front = [Card.new(x) for x in ['Ah', 'Ac', '3d']]
    assert RoyaltyCalculator.score_front_royalties(front) == 9

    front = [Card.new(x) for x in ['2h', '2c', '2d']]
    assert RoyaltyCalculator.score_front_royalties(front) == 10

    front = [Card.new(x) for x in ['Ah', 'Ac', 'Ad']]
    assert RoyaltyCalculator.score_front_royalties(front) == 22
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:17,代码来源:test_royalty_calculator.py

示例5: cardsRank

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
 def cardsRank(self, cards):
     evaCards = []
     for card in cards:
         evaCards.append(Card.new(self.ePoint[self.getPointOf(card)] + \
                                  self.eColor[self.getColorOf(card)]))
     rank = self.evaluator.evaluate(evaCards)
     return rank
开发者ID:HuaweiHoldem,项目名称:TexasHoldem-0002,代码行数:9,代码来源:PokerUtils.py

示例6: get_probabilities

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def get_probabilities(card_1, card_2, other_players, trials=10000):
    """
    for a given preflop hand, compute the probabilities of winning or tying.
    Note that we've got a very important design decision here: we could obtain
    the probabilities in a combinatorial fashion -- it's possible to mathematically
    reason to obtain the exact probability of winning or tying, but this seems
    quite involved. It's much easier to use a Monte Carlo simulation to approximate
    the probabilities. With a large number of trials (e.g. 10k or 100k) the
    approximations should be sufficiently close to the theoretical "true" values
    for all practical intents and purposes. 
    """
    deck = map(lambda (x,y): Card.new(y+x), list(product(suits,ranks)))
    wins = 0
    ties = 0
    deck.remove(card_1)
    deck.remove(card_2)
    for i in range(trials):
        # Randomly shuffling the deck and slicing the first few cards to get hands
        # seems computationally cheaper than using random.choice to select subsets as hands
        shuffle(deck)
        shared_cards = deck[:5]
        # hands held by other players
        other_hands = [deck[5+(2*x):7+(2*x)] for x in range(other_players)]
        result = eval_table([card_1, card_2], shared_cards, other_hands)
        if result == WIN:
            wins +=1
        elif result == TIE:
            ties +=1
    return wins/float(trials), ties/float(trials)
开发者ID:Datamine,项目名称:PokerTexter,代码行数:31,代码来源:generate-lookup-table.py

示例7: parse_cards

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def parse_cards(cardstr):
    #have to replace 10 with T for deuces
    cardstr = cardstr.replace('10', 'T')
    cardlist = cardstr.split(' ')
    hand = []
    for card in cardlist:
        dcard = Card.new(card)
        hand.append(dcard)
    return hand
开发者ID:ahendy0,项目名称:Holdem,代码行数:11,代码来源:processdata.py

示例8: evaluate_hands

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
    def evaluate_hands(self):
        agent_hands = []
        if self.in_game_count > 1:
            evaluator = Evaluator()
            board = []
            scores = []
            hand_types = []

            for c in self.community_cards:
                board.append(Card.new(c))
            for i in range(0, len(self.agents)):
                agent = self.agents[i]
                agent_hand = []

                for c in agent.hand:
                    agent_hand.append(Card.new(c))

                if self.in_game[i]:
                    agent_hands.append(agent.hand)
                    agent_score = evaluator.evaluate(board, agent_hand)
                    agent_hand_type = evaluator.class_to_string(evaluator.get_rank_class(agent_score))
                    scores.append(agent_score)
                    hand_types.append(agent_hand_type)
                else:
                    agent_hands += [None]
                    scores.append(9999999999999)
            
            lowest_rank = scores[0]
            winner = 0
            for i in range(0, len(self.agents)):
                if lowest_rank > scores[i]:
                    lowest_rank = scores[i]
                    winner = i
                    
            return (winner, agent_hands)
        else: # Only 1 remaining player
            winner = 0
            for i in range(0, len(self.agents)):
                if (self.in_game[i]):
                    winner = i
                    break
            return winner, agent_hands
开发者ID:crainiarc,项目名称:poker-simulator,代码行数:44,代码来源:game_engine.py

示例9: get_lowest_unpairing_card

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def get_lowest_unpairing_card(hand):
    """Add the worst possible card to an incomplete hand. Something
    that cannot pair up or make a flush or make a straight."""
    existing_ranks = set([Card.get_rank_int(x) for x in hand])
    remaining_ranks = list(set(range(12)) - existing_ranks)
    selected_rank = remaining_ranks[0]

    would_be_hand = hand + [Card.new(Card.STR_RANKS[selected_rank] + 'h')]
    if is_straight(would_be_hand):
        selected_rank = remaining_ranks[1]    # Don't make a straight

    selected_rank_str = Card.STR_RANKS[selected_rank]

    last_suit = Card.get_suit_int(hand[-1])
    last_suit_index = [1, 2, 4, 8].index(last_suit)
    selected_suit = [1, 2, 4, 8][(last_suit_index + 1) % 4]
    selected_suit_str = Card.INT_SUIT_TO_CHAR_SUIT[selected_suit]

    selected_card_str = selected_rank_str + str(selected_suit_str)
    return Card.new(selected_card_str)
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:22,代码来源:generate_front_lookup.py

示例10: setUpDeucesCards

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def setUpDeucesCards(cardsList):
    # Take a list of cards numbered 1-52 and put them into the form
    #used by deuces evaluator.
    # Convert card numbers to a deuces form string.
    cardStrings = []
    for i in range (0,len(cardsList)):
        cardStrings.append(convertToDeuces(cardsList[i]))
    # Put cards into a deuces form hand.
    deucesCards = []
    for i in range (0,len(cardsList)):
        deucesCards.append(Card.new(cardStrings[i]))
    return deucesCards
开发者ID:hughheadley,项目名称:pookeyPython,代码行数:14,代码来源:handEval.py

示例11: main

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def main(other_players, trials):
    with open("lookup-table-" + str(other_players), "w") as f:
        # iterate over all 169 equivalent starting hands. If you're curious about 
        # why there are only 169 equivalent starting hands, see:
        # https://en.wikipedia.org/wiki/Texas_hold_'em_starting_hands#Essentials
        count = 0
        for c1 in range(len(ranks)):
            for c2 in range(c1,len(ranks)):
                # note that the way we iterate means that r1 <= r2 always. 
                # knowing this makes it easier to get data from the output lookup table. 
                r1 = ranks[c1]
                r2 = ranks[c2]
                # We only ever use Spades and Clubs as suits because all that matters
                # is whether your starting cards are suited or off-suit. The suits
                # themselves are all equivalent, so the nominal choice doesn't matter.
                if r1==r2:
                    wins,ties = get_probabilities((Card.new(r1 + "s")), Card.new(r2 + "c"), 
                                                    other_players, trials)
                    write_to_file(f, r1, r2, "offsuit", wins, ties)
                    count +=1
                else:
                    wins,ties = get_probabilities((Card.new(r1 + "s")), Card.new(r2+ "c"), 
                                                    other_players, trials)
                    write_to_file(f, r1, r2, "offsuit", wins, ties)
                    count +=1

                    wins,ties = get_probabilities((Card.new(r1 + "s")), Card.new(r2+ "s"), 
                                                    other_players, trials)
                    write_to_file(f, r1, r2, "suited", wins, ties)
                    count +=1
                # Log the script's progress. For a given number of players, every simulation 
                # should take roughly equally long. However, the more players you have, 
                # the longer the entire process takes. (More hands to evaluate.)
                print "Simulated " + str(count) +" / 169"
开发者ID:Datamine,项目名称:PokerTexter,代码行数:36,代码来源:generate-lookup-table.py

示例12: getRank4

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def getRank4(card):
	hand=[Card.new(card[0]),Card.new(card[1])]
	evaluator=Evaluator()
	board=[Card.new(card[2]),Card.new(card[3]),Card.new(card[4]),Card.new(card[5]),Card.new(card[6])]
	rank4=evaluator.evaluate(board,hand)
	return rank4
开发者ID:yutianqiuhao,项目名称:TexasPokerRobot,代码行数:8,代码来源:cards2_judge.py

示例13: getRankBoard

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
def getRankBoard(card):
	board1=[Card.new(card[2]),Card.new(card[3])]
	evaluator=Evaluator()
	board2=[Card.new(card[4]),Card.new(card[5]),Card.new(card[6])]
	rankboard=evaluator.evaluate(board1,board2)
	return rankboard
开发者ID:yutianqiuhao,项目名称:TexasPokerRobot,代码行数:8,代码来源:cards2_judge.py

示例14: __init__

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
 def __init__(self, card_strs):
     self.cards = [Card.new(x) for x in card_strs]
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:4,代码来源:ofc_board.py

示例15: add_card

# 需要导入模块: from deuces import Card [as 别名]
# 或者: from deuces.Card import new [as 别名]
 def add_card(self, new_card_str):
     self.cards.append(Card.new(new_card_str))
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:4,代码来源:ofc_board.py


注:本文中的deuces.Card.new方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。