本文整理汇总了Python中card.Card.suit_and_value_from_identifier方法的典型用法代码示例。如果您正苦于以下问题:Python Card.suit_and_value_from_identifier方法的具体用法?Python Card.suit_and_value_from_identifier怎么用?Python Card.suit_and_value_from_identifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类card.Card
的用法示例。
在下文中一共展示了Card.suit_and_value_from_identifier方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_hex_identifier
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import suit_and_value_from_identifier [as 别名]
def from_hex_identifier(cls, identifier):
hands = cls._empty_hands()
hexChars = '0123456789abcdef'
for charIndex, hexChar in enumerate(identifier):
hexIndex = hexChars.index(hexChar)
highHandIndex = hexIndex / 4
lowHandIndex = hexIndex - highHandIndex * 4
highSuit, highCard = Card.suit_and_value_from_identifier(charIndex * 2 + 0)
lowSuit, lowCard = Card.suit_and_value_from_identifier(charIndex * 2 + 1)
hands[highHandIndex][highSuit.index] += highCard
hands[lowHandIndex][lowSuit.index] += lowCard
return Deal(map(Hand, hands))
示例2: random
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import suit_and_value_from_identifier [as 别名]
def random(cls):
shuffled_cards = range(52)
random.shuffle(shuffled_cards)
cards_by_suit_index = ["" for suit in SUITS]
for card_identifier in shuffled_cards[:13]:
suit, card = Card.suit_and_value_from_identifier(card_identifier)
cards_by_suit_index[suit.index] += card
return Hand(cards_by_suit_index)
示例3: from_old_identifier
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import suit_and_value_from_identifier [as 别名]
def from_old_identifier(cls, identifier):
identifier = long(identifier)
hands = cls._empty_hands()
for card_identifier in reversed(range(52)):
power_of_four = pow(4, card_identifier)
position = identifier / power_of_four
identifier -= power_of_four * position
suit, card = Card.suit_and_value_from_identifier(card_identifier)
hands[position][suit.index] += card
return Deal(map(Hand, hands))
示例4: random
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import suit_and_value_from_identifier [as 别名]
def random(cls):
# FIXME: A better random would generate a random identifier
# and use from_identifier. Howver our current identifier
# space is not compact. We can generate identifiers
# which are not valid deals.
hands = cls._empty_hands()
shuffled_cards = range(52)
random.shuffle(shuffled_cards)
for index_in_deck, card_identifier in enumerate(shuffled_cards):
position = index_in_deck % len(POSITIONS)
suit, card = Card.suit_and_value_from_identifier(card_identifier)
hands[position][suit.index] += card
return Deal(map(Hand, hands))