Пример #1
0
    def deal_hands(self) -> List[str]:
        # Shuffles a new deck of cards
        self.cur_deck = Deck()

        # Start out the shared cards as being empty
        self.shared_cards = []

        # Deals hands to each player, setting their initial bets to zero and
        # adding them as being in on the hand
        self.in_hand = []
        for player in self.players:
            player.cards = (self.cur_deck.draw(), self.cur_deck.draw())
            player.cur_bet = 0
            player.placed_bet = False
            self.in_hand.append(player)

        self.state = GameState.HANDS_DEALT
        messages = ["The hands have been dealt!"]

        # Reset the pot for the new hand
        self.pot.new_hand(self.players)

        if self.options["blind"] > 0:
            messages += self.pay_blinds()

        self.turn_index -= 1
        return messages + self.next_turn()
Пример #2
0
 def __init__(self, player_name, counter, player_id):
     self.player_name = player_name
     self.player_id = player_id
     self.counter = counter
     self.buyin_time = 1
     self.active = False
     self.ready = False
     self.pool = 0
     self.hands = Deck()
Пример #3
0
def deal_and_evaluate():
    d = Deck()
    d.shuffle()
    hands = d.deal_hands(2)
    winning_hand = -1
    hand_text = [repr(h) for h in hands]
    if hands[0] > hands[1]:
        winning_hand = 0
    elif hands[0] < hands[1]:
        winning_hand = 1
    return jsonify({'winner': winning_hand, 'hands': hand_text})
Пример #4
0
    def test_remove_specified_number_of_cards_from_deck(self):
        ace = Card("Ace", "Hearts")
        king = Card("King", "Clubs")
        queen = Card("Queen", "Diamonds")
        cards = [ace, king, queen]

        deck = Deck()
        deck.add_cards(cards)

        self.assertEqual(deck.deal_cards(2), [ace, king])
        self.assertEqual(deck.cards, [queen])
Пример #5
0
 def __init__(self, room_name, blind, buyin, room_id):
     self.room_name = room_name
     if isinstance(blind, int) and blind < 100:
         self.blind = blind
     else:
         raise Exception('blind must be int and small than 100')
     if isinstance(buyin, int):
         self.buyin = buyin
     else:
         raise Exception('buyin must be int')
     self.lock = Lock()
     self.room_id = room_id
     self.stage = 1  #未开局/翻牌/转牌/河牌/开牌
     self.players = []
     self.change_banker = False
     self.banker = 1
     self.speak = 0  #all speak
     self.queue = Queue()
     self.poker_engine = PokerEngine()
     self.public = Deck()
     self.players_cache = {}
Пример #6
0
 def test_stores_no_cards_at_start(self):
     deck = Deck()
     self.assertEqual(deck.cards, [])
Пример #7
0
 def test_deck_has_length(self):
     deck = Deck()
     self.assertEqual(len(deck), 0)
Пример #8
0
 def test_add_card_to_collection(self):
     deck = Deck()
     card = Card("Ace", "Clubs")
     deck.add_cards([card])
     self.assertEqual(deck.cards, [card])
Пример #9
0
 print()
 print("                           $")
 print("                        $$$$$$$")
 print("                      $$   $   $$")
 print("                      $    $    $")
 print("                      $    $    ")
 print("                       $$  $  ")
 print("                         $$$$$")
 print("                           $  $$")
 print("                           $    $")
 print("                      $    $    $")
 print("                      $$   $   $$")
 print("                        $$$$$$$")
 print("                           $")
 print()
 myDeck = Deck()
 myDeck.shuffle()
 dealer = Player()
 player = Player()
 myDeck.deal(dealer, 2)
 myDeck.deal(player, 2)
 print("Here are the dealer's cards: " + dealer.__str__())
 dealer_sum = dealer.get_value()
 print("They add to " + str(dealer_sum))
 print()
 print("Here are your cards: " + player.__str__())
 player_sum = player.get_value()
 print("They add to " + str(player_sum))
 print()
 hitting = True
 while hitting:
Пример #10
0
three_kind = Hand('AS AC AD 4H 5S')
two_pair = Hand('AS AC 4D 4H 5S')
pair = Hand('AS 2C 4D 4H 5S')
high_card_1 = Hand('AS 2C 4D 7H 5S')
high_card_2 = Hand('9S 2C 4D 7H 5S')
assert royal_flush.hand == 'royal flush'
assert straight_flush_1.hand == straight_flush_2.hand == 'straight flush'
assert flush.hand == 'flush'
assert straight_1.hand == straight_2.hand == 'straight'
assert four_kind.hand == 'four of a kind'
assert full_house.hand == 'full house'
assert three_kind.hand == 'three of a kind'
assert two_pair.hand == 'two pair'
assert pair.hand == 'pair'
assert high_card_1.hand == high_card_2.hand == 'high card'

assert (royal_flush > straight_flush_1 > straight_flush_2 > four_kind >
        full_house > flush > straight_1 > straight_2 > three_kind > two_pair >
        pair > high_card_1 > high_card_2)

# test creating a deck
deck = Deck()
assert len(deck) == 52
assert all(isinstance(card, Card) for card in deck)

# test creating a hand from the deck
hand_1 = Hand(deck)
hand_2 = Hand(deck)
assert len(hand_1) == 5
assert len(hand_2) == 5
Пример #11
0
def deck():
    return Deck(PKCard)
Пример #12
0
from poker import Player, Card, Deck

playing = True

while playing:
    my_deck = Deck()
    my_deck.shuffle()
    opponent = Player()
    player = Player()
    my_deck.deal(opponent, 5)
    my_deck.deal(player, 5)
    print(opponent)
    print(player)
    playing = False
Пример #13
0
result_dict = {}
for result in results:
    result_dict[result] = 0

# for i in range(10000):
#     new_deck = Deck()
#     new_deck.shuffle()
#     for j in range(10):
#         hand = Hand(new_deck)
#         if hand.is_full_house():
#             print("Full House: ", hand)

for i in range(100000):
    #while result_dict[results[0]] == 0:

    new_deck = Deck()
    new_deck.shuffle()
    # 10 hands per deck, right?
    #for j in range(10):
    hand = Hand(new_deck)
    result_dict[hand.check_ranking()] += 1

print(result_dict)

# checking that all hands get assigned a result
total = 0
for i in result_dict:
    total += result_dict[i]

print(total)
new_deck = Deck()