Пример #1
0
class Player:
    def __init__(self, n, b=10):
        self.hand = Hand()
        self.name = n
        self.bank = b
        self.bet = 0

    def draw_new_card_from_deck(self, deck):
        self.hand.add_card(deck.draw_card())

    def take_card(self, card):
        self.hand.add_card(card)
Пример #2
0
def generate_tp(val=15, val2=15, val3=15):
    """Generate two pairs 5 cards hand"""
    suits = ["Spade", "Club", "Diamond", "Heart"]
    h = Hand()
    # First Pair
    choice = random.choice(suits)
    choice2 = random.choice(suits)
    while choice == choice2:
        choice2 = random.choice(suits)
    if val == 15:
        val = random.choice(range(2, 15))
    for su in suits:
        if not (su.__eq__(choice) or su.__eq__(choice2)):
            h.add_card(Card(su, val))
    # Second Pair
    choice = random.choice(suits)
    choice2 = random.choice(suits)
    while choice == choice2:
        choice2 = random.choice(suits)
    while val2 == 15 or val2 == val:
        val2 = random.choice(range(2, 15))
    for su in suits:
        if not (su.__eq__(choice) or su.__eq__(choice2)):
            h.add_card(Card(su, val2))
    # Last Card
    while val3 == 15 or val3 == val or val3 == val2:
        val3 = random.choice(range(2, 15))
    h.add_card(Card(random.choice(suits), val3))
    return h
Пример #3
0
 def getQuads(self, values, cards, player):
     for key, val in values.items():
         if len(val) == 4:
             return Hand(name=Hands.quads,
                         owner=player.id,
                         cards=val,
                         kickers=[[c for c in cards if c.value != key][0]])
     return None
Пример #4
0
 def getOnePair(self, values, cards, player):
     for key, val in values.items():
         if len(val) == 2:
             return Hand(name=Hands.onePair,
                         owner=player.id,
                         cards=val,
                         kickers=[c for c in cards if c.value != key][:3])
     return None
Пример #5
0
 def getTrips(self, values, cards, player):
     for key, val in values.items():
         if len(val) == 3:
             return Hand(name=Hands.trips,
                         owner=player.id,
                         cards=val,
                         kickers=[c for c in cards if c.value != key][0:2])
     return None
Пример #6
0
 def getRoyal(self, suits, player):
     straightFlush = self.getStraightFlush(suits, player)
     if straightFlush and sorted(straightFlush.cards,
                                 key=lambda c: c.value)[0].value == 10:
         return Hand(Hands.royalFlush,
                     owner=player.id,
                     cards=straightFlush.cards)
     return None
Пример #7
0
def print_qt(num, ch):
    _c = False
    _qt = None
    try:
        # Load Qtable from file
        with np.load('Qtable/qtablenpc.npz') as data:
            _qt = data['qtable']
        _c = True
    except IOError:
        print("error loading qtable")
    if not _c:
        exit(0)
    _h = Hand()
    _res = np.zeros(8, dtype=int)
    for i in range(num):
        print(
            "Cards  --  big blind  --  money ranges  --  small blind  -- money ranges"
        )
        for j in range(i + 1, num):
            _h.add_card(Card.decode(i))
            _h.add_card(Card.decode(j))
            for i1 in range(2):
                for j1 in range(4):
                    _res[i1 * 4 + j1] = PokerEnv.encode(
                        _h, i1, 1 + (j1 * (ch / 2)), ch)
            _s = _h.__str__() + " - "
            for i2 in range(8):
                _s += str.format('{:.2f}', _qt[_res[i2]][0])
                _s += "|"
                _s += str.format('{:.2f}', _qt[_res[i2]][1])
                _s += " -- "
            print(_s)
            _h.clear_hand()
Пример #8
0
    def getFlush(self, suits, player):
        for key, val in suits.items():
            if len(val) >= 5:
                return Hand(name=Hands.flush,
                            owner=player.id,
                            cards=val[:5],
                            kickers=val[1:5])

        return None
