Esempio n. 1
0
  def play(self, hand_size=3):
    """Starts a card game between two players.

    Args:
      hand_size: An int representing the number of cards a player will draw.
    """
    self.playing = True

    while self.playing:
      cards = Deck()
      cards.shuffle_deck()

      p1 = Player(input("\nPLAYER 1 NAME:  "))
      p2 = Player(input("\nPLAYER 2 NAME:  "))

      for _ in range(hand_size):
        p1.draw_card(cards.deck)
        p2.draw_card(cards.deck)

      p1.sort_hand(cards.suits, cards.suit_cards)
      p2.sort_hand(cards.suits, cards.suit_cards)

      p1.score_hand(cards.suits, cards.suit_cards)
      p2.score_hand(cards.suits, cards.suit_cards)

      self.show_hands(p1, p2)
      self.declare_winner(p1, p2)

      play_again = input("\nPlay again? [y/N]  ")

      if not strtobool(play_again):
        self.playing = False
Esempio n. 2
0
 def __init__(self):
     """Initialize."""
     self.deck = Deck()
     self.deck.shuffle()
     self.player_hand = []
     self.dealer_hand = []
     self.player_bet = 0
     self.player_money = 0
     self.rounds_played = 0
Esempio n. 3
0
    def __init__(self, purse):

        #store the new deck
        self.game_deck = Deck()

        #initialize player with a purse
        self.Player = Player(purse)

        #initialize computer player with a purse
        self.Computer = Player(purse)
Esempio n. 4
0
 def __init__(self, players=None, num_rounds=9, verbose=True):
     if not players:
         players = [('AI1', PlayerType.Computer),
                    ('AI1', PlayerType.Computer)]
     self.verbose = verbose
     self.players = []
     for player in players:
         name, type_ = player
         self.players.append(Player(name, type_))
     self.round = 1
     self.num_rounds = num_rounds
     self.deck = Deck()
     self.top = None
     self.first_player = 0
Esempio n. 5
0
    def __init__(self):

        self.__deck = Deck()
        self.__a_Team = []
        self.__b_Team = []

        # players 1-3 on team A
        # players 4-6 on team B
        self.__current_player_id = 1
        self.__score = [0, 0]

        # create players
        for i in range(1, 4):
            self.__a_Team.append(Player(i, i))
            self.__b_Team.append(Player(i, i + 3))

        # deal cards to players
        i = 0
        for card in self.__deck.get_cards():
            if i < 3:
                self.__a_Team[i].receive_card(card)
            else:
                self.__b_Team[i - 3].receive_card(card)
            i = (i + 1) % 6
Esempio n. 6
0
 def __init__(self, num_rounds_per_episode=10):
     self.deck = Deck()
     self.reset()
     self.rounds_per_episode = num_rounds_per_episode
Esempio n. 7
0
 def setUp(self):
     self.deck = Deck()
Esempio n. 8
0
 def setUp(self):
     self.sample_deck = Deck()
Esempio n. 9
0
def run():
    print(
        "Welcome to Blackjack! Get as close to 21 as you can without going bust! Dealer hits until they reach 17 or over. Aces count as 1 or 11 depending on your current hand value.\n"
    )
    player_chips = Chips(
    )  # Initialise player's chip pool. It is outside of the main loop so it carries between hands
    while True:
        playing = True  # used for the player's turn
        card_deck = Deck()
        card_deck.shuffle_deck()  # setting up the deck

        betting = input("Player, would you like to bet on this round? (y/n) "
                        )  # asks if the player wants to bet
        if betting == "y":
            set_up_bet(player_chips)

        # intialising the player's and dealer's hands
        player = Hand()
        dealer = Hand()

        deal_cards(player, dealer, card_deck)

        # player's turn; the loop will continue until the player stands or goes bust
        while playing:
            show_some_cards(player, dealer)

            # runs if the player is bust
            if player.total_card_value > 21:
                player_busts(player_chips)
                break

            playing = hit_or_stand(
                player, card_deck)  # asks if the player wants to hit or stand

        if player.total_card_value <= 21:

            # the dealer hits until their hand value is greater than 17
            while dealer.total_card_value < 17:
                hit(dealer, card_deck)

            show_cards(player, dealer)  # shows players and dealers cards

            # checks the outcome of the game and calls the respective method (which sorts the bet outcome if there was one)
            if dealer.total_card_value > 21:
                dealer_busts(player_chips)
            elif dealer.total_card_value > player.total_card_value:
                dealer_wins(player_chips)
            elif dealer.total_card_value < player.total_card_value:
                player_wins(player_chips)
            else:
                print("Dealer and Player tie! It's a push.")

        # checks if the player wants to play another hand
        play_again = input("\nWould you like to play another hand? y/n: ")
        if play_again.lower() == "y":
            playing = True
            print("\n" * 100)
        else:
            print("Thanks for playing! You have left the table with {} chips.".
                  format(player_chips.chips_pool))
            break
Esempio n. 10
0
 def __init__(self, channel):
     self._channel = channel
     self.deck = Deck()
     self.dealt_this_phase = False
Esempio n. 11
0
def cards_for_tests():
    cards = Deck()
    return cards