本文整理汇总了Python中card.Card.identifier_for_card方法的典型用法代码示例。如果您正苦于以下问题:Python Card.identifier_for_card方法的具体用法?Python Card.identifier_for_card怎么用?Python Card.identifier_for_card使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类card.Card
的用法示例。
在下文中一共展示了Card.identifier_for_card方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _validate
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import identifier_for_card [as 别名]
def _validate(self):
all_cards = set()
for hand in self.hands:
for suit in SUITS:
for card in hand.cards_in_suit(suit):
card_identifier = Card.identifier_for_card(suit, card)
assert card_identifier not in all_cards, ("Already seen %s" % Card.card_name(suit, card))
all_cards.add(card_identifier)
assert len(all_cards) == 52
示例2: old_identifier
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import identifier_for_card [as 别名]
def old_identifier(self):
# We're constructing a 52 digit number in base 4,
# converted to base-10, its our identifier.
identifier = 0
for position, hand in enumerate(self.hands):
for suit, cards in enumerate(hand.cards_by_suit):
for card in cards:
card_identifier = Card.identifier_for_card(suit, card)
identifier += position * pow(4, card_identifier)
return str(identifier)
示例3: identifier
# 需要导入模块: from card import Card [as 别名]
# 或者: from card.Card import identifier_for_card [as 别名]
def identifier(self):
position_for_card = [None for _ in range(52)]
for position, hand in enumerate(self.hands):
for suit, cards in enumerate(hand.cards_by_suit):
for card in cards:
card_identifier = Card.identifier_for_card(suit, card)
position_for_card[card_identifier] = position
# position_for_card represents a 52-digit number in base 4
# We're going to split it into 4-digit hunks and convert to base 16.
identifier = ""
hex_chars = '0123456789abcdef'
for offset in range(26):
# A single hex digit encodes 4 bits where as our previous encoding was 2.
hex_index = position_for_card[offset * 2 + 0] * 4 + position_for_card[offset * 2 + 1]
identifier += hex_chars[hex_index]
return identifier