diff --git a/README.md b/README.md index e5d7b00..029f26d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,27 @@ # Blackjack -* [Part 1](README_1.md) -* [Part 2](README_2.md) \ No newline at end of file +Players can start the game in their console by typing: +python -m blackjack + +Blackjack is a game played between a Dealer and a Player. + +1. Cards are dealt from a deck that reshuffles after each hand. +These cards constitute the Hands of each player. +At the start of the Game, 2 cards are dealt to each player (The 1st and 3rd cards off the deck go to the player. The 2nd and 4th cards go to the dealer.) + +2. The player's point total is the combined points of his hand. The dealer's point total is the combined points of his hand. + +3. Points are ascribed as follows: + The ace is worth 11 points, unless the point total of the hand with an 11-point ace is worth more than 21. In that case, it is worth 1 point. + 2-10 are worth the same points as their names + Face cards (Jack, Queen, King) are worth 10 points + +4. The player acts first. The Player has the choice to Hit or Stand. Hitting means that another Card is drawn from the deck, the Card is added to the player's hand and the points from that card are added to the point total of the Player's Hand. Stand means that no more cards are drawn, and his point total remains at its current amount. Stay also means that he stays for all future rounds. + +5. After the player acts, there should be a win-condition check to see if the player has busted. If the player hit and busted, the dealer wins. + +6. If the player has not busted, the Dealer either hits or stays based on its built in hit-or-stay algorithm. If the total points in DealerHand are less than 17, the Dealer will Hit. If the total points in DealerHand are greater than 17, the Dealer will Stay. (If the dealer has an ace and TotalPoints == 17, then the Dealer hits.) If the dealer hits, another card is added to the player's Hand and the hand's point total are increased by the point value of the card card. + +7. After Dealer plays, another win-condition check. If the dealer busted, the player wins. If neither player nor dealer busted, whoever's hand is higher wins. A tie is called a push. + +8. If the player wins, he wins the amount of his bet. If he loses, he loses the amount of his bet. If it is a push, there is no change to the amount of the player's chips. If the players wins with blackjack, he wins 1.5x the amount of his bet. diff --git a/blackjack/.DS_Store b/blackjack/.DS_Store new file mode 100644 index 0000000..fbcd765 Binary files /dev/null and b/blackjack/.DS_Store differ diff --git a/blackjack/__init__.py b/blackjack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/__main__.py b/blackjack/__main__.py new file mode 100644 index 0000000..14ba9e0 --- /dev/null +++ b/blackjack/__main__.py @@ -0,0 +1,185 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player +from blackjack.dealer import Dealer +from blackjack.game import Game + +import blackjack.functions as fun + +if __name__ == "__main__": + + player = Player() + dealer = Dealer() + + print("\n \n") + player.name = input("What's your name? ") + print("") + print("Hi {}, let's play blackjack!".format(player.name)) + + play_game = True + while play_game: + + p_win = False + d_win = False + tie = False + p_bust = False + d_bust = False + p_blackjack = False + d_blackjack = False + + while not (p_win or d_win or tie or p_blackjack or d_blackjack): + game = Game() + deck = game.create_and_shuffle_deck() + player_hand = Hand() + dealer_hand = Hand() + + print("\n \n") + print("New Hand\n") + + while True: + print("You have {} chips.".format(player.chips)) + print("What is your bet?") + new_bet = input("> ") + print("") + player.bet = int(new_bet) + if player.bet <= player.chips: + break + + player.make_bet() + + player_hand.get_card(deck) + dealer_hand.get_card(deck) + player_hand.get_card(deck) + dealer_hand.get_card(deck) + + player_hand.value = player_hand.valuation() + dealer_hand.value = dealer_hand.valuation() + + print("{}'s hand: {} {}".format( + player.name, player_hand.value, player_hand.cards)) + print("Dealer shows: {} [{}]".format( + dealer.shown_value(dealer_hand), dealer.shown(dealer_hand))) + print("") + p_blackjack = game.blackjack_check(player_hand) + d_blackjack = game.blackjack_check(dealer_hand) + if p_blackjack is True: + break + + hit_or_stand = 0 + while not fun.hit_stand(hit_or_stand): + hit_or_stand = (input("Hit or Stand? ")).upper() + + if hit_or_stand == "HIT": + player_hand.get_card(deck) + player_hand.value = player_hand.valuation() + print("") + print("{}".format(player_hand.new_card())) + print("") + print("{} has: {} {}".format( + player.name, player_hand.value, player_hand.cards)) + print("Dealer shows: {} [{}]".format( + dealer.shown_value(dealer_hand), dealer.shown( + dealer_hand))) + print("") + p_bust = game.bust_check(player_hand) + if p_bust is True: + break + hit_or_stand = 0 + if p_bust is True: + break + + print("") + print("Dealer's turn.") + input("Press ENTER to continue. \n") + print("Dealer shows his hole card.") + print("Dealer has: {} {}".format( + dealer_hand.value, dealer_hand.cards)) + input("Press ENTER to continue. \n") + print("") + + d_blackjack = game.blackjack_check(dealer_hand) + if d_blackjack is True: + break + + hit_or_stand = dealer.hit_test(dealer_hand) + while hit_or_stand == "HIT": + print("Dealer hits. \n") + dealer_hand.get_card(deck) + dealer_hand.value = dealer_hand.valuation() + print("{}".format(dealer_hand.new_card())) + print("") + print("{} has: {} {}".format( + player.name, player_hand.value, player_hand.cards)) + print("Dealer has: {} {}".format( + dealer_hand.value, dealer_hand.cards)) + input("Press ENTER to continue. \n") + d_bust = game.bust_check(dealer_hand) + if d_bust is True: + break + hit_or_stand = dealer.hit_test(dealer_hand) + if d_bust is True: + break + + print("Dealer stands.") + input("Press ENTER to continue. \n") + print("Player has: {} {}".format( + player_hand.value, player_hand.cards)) + print("Dealer has: {} {}".format( + dealer_hand.value, dealer_hand.cards)) + + higher_hand = game.higher_hand(player_hand, dealer_hand) + if higher_hand == 'p_hand': + p_win = True + if higher_hand == 'd_hand': + d_win = True + else: + tie = True + + if p_blackjack and d_blackjack: + print("Wow. Crap. The dealer also had blackjack.") + print("That's a push.") + player.push() + print("You have {} chips remaining.".format(player.chips)) + else: + if p_blackjack: + print("You've got blackjack! You win.") + player.win_blackjack() + print("You have {} chips remaining.".format(player.chips)) + if d_blackjack: + print("Dealer has blackjack. Dealer wins.") + print("You have {} chips remaining.".format(player.chips)) + elif p_bust: + print("Sorry, you busted! Dealer wins.") + print("You have {} chips remaining.".format(player.chips)) + elif d_bust: + print("Dealer busts! You win.") + player.win_bet() + print("You have {} chips remaining.".format(player.chips)) + elif p_win: + print("You have the higher hand! You win.") + player.win_bet() + print("You have {} chips remaining.".format(player.chips)) + elif d_win: + print("Dealer has the higher hand! Dealer wins.") + print("You have {} chips remaining.".format(player.chips)) + elif tie: + print("That's a push.") + player.push() + print("You have {} chips remaining.".format(player.chips)) + + if player.chips <= 0: + print("You're out of chips! You're done! Go home!") + print("I hope you learned a valuable lesson about gambling.") + exit() + + print("") + + checker = 1 + while checker == 1: + answer = (input("Play again? Y/N: ")).upper() + if answer == "Y": + checker = 0 + if answer == "N": + checker = 0 + play_game = False diff --git a/blackjack/card.py b/blackjack/card.py new file mode 100644 index 0000000..cd42cb9 --- /dev/null +++ b/blackjack/card.py @@ -0,0 +1,22 @@ +class Card: + """A playing card. + + Responsibilities: + + * Has a rank and a suit. + * Cards should have readable representations + + Collaborators: + + * Collected into a Deck. + * Collected into a Hand for each player and a Hand for the dealer.""" + + def __init__(self, rank, suit): + self.rank = rank + self.suit = suit + + def __str__(self): + return "{} of {}".format(self.rank, self.suit) + + def __repr__(self): + return self.__str__() diff --git a/blackjack/dealer.py b/blackjack/dealer.py new file mode 100644 index 0000000..ba3870b --- /dev/null +++ b/blackjack/dealer.py @@ -0,0 +1,76 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player + + +class Dealer: + """A computer player that uses an algorithm to determine whether to hit + or stay + + Responsibilities: + * Stay on 17 (with no Ace in hand) + * Hit on 17 (with Ace in hand) + * Hit on 16 or under + * Stay on 18-21 + * Display just the shown card when the dealer's hole card is + still concealed + + Collaborators: + * uses the Hand class to determine the value of the hand, on which it + bases its actions""" + + def __init__(self): + pass + + def hit_test(self, a_hand): + """algorithm to determine the automated actions of the dealer. + This includes the idea of the dealer hitting on a 'soft' 17""" + + value_dict = {'1': 1, + '2': 2, + '3': 3, + '4': 4, + '5': 5, + '6': 6, + '7': 7, + '8': 8, + '9': 9, + '10': 10, + 'J': 10, + 'Q': 10, + 'K': 10, + 'A': 11} + hand_ranks = [card.rank for card in a_hand.cards] + values = [value_dict[x] for x in hand_ranks] + value = sum(values) + + list_of_a = [card.rank for card in a_hand.cards if card.rank == 'A'] + if len(list_of_a) > 0 and value < 21: + if a_hand.value < 18: + return "HIT" + else: + return "STAND" + else: + if a_hand.value < 17: + return "HIT" + else: + return "STAND" + + def shown(self, a_hand): + """displays just 1 card of the dealer's at the start of the hand""" + return a_hand.cards[1] + + def shown_value(self, a_hand): + """calculates the value of just the dealer's starting shown card""" + card = a_hand.cards[1] + new_hand = Hand() + new_hand.cards = [card] + value = new_hand.valuation() + return value + + def __str__(self): + return "Dealer" + + def __repr__(self): + return self.__str__() diff --git a/blackjack/deck.py b/blackjack/deck.py new file mode 100644 index 0000000..f39fd4f --- /dev/null +++ b/blackjack/deck.py @@ -0,0 +1,46 @@ +import random + +from blackjack.card import Card + + +class Deck: + """A set of 52 playing cards. + + Responsibilities: + * hold a collection of cards + * self-generates a list of 52 cards of every variation + * Should be able to (re)shuffle itself + * should be able to report its current size + + Collaborators: + * consists of cards""" + + def __init__(self): + ranks = ['2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '10', + 'J', + 'Q', + 'K', + 'A'] + suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs'] + self.cards = [Card(rank, suit) for rank in ranks for suit in suits] + + def draw(self): + return self.cards.pop() + + def shuffle(self): + return random.shuffle(self.cards) + + def __str__(self): + card_list = [str(card) for card in self.cards] + return ', '.join(card_list) + + def __repr__(self): + return self.__str__() diff --git a/blackjack/functions.py b/blackjack/functions.py new file mode 100644 index 0000000..486bc3d --- /dev/null +++ b/blackjack/functions.py @@ -0,0 +1,8 @@ +def hit_stand(x): + "checks to see if input was an acceptable option" + if x == 'HIT': + return True + if x == 'STAND': + return True + else: + return False diff --git a/blackjack/game.py b/blackjack/game.py new file mode 100644 index 0000000..44b6f04 --- /dev/null +++ b/blackjack/game.py @@ -0,0 +1,44 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player +from blackjack.dealer import Dealer + + +class Game: + """I kinda mucked this up, and rather than having the game run + through this class, it ended up just basically being a repository + for miscellaneous functions that were part of the game play""" + + def __init__(self): + pass + + def create_and_shuffle_deck(self): + """Creates and shuffles deck""" + deck = Deck() + deck.shuffle() + return deck + + def blackjack_check(self, hand): + """checks to see if a hand has blackjack. To be used only + at a juncture where the hand has only 2 cards.""" + if hand.value == 21: + return True + else: + return False + + def bust_check(self, hand): + """checks to see whether a hand has busted, ie has value over 21""" + if hand.value > 21: + return True + else: + return False + + def higher_hand(self, p_hand, d_hand): + """if both player and dealer stand, checks to see who wins""" + if p_hand.value == d_hand.value: + return 'push' + elif p_hand.value > d_hand.value: + return 'p_hand' + else: + return 'd_hand' diff --git a/blackjack/hand.py b/blackjack/hand.py new file mode 100644 index 0000000..670e174 --- /dev/null +++ b/blackjack/hand.py @@ -0,0 +1,67 @@ +from blackjack.card import Card +from blackjack.deck import Deck + + +class Hand: + """ A hand (either for player or dealer) that can contain cards + + Responsibilities: + * keep track of which cards are in the hand + * keep track of the value of the hand + + + Collaborators: + * get popped cards from the shoe""" + + def __init__(self, value=0): + self.cards = [] + self.value = value + + def _str__(self): + card_list = [str(card) for card in self.cards] + return ', '.join(card_list) + + def __repr__(self): + return self.__str__() + + def get_card(self, deck): + """gets a card from the deck, adds it to the hand""" + card = deck.draw() + return self.cards.append(card) + + def new_card(self): + """shows the card most recently added to the deck""" + newest_card = self.cards[-1] + return newest_card + + def valuation(self): + """determines the value of the hand, accounting for the + changing value of Aces, depending on the total hand value""" + value_dict = {'1': 1, + '2': 2, + '3': 3, + '4': 4, + '5': 5, + '6': 6, + '7': 7, + '8': 8, + '9': 9, + '10': 10, + 'J': 10, + 'Q': 10, + 'K': 10, + 'A': 11} + + list_of_a = [card.rank for card in self.cards if card.rank == 'A'] + a_counter = len(list_of_a) + + hand_ranks = [card.rank for card in self.cards] + values = [value_dict[x] for x in hand_ranks] + value = sum(values) + + while a_counter > 0: + if value > 21: + value -= 10 + a_counter -= 1 + + return value diff --git a/blackjack/player.py b/blackjack/player.py new file mode 100644 index 0000000..f21753a --- /dev/null +++ b/blackjack/player.py @@ -0,0 +1,44 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand + + +class Player: + """Keeps track of the player's betting + + Responsibilities: + * has chips + * bets chips + * wins chips of various values + * holds the player's name""" + + def __init__(self, chips=100, bet=10, name='Player'): + self.chips = chips + self.bet = bet + self.name = name + + def make_bet(self): + """makes initial bet, taking bet amount from chip count""" + self.chips -= self.bet + return int(self.chips) + + def win_bet(self): + """returns original bet, plus bet amount for winning""" + self.chips += (2*self.bet) + return int(self.chips) + + def win_blackjack(self): + """returns original bet, plus augmented blackjack winnings""" + self.chips += int(2.5*self.bet) + return int(self.chips) + + def push(self): + """returns original bet""" + self.chips += self.bet + return int(self.chips) + + def __str__(self): + return "Player has {} chips.".format(self.chips) + + def __repr__(self): + return self.__str__() diff --git a/blackjack/tests/__init__.py b/blackjack/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/tests/test_card.py b/blackjack/tests/test_card.py new file mode 100644 index 0000000..011a719 --- /dev/null +++ b/blackjack/tests/test_card.py @@ -0,0 +1,13 @@ +from blackjack.card import Card + + +def test_card(): + a_card = Card(2, "Spades") + assert a_card.rank == 2 + assert a_card.suit == "Spades" + + +def test_card2(): + a_card = Card("Jack", "Hearts") + assert a_card.rank == "Jack" + assert a_card.suit == "Hearts" diff --git a/blackjack/tests/test_dealer.py b/blackjack/tests/test_dealer.py new file mode 100644 index 0000000..34ad1e2 --- /dev/null +++ b/blackjack/tests/test_dealer.py @@ -0,0 +1,53 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player +from blackjack.dealer import Dealer + + +def test_shown_cards(): + dealer = Dealer() + a_hand = Hand() + a_hand.cards = [Card('2', 'Hearts'), Card('3', 'Diamonds')] + test_card = dealer.shown(a_hand) + assert test_card.rank == '3' + assert test_card.suit == 'Diamonds' + + +def test_shown_value(): + dealer = Dealer() + a_hand = Hand() + a_hand.cards = [Card('2', 'Hearts'), Card('3', 'Diamonds')] + assert dealer.shown_value(a_hand) == 3 + b_hand = Hand() + b_hand.cards = [Card('2', 'Hearts'), Card('K', 'Diamonds')] + assert dealer.shown_value(b_hand) == 10 + + +def test_hit_test(): + dealer = Dealer() + a_hand = Hand(value=16) + b_hand = Hand(value=17) + c_hand = Hand(value=18) + a_hand.cards = [Card('7', 'Hearts'), Card('9', 'Diamonds')] + b_hand.cards = [Card('7', 'Hearts'), Card('10', 'Diamonds')] + c_hand.cards = [Card('8', 'Hearts'), Card('10', 'Diamonds')] + + assert dealer.hit_test(a_hand) == "HIT" + assert dealer.hit_test(b_hand) == "STAND" + assert dealer.hit_test(c_hand) == "STAND" + + d_hand = Hand(value=16) + e_hand = Hand(value=17) + f_hand = Hand(value=18) + g_hand = Hand(value=17) + d_hand.cards = [Card('A', 'Hearts'), Card('5', 'Diamonds')] + e_hand.cards = [Card('A', 'Hearts'), Card('6', 'Diamonds')] + f_hand.cards = [Card('A', 'Hearts'), Card('7', 'Diamonds')] + g_hand.cards = [Card('A', 'Hearts'), Card('6', 'Diamonds'), + Card('Q', 'Clubs')] + + assert dealer.hit_test(d_hand) == "HIT" + assert dealer.hit_test(e_hand) == "HIT" + assert dealer.hit_test(f_hand) == "STAND" + assert dealer.hit_test(g_hand) == "STAND" diff --git a/blackjack/tests/test_deck.py b/blackjack/tests/test_deck.py new file mode 100644 index 0000000..9d9d65c --- /dev/null +++ b/blackjack/tests/test_deck.py @@ -0,0 +1,13 @@ +from blackjack.card import Card +from blackjack.deck import Deck + + +def test_deck(): + a_deck = Deck() + assert len(a_deck.cards) == 52 + + +def test_deck_draw(): + a_deck = Deck() + a_deck.draw() + assert len(a_deck.cards) == 51 diff --git a/blackjack/tests/test_functions.py b/blackjack/tests/test_functions.py new file mode 100644 index 0000000..bbef33e --- /dev/null +++ b/blackjack/tests/test_functions.py @@ -0,0 +1,10 @@ +import blackjack.functions as fun + + +def test_hit_stand(): + x = 'HIT' + y = 'STAND' + z = 'POTATO' + assert fun.hit_stand(x) is True + assert fun.hit_stand(y) is True + assert fun.hit_stand(z) is False diff --git a/blackjack/tests/test_game.py b/blackjack/tests/test_game.py new file mode 100644 index 0000000..8a6f194 --- /dev/null +++ b/blackjack/tests/test_game.py @@ -0,0 +1,33 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player +from blackjack.dealer import Dealer +from blackjack.game import Game + + +def test_bust_check(): + game = Game() + a_hand = Hand(value=20) + b_hand = Hand(value=21) + c_hand = Hand(value=22) + + assert game.bust_check(a_hand) is False + assert game.bust_check(b_hand) is False + assert game.bust_check(c_hand) is True + + +def test_higher_hand(): + game = Game() + + p_hand = Hand(value=20) + d_hand = Hand(value=20) + assert game.higher_hand(p_hand, d_hand) == 'push' + + p_hand = Hand(value=20) + d_hand = Hand(value=19) + assert game.higher_hand(p_hand, d_hand) == 'p_hand' + + p_hand = Hand(value=19) + d_hand = Hand(value=20) + assert game.higher_hand(p_hand, d_hand) == 'd_hand' diff --git a/blackjack/tests/test_hand.py b/blackjack/tests/test_hand.py new file mode 100644 index 0000000..1003682 --- /dev/null +++ b/blackjack/tests/test_hand.py @@ -0,0 +1,47 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand + + +def test_get_card(): + a_deck = Deck() + a_hand = Hand() + a_hand.get_card(a_deck) + assert len(a_hand.cards) == 1 + assert len(a_deck.cards) == 51 + + +def test_new_card(): + a_hand = Hand() + a_hand.cards = [Card('2', 'Hearts'), Card('10', 'Spades')] + test_card = a_hand.new_card() + assert test_card.rank == '10' + assert test_card.suit == 'Spades' + + +def test_valuation_non_ace(): + a_hand = Hand() + a_hand.cards = [Card('2', 'Hearts'), Card('10', 'Spades')] + assert a_hand.valuation() == 12 + + +def test_valuation_ace_test(): + a_hand = Hand() + b_hand = Hand() + c_hand = Hand() + d_hand = Hand() + a_hand.cards = [Card('A', 'Hearts'), + Card('5', 'Spades'), + Card('K', 'Clubs')] + b_hand.cards = [Card('A', 'Hearts'), + Card('A', 'Spades'), + Card('K', 'Clubs')] + c_hand.cards = [Card('A', 'Hearts'), + Card('A', 'Spades')] + d_hand.cards = [Card('A', 'Hearts'), + Card('5', 'Spades')] + + assert a_hand.valuation() == 16 + assert b_hand.valuation() == 12 + assert c_hand.valuation() == 12 + assert d_hand.valuation() == 16 diff --git a/blackjack/tests/test_player.py b/blackjack/tests/test_player.py new file mode 100644 index 0000000..261993f --- /dev/null +++ b/blackjack/tests/test_player.py @@ -0,0 +1,37 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player + + +def test_name(): + a_player = Player(name='Card Shark') + assert a_player.name == 'Card Shark' + +def test_make_bet(): + a_player = Player() + assert a_player.chips == 100 + a_player.make_bet() + assert a_player.chips == 90 + + b_player = Player(bet=20) + b_player.make_bet() + assert b_player.chips == 80 + + +def test_win_bet(): + a_player = Player(chips=90) + a_player.win_bet() + assert a_player.chips == 110 + + +def test_win_blackjack(): + a_player = Player(chips=90) + a_player.win_blackjack() + assert a_player.chips == 115 + + +def test_push(): + a_player = Player(chips=90) + a_player.push() + assert a_player.chips == 100 diff --git a/blackjack/tests/test_shoe.py b/blackjack/tests/test_shoe.py new file mode 100644 index 0000000..fac0aa3 --- /dev/null +++ b/blackjack/tests/test_shoe.py @@ -0,0 +1,8 @@ +# from blackjack.card import Card +#from blackjack.deck import Deck +#from blackjack.shoe import Shoe + +#def test_shoe_length(): +# shoe_1_deck = Shoe(1) +# assert len(shoe_1_deck.shuffle) == 52 +# assert shoe_1_deck.decks == 1 diff --git a/lib/blackjack/card.py b/lib/blackjack/card.py new file mode 100644 index 0000000..9b4ded8 --- /dev/null +++ b/lib/blackjack/card.py @@ -0,0 +1,22 @@ +class Card: + """A playing card. + + Responsibilities: + + * Has a rank and a suit. + * Has a point value. Aces point values depend on the Hand. + + Collaborators: + + * Collected into a Deck. + * Collected into a Hand for each player and a Hand for the dealer.""" + + def __init__(self, rank, suit): + self.rank = rank + self.suit = suit + + def __str__(self): + return "{} of {}".format(self.rank, self.suit) + + def __repr__(self): + return self.__str__ diff --git a/lib/blackjack/dealer.py b/lib/blackjack/dealer.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/blackjack/dealer_hand.py b/lib/blackjack/dealer_hand.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/blackjack/deck.py b/lib/blackjack/deck.py new file mode 100644 index 0000000..a92b577 --- /dev/null +++ b/lib/blackjack/deck.py @@ -0,0 +1,29 @@ +from card import Card + +class Deck: + """A set of 52 playing cards. + + Responsibilities: + * self-generates a list of 52 cards of every variation + + Collaborators: + * consists of cards + * collected into a Shoe, either by itself or with multiple decks""" + + + def __init__(self): + ranks = [2,3,4,5,6,7,8,9,10,'Jack','Queen','King','Ace'] + suits = ['Spades', 'Hearts', 'Diamonds', 'Clubs'] + self.cards = [Card(rank, suit) for rank in ranks for suit in suits] + + + def __str__(self): + card_list = [str(card) for card in self.cards] + return ', '.join(card_list) + + + def __repr__(self): + return self.__str__ + +a_deck = Deck() +print(a_deck.cards[0]) diff --git a/lib/blackjack/player.py b/lib/blackjack/player.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/blackjack/player_hand.py b/lib/blackjack/player_hand.py new file mode 100644 index 0000000..e69de29 diff --git a/lib/blackjack/shoe.py b/lib/blackjack/shoe.py new file mode 100644 index 0000000..795a89d --- /dev/null +++ b/lib/blackjack/shoe.py @@ -0,0 +1,8 @@ +class Shoe: + """ A collection of 1-6 decks. + + Responsibilities: + * + + Collaborators: + * diff --git a/lib/blackjack/test_card.py b/lib/blackjack/test_card.py new file mode 100644 index 0000000..72f8eb9 --- /dev/null +++ b/lib/blackjack/test_card.py @@ -0,0 +1,11 @@ +from card import Card + +def test_card(): + a_card = Card(2, "Spades") + assert a_card.rank == 2 + assert a_card.suit == "Spades" + +def test_card2(): + a_card = Card("Jack", "Hearts") + assert a_card.rank == "Jack" + assert a_card.suit == "Hearts" diff --git a/lib/blackjack/test_deck.py b/lib/blackjack/test_deck.py new file mode 100644 index 0000000..44ef215 --- /dev/null +++ b/lib/blackjack/test_deck.py @@ -0,0 +1,8 @@ +from card import Card +from deck import Deck + +def test_deck(): + a_deck = Deck() + assert len(a_deck.cards) == 52 + assert type(a_deck.cards) == list +