Exemple #1
0
 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))
Exemple #2
0
 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)
Exemple #3
0
 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))
Exemple #4
0
 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))