Example #1
0
def init_54_deck():
    ''' Initialize a standard deck of 52 cards, BJ and RJ

    Returns:
        (list): Alist of Card object
    '''
    suit_list = ['S', 'H', 'D', 'C']
    rank_list = ['A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K']
    res = [Card(suit, rank) for suit in suit_list for rank in rank_list]
    res.append(Card('BJ', ''))
    res.append(Card('RJ', ''))
    return res
Example #2
0
 def _reduce_meld_kinds_by_rank_id(self, card: Card):
     rank_id = utils.get_rank_id(card)
     meld_kinds = self.meld_kinds_by_rank_id[rank_id]
     if len(meld_kinds) > 1:
         suits = ['S', 'H', 'D', 'C']
         self.meld_kinds_by_rank_id[rank_id] = [[
             Card(suit, card.rank) for suit in suits if suit != card.suit
         ]]
     else:
         self.meld_kinds_by_rank_id[rank_id] = []
Example #3
0
def card_from_card_id(card_id: int) -> Card:
    ''' Make card from its card_id

    Args:
        card_id: int in range(0, 52)
     '''
    if not (0 <= card_id < 52):
        raise GinRummyProgramError(
            "card_id is {}: should be 0 <= card_id < 52.".format(card_id))
    rank_id = card_id % 13
    suit_id = card_id // 13
    rank = Card.valid_rank[rank_id]
    suit = Card.valid_suit[suit_id]
    return Card(rank=rank, suit=suit)
Example #4
0
 def _increase_meld_kinds_by_rank_id(self, card: Card):
     rank_id = utils.get_rank_id(card)
     meld_kinds = self.meld_kinds_by_rank_id[rank_id]
     if len(meld_kinds) == 0:
         card_rank = card.rank
         meld_kind = [card for card in self.hand if card.rank == card_rank]
         if len(meld_kind) >= 3:
             self.meld_kinds_by_rank_id[rank_id].append(meld_kind)
     else:  # must have all cards of given rank
         suits = ['S', 'H', 'D', 'C']
         max_kind_meld = [Card(suit, card.rank) for suit in suits]
         self.meld_kinds_by_rank_id[rank_id] = [max_kind_meld]
         for meld_card in max_kind_meld:
             self.meld_kinds_by_rank_id[rank_id].append(
                 [card for card in max_kind_meld if card != meld_card])
Example #5
0
 def __init__(self, np_random):
     ''' Initialize a leducholdem dealer class
     '''
     self.np_random = np_random
     self.deck = [
         Card('S', 'J'),
         Card('H', 'J'),
         Card('S', 'Q'),
         Card('H', 'Q'),
         Card('S', 'K'),
         Card('H', 'K')
     ]
     self.shuffle()
     self.pot = 0
Example #6
0
def card_from_text(text: str) -> Card:
    if len(text) != 2:
        raise GinRummyProgramError("len(text) is {}: should be 2.".format(
            len(text)))
    return Card(rank=text[0], suit=text[1])