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


Python deuces.Card类代码示例

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


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

示例1: __init__

    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,代码行数:58,代码来源:PokerMath.py

示例2: encode

    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,代码行数:51,代码来源:gamestate_encoder.py

示例3: getRank

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,代码行数:14,代码来源:scripttest.py

示例4: handRank

 def handRank(self):
     scores = []
     for i in range(2):
         if self.player_list[i].folded == False:
             strength = self.evaluator.evaluate(self.table, self.player_list[i].hand)
             scores.append([i, strength])
             print self.player_list[i].name + ": " + self.evaluator.class_to_string(self.evaluator.get_rank_class(strength))
             Card.print_pretty_cards(self.player_list[i].hand)
     scores = sorted(scores,key=itemgetter(1))
     groups = groupby(scores, itemgetter(1))
     result = [[item[0] for item in data] for (key, data) in groups]
     for i in result[0]:
         print self.player_list[i].name + " wins!"
     return result
开发者ID:mingu600,项目名称:Poker,代码行数:14,代码来源:heads_up.py

示例5: rounds

 def rounds(self, round_num):
     if round_num == 1:
         print("The Flop")
         self.table += self.deck.draw(3)
     elif round_num == 2:
         print("The Turn")
         self.table += [self.deck.draw(1)]
     elif round_num == 3:
         print("The River")
         self.table += [self.deck.draw(1)]
     else:
         print("Showdown")
     Card.print_pretty_cards(self.table)
     for i in range(len(self.player_list)):
         self.strengths[i].append(self.player_list[i].calc_hand_strength(self))
开发者ID:mingu600,项目名称:Poker,代码行数:15,代码来源:framework.py

示例6: test_front_royalties

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,代码行数:15,代码来源:test_royalty_calculator.py

示例7: cardsRank

 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,代码行数:7,代码来源:PokerUtils.py

示例8: get_probabilities

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,代码行数:29,代码来源:generate-lookup-table.py

示例9: parse_cards

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,代码行数:9,代码来源:processdata.py

示例10: query_state

 def query_state(self):
     ret = 'pies = %d, cards = ' % self.pies
     for c in self.cards:
         ret += Card.int_to_pretty_str(c)
     if self.game is None:
         ret += ', currently not in-game'
     else:
         ret += ', ' + self.game.query_state()
     return ret
开发者ID:dramborleg,项目名称:text-poker,代码行数:9,代码来源:player.py

示例11: cards_to_suits

 def cards_to_suits(cards):
     suit_dummy = np.zeros(4)
     suit_binaries = np.array([Card.get_suit_int(x) for x in cards])
     suit_dummy[0] = sum(suit_binaries == 1)
     suit_dummy[1] = sum(suit_binaries == 2)
     suit_dummy[2] = sum(suit_binaries == 4)
     suit_dummy[3] = sum(suit_binaries == 8)
     suit_dummy_std = (suit_dummy - 1.5) / 2  # Hacky "standardisation"
     return suit_dummy_std
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:9,代码来源:gamestate_encoder.py

示例12: reveal

 def reveal(self):
     msg = "%s's cards are" % self.tag
     for c in self.cards:
         msg += ' ' + Card.int_to_pretty_str(c)
     self.cards = []
     if self.game is not None:
         self.game.message_players(msg)
     else:
         return 'Not in game'
     return 'Revealed and discarded hand'
开发者ID:dramborleg,项目名称:text-poker,代码行数:10,代码来源:player.py

示例13: cards_to_ranks

 def cards_to_ranks(cards, pad):
     rank_dummy = np.zeros(pad)
     # Add one to distinguish deuce from missing
     cards = sorted([Card.get_rank_int(x) for x in cards])
     for i, card in enumerate(cards):
         if i >= pad:
             continue
         rank_dummy[i] = card + 1
     rank_dummy_std = (rank_dummy - 8) / 14  # Hacky "standardisation"
     return rank_dummy_std
开发者ID:DexGroves,项目名称:rl-ofc,代码行数:10,代码来源:gamestate_encoder.py

示例14: evaluate_hands

    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,代码行数:42,代码来源:game_engine.py

示例15: get_lowest_unpairing_card

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,代码行数:20,代码来源:generate_front_lookup.py


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