本文整理汇总了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()
示例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
示例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
示例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
示例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))
示例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
示例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
示例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)
示例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
示例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
示例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
示例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'
示例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
示例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
示例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)