Пример #9
0
 def getTwoPair(self, values, cards, player):
     pairs = [v for k, v in values.items() if len(v) == 2]
     if len(pairs) > 1:
         return Hand(name=Hands.twoPair,
                     owner=player.id,
                     cards=pairs[0] + pairs[1],
                     kickers=[[
                         c for c in cards if c.value != pairs[0][0].value
                         and c.value != pairs[1][0].value
                     ][0]])
     return None
Пример #10
0
def generate_tok(val=15, val2=15, val3=15):
    """Generate three of a kind 5 cards hand"""
    suits = ["Spade", "Club", "Diamond", "Heart"]
    choice = random.choice(suits)
    if val == 15:
        val = random.choice(range(2, 15))
    h = Hand()
    for su in suits:
        if not su.__eq__(choice):
            h.add_card(Card(su, val))
    while val2 == 15 or val2 == val:
        val2 = random.choice(range(2, 15))
    h.add_card(Card(random.choice(suits), val2))
    while val3 == 15 or val3 == val or val3 == val2:
        val3 = random.choice(range(2, 15))
    h.add_card(Card(random.choice(suits), val3))
    return h
Пример #11
0
    def getFullHouse(self, values, player):
        trips = []
        dubs = []
        for key, val in values.items():
            if len(val) == 3:
                trips = val
                for key, val in values.items():
                    if len(val) == 2:
                        dubs = val
                        break
                break
        if trips and dubs:
            return Hand(name=Hands.fullHouse,
                        owner=player.id,
                        cards=trips + dubs
                        # this might need work, lookup trips rules
                        )

        return None
Пример #12
0
    def getStraight(self, cards, player):

        if cards[0].value == 14:
            cards = cards + [Card(1, cards[0].suit)]

        seqCards = []
        for c in cards:
            if not seqCards or seqCards[-1].value - c.value == 1:
                seqCards.append(c)
            elif seqCards[-1].value - c.value > 1:
                seqCards = [c]

            if len(seqCards) == 5:
                if seqCards[-1].value == 1:
                    seqCards[-1] = Card(14, seqCards[-1].suit)

                return Hand(name=Hands.straight,
                            owner=player.id,
                            cards=seqCards)
        return None
Пример #13
0
    def getStraightFlush(self, suits, player):
        for key, val in suits.items():
            if len(val) >= 5:
                cards = val[:]

                if cards[0].value == 14:
                    cards = cards + [Card(1, cards[0].suit)]

                seqCards = []
                for c in cards:
                    if not seqCards or seqCards[-1].value - c.value == 1:
                        seqCards.append(c)
                    elif seqCards[-1].value - c.value > 1:
                        seqCards = [c]

                    if len(seqCards) == 5:
                        if seqCards[-1].value == 1:
                            seqCards[-1] = Card(14, seqCards[-1].suit)

                        return Hand(name=Hands.straightFlush,
                                    owner=player.id,
                                    cards=seqCards)
        return None
Пример #14
0
def generate_fh(val=15, val2=15):
    """Generate Full house 5 cards hand"""
    suits = ["Spade", "Club", "Diamond", "Heart"]
    choice = random.choice(suits)
    if val == 15:
        val = random.choice(range(2, 15))
    h = Hand()
    for su in suits:
        if not su.__eq__(choice):
            h.add_card(Card(su, val))
    choice, choice2 = random.choice(suits), random.choice(suits)
    while choice2 == choice:
        choice2 = random.choice(suits)
    while val2 == 15 or val2 == val:
        val2 = random.choice(range(2, 15))
    for su in suits:
        if not (su.__eq__(choice) or su.__eq__(choice2)):
            h.add_card(Card(su, val2))
    return h
Пример #15
0
 def __init__(self, n, b=10):
     self.hand = Hand()
     self.name = n
     self.bank = b
     self.bet = 0
Пример #16
0
 def getHighCard(self, cards, player):
     return Hand(name=Hands.highCard,
                 owner=player.id,
                 cards=[cards[0]],
                 kickers=cards[1:])