From 36278f860691c94dcd8bb1b97a8fdf5c53e8ee8c Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Wed, 21 Jan 2015 13:21:03 -0500 Subject: [PATCH 01/12] Rough outline in README --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e5d7b00..fd1c204 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,30 @@ # Blackjack -* [Part 1](README_1.md) -* [Part 2](README_2.md) \ No newline at end of file +Blackjack is a game played between a Dealer and a Player. + +1. At the start of the game, the Player has the choice of how many Decks they would like in the Shoe. The choice is from 1-6. + +2. Cards are dealt from a Shoe that consists of one or more Decks. +These cards constitute the Hands of each player, PlayerHand and DealerHand. +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.) + +3. The player's PointTotal is the combined points of his hand. The dealer's PointTotal is the combined points of his hand. + +4. Points are ascribed as follows: + The ace is worth 11 points, unless the PointTotal 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 + +5. After the cards are dealt, the first Round takes place: + +ROUND: +a. the Player has the choice to Hit or Stay. Hitting means that another Card is drawn from the Shoe, the Card is added to the player's hand and the points from that card are added to the PointTotal of the Player's Hand. Stay means that no more cards are drawn, and his PointTotal remains at its current amount. Stay also means that he stays for all future rounds. + +b. 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. + +c. If the player has not busted, the Dealer either hits or stays based on its built in hit-or-stay algorithm. If the TotalPoints in DealerHand are less than 17, the Dealer will Hit. If the TotalPoints 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 PointTotal are increased by the point value of the card card. + +d. After Dealer plays, another win-condition check. If the player's last move was stay, and the Dealer's hand is greater than 17, the game ends. Whoever's hand has the greater PointTotal is the winner. +If the Dealer hits and busts(PointTotal greater than 21), the player wins. + +6. Repeat Rounds until one of the win conditions is met From beec05693434e5c5d3bd6bef89bf1c64a1ba8bfa Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Wed, 21 Jan 2015 15:40:30 -0500 Subject: [PATCH 02/12] completed(?) card and deck classes. Weak test files for both. Created files for other classes --- lib/blackjack/card.py | 22 ++++++++++++++++++++++ lib/blackjack/dealer.py | 0 lib/blackjack/dealer_hand.py | 0 lib/blackjack/deck.py | 29 +++++++++++++++++++++++++++++ lib/blackjack/player.py | 0 lib/blackjack/player_hand.py | 0 lib/blackjack/shoe.py | 8 ++++++++ lib/blackjack/test_card.py | 11 +++++++++++ lib/blackjack/test_deck.py | 8 ++++++++ 9 files changed, 78 insertions(+) create mode 100644 lib/blackjack/card.py create mode 100644 lib/blackjack/dealer.py create mode 100644 lib/blackjack/dealer_hand.py create mode 100644 lib/blackjack/deck.py create mode 100644 lib/blackjack/player.py create mode 100644 lib/blackjack/player_hand.py create mode 100644 lib/blackjack/shoe.py create mode 100644 lib/blackjack/test_card.py create mode 100644 lib/blackjack/test_deck.py 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 + From 58e411e968bca509eb0fc5d9edda5618ff20ee5a Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Wed, 21 Jan 2015 21:02:02 -0500 Subject: [PATCH 03/12] homework theoretically complete. moved files around --- blackjack/blackjack/card.py | 22 +++++++++++++++++++ blackjack/blackjack/dealer.py | 13 +++++++++++ blackjack/blackjack/dealer_hand.py | 8 +++++++ blackjack/blackjack/deck.py | 26 ++++++++++++++++++++++ blackjack/blackjack/hand.py | 12 ++++++++++ blackjack/blackjack/player.py | 10 +++++++++ blackjack/blackjack/shoe.py | 35 ++++++++++++++++++++++++++++++ blackjack/blackjack/test_card.py | 11 ++++++++++ blackjack/blackjack/test_deck.py | 8 +++++++ blackjack/blackjack/test_shoe.py | 8 +++++++ blackjack/card.py | 22 +++++++++++++++++++ blackjack/dealer.py | 13 +++++++++++ blackjack/dealer_hand.py | 8 +++++++ blackjack/deck.py | 26 ++++++++++++++++++++++ blackjack/hand.py | 12 ++++++++++ blackjack/player.py | 10 +++++++++ blackjack/shoe.py | 35 ++++++++++++++++++++++++++++++ blackjack/test_card.py | 11 ++++++++++ blackjack/test_deck.py | 8 +++++++ blackjack/test_shoe.py | 8 +++++++ 20 files changed, 306 insertions(+) create mode 100644 blackjack/blackjack/card.py create mode 100644 blackjack/blackjack/dealer.py create mode 100644 blackjack/blackjack/dealer_hand.py create mode 100644 blackjack/blackjack/deck.py create mode 100644 blackjack/blackjack/hand.py create mode 100644 blackjack/blackjack/player.py create mode 100644 blackjack/blackjack/shoe.py create mode 100644 blackjack/blackjack/test_card.py create mode 100644 blackjack/blackjack/test_deck.py create mode 100644 blackjack/blackjack/test_shoe.py create mode 100644 blackjack/card.py create mode 100644 blackjack/dealer.py create mode 100644 blackjack/dealer_hand.py create mode 100644 blackjack/deck.py create mode 100644 blackjack/hand.py create mode 100644 blackjack/player.py create mode 100644 blackjack/shoe.py create mode 100644 blackjack/test_card.py create mode 100644 blackjack/test_deck.py create mode 100644 blackjack/test_shoe.py diff --git a/blackjack/blackjack/card.py b/blackjack/blackjack/card.py new file mode 100644 index 0000000..9b4ded8 --- /dev/null +++ b/blackjack/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/blackjack/blackjack/dealer.py b/blackjack/blackjack/dealer.py new file mode 100644 index 0000000..949ca0a --- /dev/null +++ b/blackjack/blackjack/dealer.py @@ -0,0 +1,13 @@ +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 + + Collaborators: + * on hit, tell dealer's Hand to get Card from Shoe + * """ diff --git a/blackjack/blackjack/dealer_hand.py b/blackjack/blackjack/dealer_hand.py new file mode 100644 index 0000000..8b6bd39 --- /dev/null +++ b/blackjack/blackjack/dealer_hand.py @@ -0,0 +1,8 @@ +class Dealer_Hand: + """ A collection of 1-6 decks. + + Responsibilities: + * + + Collaborators: + * diff --git a/blackjack/blackjack/deck.py b/blackjack/blackjack/deck.py new file mode 100644 index 0000000..4322b08 --- /dev/null +++ b/blackjack/blackjack/deck.py @@ -0,0 +1,26 @@ +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__ diff --git a/blackjack/blackjack/hand.py b/blackjack/blackjack/hand.py new file mode 100644 index 0000000..7b4a3ff --- /dev/null +++ b/blackjack/blackjack/hand.py @@ -0,0 +1,12 @@ +class Hand: + """ The current cards in the player's hand + + 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 + * give Dealer the cards and value of the two hands + * give user the cards and value of the two hands""" diff --git a/blackjack/blackjack/player.py b/blackjack/blackjack/player.py new file mode 100644 index 0000000..ce9bf8b --- /dev/null +++ b/blackjack/blackjack/player.py @@ -0,0 +1,10 @@ +class Player: + """ An interface for the user? Not sure I'll use this + + Responsibilities: + * take inputs from the user - # of decks in shoe, hit or stay + + Collaborators: + * tell Shoe how many decks to have in the shoe + * get information from Hand about the player and dealer hands + * on hit, tell player's Hand to get another Card from Shoe""" diff --git a/blackjack/blackjack/shoe.py b/blackjack/blackjack/shoe.py new file mode 100644 index 0000000..9d58b3b --- /dev/null +++ b/blackjack/blackjack/shoe.py @@ -0,0 +1,35 @@ +import random + +from card import Card +from deck import Deck + + +class Shoe: + """ A collection of 1-6 decks. + + Responsibilities: + *take an argument for the number of decks + *combine and shuffle decks + *pop the last item off of the shuffled deck and send it to either + player_hand or dealer_hand + + Collaborators: + *gets decks to combine into shoe + * pops the last item off of the shuffled deck and send it to either + the dealer's Hand or the player's Hand""" + + def __init__(self, an_int, a_deck): + self.decks = an_int + self.shuffle = random.shuffle(a_deck.cards * an_int) + + + def __str__(self): + card_list = [str(card) for card in self.shuffle] + return ', '.join(card_list) + + + def __repr__(self): + return self.__str__ + +a_shoe = Shoe(1) +print(a_shoe) diff --git a/blackjack/blackjack/test_card.py b/blackjack/blackjack/test_card.py new file mode 100644 index 0000000..72f8eb9 --- /dev/null +++ b/blackjack/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/blackjack/blackjack/test_deck.py b/blackjack/blackjack/test_deck.py new file mode 100644 index 0000000..44ef215 --- /dev/null +++ b/blackjack/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 + diff --git a/blackjack/blackjack/test_shoe.py b/blackjack/blackjack/test_shoe.py new file mode 100644 index 0000000..77b9fda --- /dev/null +++ b/blackjack/blackjack/test_shoe.py @@ -0,0 +1,8 @@ +from card import Card +from deck import Deck +from 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/blackjack/card.py b/blackjack/card.py new file mode 100644 index 0000000..9b4ded8 --- /dev/null +++ b/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/blackjack/dealer.py b/blackjack/dealer.py new file mode 100644 index 0000000..949ca0a --- /dev/null +++ b/blackjack/dealer.py @@ -0,0 +1,13 @@ +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 + + Collaborators: + * on hit, tell dealer's Hand to get Card from Shoe + * """ diff --git a/blackjack/dealer_hand.py b/blackjack/dealer_hand.py new file mode 100644 index 0000000..8b6bd39 --- /dev/null +++ b/blackjack/dealer_hand.py @@ -0,0 +1,8 @@ +class Dealer_Hand: + """ A collection of 1-6 decks. + + Responsibilities: + * + + Collaborators: + * diff --git a/blackjack/deck.py b/blackjack/deck.py new file mode 100644 index 0000000..4322b08 --- /dev/null +++ b/blackjack/deck.py @@ -0,0 +1,26 @@ +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__ diff --git a/blackjack/hand.py b/blackjack/hand.py new file mode 100644 index 0000000..7b4a3ff --- /dev/null +++ b/blackjack/hand.py @@ -0,0 +1,12 @@ +class Hand: + """ The current cards in the player's hand + + 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 + * give Dealer the cards and value of the two hands + * give user the cards and value of the two hands""" diff --git a/blackjack/player.py b/blackjack/player.py new file mode 100644 index 0000000..ce9bf8b --- /dev/null +++ b/blackjack/player.py @@ -0,0 +1,10 @@ +class Player: + """ An interface for the user? Not sure I'll use this + + Responsibilities: + * take inputs from the user - # of decks in shoe, hit or stay + + Collaborators: + * tell Shoe how many decks to have in the shoe + * get information from Hand about the player and dealer hands + * on hit, tell player's Hand to get another Card from Shoe""" diff --git a/blackjack/shoe.py b/blackjack/shoe.py new file mode 100644 index 0000000..9d58b3b --- /dev/null +++ b/blackjack/shoe.py @@ -0,0 +1,35 @@ +import random + +from card import Card +from deck import Deck + + +class Shoe: + """ A collection of 1-6 decks. + + Responsibilities: + *take an argument for the number of decks + *combine and shuffle decks + *pop the last item off of the shuffled deck and send it to either + player_hand or dealer_hand + + Collaborators: + *gets decks to combine into shoe + * pops the last item off of the shuffled deck and send it to either + the dealer's Hand or the player's Hand""" + + def __init__(self, an_int, a_deck): + self.decks = an_int + self.shuffle = random.shuffle(a_deck.cards * an_int) + + + def __str__(self): + card_list = [str(card) for card in self.shuffle] + return ', '.join(card_list) + + + def __repr__(self): + return self.__str__ + +a_shoe = Shoe(1) +print(a_shoe) diff --git a/blackjack/test_card.py b/blackjack/test_card.py new file mode 100644 index 0000000..72f8eb9 --- /dev/null +++ b/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/blackjack/test_deck.py b/blackjack/test_deck.py new file mode 100644 index 0000000..44ef215 --- /dev/null +++ b/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 + diff --git a/blackjack/test_shoe.py b/blackjack/test_shoe.py new file mode 100644 index 0000000..77b9fda --- /dev/null +++ b/blackjack/test_shoe.py @@ -0,0 +1,8 @@ +from card import Card +from deck import Deck +from 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 From 85e8c76ac6ed71eb14727c7879186b094ebac8c3 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Thu, 22 Jan 2015 16:47:01 -0500 Subject: [PATCH 04/12] hand rough draft --- blackjack/blackjack/card.py | 22 ------------ blackjack/blackjack/dealer.py | 13 ------- blackjack/blackjack/dealer_hand.py | 8 ----- blackjack/blackjack/deck.py | 26 -------------- blackjack/blackjack/hand.py | 12 ------- blackjack/blackjack/player.py | 10 ------ blackjack/blackjack/shoe.py | 35 ------------------ blackjack/blackjack/test_deck.py | 8 ----- blackjack/blackjack/test_shoe.py | 8 ----- blackjack/card.py | 5 +-- blackjack/deck.py | 23 +++++++++--- blackjack/hand.py | 39 ++++++++++++++++++++- blackjack/player.py | 7 ++-- blackjack/test_card.py | 11 ------ blackjack/test_deck.py | 8 ----- blackjack/test_shoe.py | 8 ----- blackjack/{blackjack => tests}/test_card.py | 2 +- blackjack/tests/test_deck.py | 11 ++++++ blackjack/tests/test_hand.py | 16 +++++++++ blackjack/tests/test_shoe.py | 8 +++++ 20 files changed, 100 insertions(+), 180 deletions(-) delete mode 100644 blackjack/blackjack/card.py delete mode 100644 blackjack/blackjack/dealer.py delete mode 100644 blackjack/blackjack/dealer_hand.py delete mode 100644 blackjack/blackjack/deck.py delete mode 100644 blackjack/blackjack/hand.py delete mode 100644 blackjack/blackjack/player.py delete mode 100644 blackjack/blackjack/shoe.py delete mode 100644 blackjack/blackjack/test_deck.py delete mode 100644 blackjack/blackjack/test_shoe.py delete mode 100644 blackjack/test_card.py delete mode 100644 blackjack/test_deck.py delete mode 100644 blackjack/test_shoe.py rename blackjack/{blackjack => tests}/test_card.py (88%) create mode 100644 blackjack/tests/test_deck.py create mode 100644 blackjack/tests/test_hand.py create mode 100644 blackjack/tests/test_shoe.py diff --git a/blackjack/blackjack/card.py b/blackjack/blackjack/card.py deleted file mode 100644 index 9b4ded8..0000000 --- a/blackjack/blackjack/card.py +++ /dev/null @@ -1,22 +0,0 @@ -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/blackjack/blackjack/dealer.py b/blackjack/blackjack/dealer.py deleted file mode 100644 index 949ca0a..0000000 --- a/blackjack/blackjack/dealer.py +++ /dev/null @@ -1,13 +0,0 @@ -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 - - Collaborators: - * on hit, tell dealer's Hand to get Card from Shoe - * """ diff --git a/blackjack/blackjack/dealer_hand.py b/blackjack/blackjack/dealer_hand.py deleted file mode 100644 index 8b6bd39..0000000 --- a/blackjack/blackjack/dealer_hand.py +++ /dev/null @@ -1,8 +0,0 @@ -class Dealer_Hand: - """ A collection of 1-6 decks. - - Responsibilities: - * - - Collaborators: - * diff --git a/blackjack/blackjack/deck.py b/blackjack/blackjack/deck.py deleted file mode 100644 index 4322b08..0000000 --- a/blackjack/blackjack/deck.py +++ /dev/null @@ -1,26 +0,0 @@ -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__ diff --git a/blackjack/blackjack/hand.py b/blackjack/blackjack/hand.py deleted file mode 100644 index 7b4a3ff..0000000 --- a/blackjack/blackjack/hand.py +++ /dev/null @@ -1,12 +0,0 @@ -class Hand: - """ The current cards in the player's hand - - 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 - * give Dealer the cards and value of the two hands - * give user the cards and value of the two hands""" diff --git a/blackjack/blackjack/player.py b/blackjack/blackjack/player.py deleted file mode 100644 index ce9bf8b..0000000 --- a/blackjack/blackjack/player.py +++ /dev/null @@ -1,10 +0,0 @@ -class Player: - """ An interface for the user? Not sure I'll use this - - Responsibilities: - * take inputs from the user - # of decks in shoe, hit or stay - - Collaborators: - * tell Shoe how many decks to have in the shoe - * get information from Hand about the player and dealer hands - * on hit, tell player's Hand to get another Card from Shoe""" diff --git a/blackjack/blackjack/shoe.py b/blackjack/blackjack/shoe.py deleted file mode 100644 index 9d58b3b..0000000 --- a/blackjack/blackjack/shoe.py +++ /dev/null @@ -1,35 +0,0 @@ -import random - -from card import Card -from deck import Deck - - -class Shoe: - """ A collection of 1-6 decks. - - Responsibilities: - *take an argument for the number of decks - *combine and shuffle decks - *pop the last item off of the shuffled deck and send it to either - player_hand or dealer_hand - - Collaborators: - *gets decks to combine into shoe - * pops the last item off of the shuffled deck and send it to either - the dealer's Hand or the player's Hand""" - - def __init__(self, an_int, a_deck): - self.decks = an_int - self.shuffle = random.shuffle(a_deck.cards * an_int) - - - def __str__(self): - card_list = [str(card) for card in self.shuffle] - return ', '.join(card_list) - - - def __repr__(self): - return self.__str__ - -a_shoe = Shoe(1) -print(a_shoe) diff --git a/blackjack/blackjack/test_deck.py b/blackjack/blackjack/test_deck.py deleted file mode 100644 index 44ef215..0000000 --- a/blackjack/blackjack/test_deck.py +++ /dev/null @@ -1,8 +0,0 @@ -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 - diff --git a/blackjack/blackjack/test_shoe.py b/blackjack/blackjack/test_shoe.py deleted file mode 100644 index 77b9fda..0000000 --- a/blackjack/blackjack/test_shoe.py +++ /dev/null @@ -1,8 +0,0 @@ -from card import Card -from deck import Deck -from 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/blackjack/card.py b/blackjack/card.py index 9b4ded8..6225ef3 100644 --- a/blackjack/card.py +++ b/blackjack/card.py @@ -4,7 +4,8 @@ class Card: Responsibilities: * Has a rank and a suit. - * Has a point value. Aces point values depend on the Hand. + * Two cards with the same suit and rank should be equal to each other + * Cards should have readable representations Collaborators: @@ -19,4 +20,4 @@ def __str__(self): return "{} of {}".format(self.rank, self.suit) def __repr__(self): - return self.__str__ + return self.__str__() diff --git a/blackjack/deck.py b/blackjack/deck.py index 4322b08..26d7e7a 100644 --- a/blackjack/deck.py +++ b/blackjack/deck.py @@ -1,26 +1,39 @@ -from card import Card +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 - * collected into a Shoe, either by itself or with multiple decks""" + * consists of cards""" def __init__(self): - ranks = [2,3,4,5,6,7,8,9,10,'Jack','Queen','King','Ace'] + 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__ + return self.__str__() diff --git a/blackjack/hand.py b/blackjack/hand.py index 7b4a3ff..8759cb5 100644 --- a/blackjack/hand.py +++ b/blackjack/hand.py @@ -1,5 +1,8 @@ +from blackjack.card import Card +from blackjack.deck import Deck + class Hand: - """ The current cards in the player's hand + """ The current cards in the hand Responsibilities: * keep track of which cards are in the hand @@ -10,3 +13,37 @@ class Hand: * get popped cards from the shoe * give Dealer the cards and value of the two hands * give user the cards and value of the two hands""" + + def __init__(self): + self.cards = [] + self.value = 0 + + 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): + card = deck.draw() + return self.cards.append(card) + + def valuation(self): + 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 self.cards] + values = [value_dict[x] for x in hand_ranks] + return sum(values) diff --git a/blackjack/player.py b/blackjack/player.py index ce9bf8b..b375afb 100644 --- a/blackjack/player.py +++ b/blackjack/player.py @@ -1,10 +1,13 @@ class Player: - """ An interface for the user? Not sure I'll use this + """ Responsibilities: * take inputs from the user - # of decks in shoe, hit or stay Collaborators: - * tell Shoe how many decks to have in the shoe + * * get information from Hand about the player and dealer hands * on hit, tell player's Hand to get another Card from Shoe""" + + def __init__(self): + self.chips = 100 diff --git a/blackjack/test_card.py b/blackjack/test_card.py deleted file mode 100644 index 72f8eb9..0000000 --- a/blackjack/test_card.py +++ /dev/null @@ -1,11 +0,0 @@ -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/blackjack/test_deck.py b/blackjack/test_deck.py deleted file mode 100644 index 44ef215..0000000 --- a/blackjack/test_deck.py +++ /dev/null @@ -1,8 +0,0 @@ -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 - diff --git a/blackjack/test_shoe.py b/blackjack/test_shoe.py deleted file mode 100644 index 77b9fda..0000000 --- a/blackjack/test_shoe.py +++ /dev/null @@ -1,8 +0,0 @@ -from card import Card -from deck import Deck -from 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/blackjack/blackjack/test_card.py b/blackjack/tests/test_card.py similarity index 88% rename from blackjack/blackjack/test_card.py rename to blackjack/tests/test_card.py index 72f8eb9..a6d3050 100644 --- a/blackjack/blackjack/test_card.py +++ b/blackjack/tests/test_card.py @@ -1,4 +1,4 @@ -from card import Card +from blackjack.card import Card def test_card(): a_card = Card(2, "Spades") diff --git a/blackjack/tests/test_deck.py b/blackjack/tests/test_deck.py new file mode 100644 index 0000000..2b32e07 --- /dev/null +++ b/blackjack/tests/test_deck.py @@ -0,0 +1,11 @@ +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_hand.py b/blackjack/tests/test_hand.py new file mode 100644 index 0000000..52e8f5f --- /dev/null +++ b/blackjack/tests/test_hand.py @@ -0,0 +1,16 @@ +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_valuation(): + a_hand = Hand() + a_hand.cards =[Card('2', 'Hearts'), Card('10', 'Spades')] + assert a_hand.valuation() == 12 + 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 From 9217e1ebd76a17aad090154407ab1a041a6f6aa5 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Fri, 23 Jan 2015 14:19:20 -0500 Subject: [PATCH 05/12] Hand, player, dealer classes --- blackjack/.DS_Store | Bin 0 -> 6148 bytes blackjack/__init__.py | 0 blackjack/dealer.py | 35 ++++++++++++++++++++++++++++++ blackjack/hand.py | 18 +++++++++++++--- blackjack/player.py | 32 +++++++++++++++++++++------ blackjack/shoe.py | 2 +- blackjack/tests/__init__.py | 0 blackjack/tests/test_dealer.py | 38 +++++++++++++++++++++++++++++++++ blackjack/tests/test_hand.py | 24 +++++++++++++++++++-- blackjack/tests/test_player.py | 15 +++++++++++++ 10 files changed, 151 insertions(+), 13 deletions(-) create mode 100644 blackjack/.DS_Store create mode 100644 blackjack/__init__.py create mode 100644 blackjack/tests/__init__.py create mode 100644 blackjack/tests/test_dealer.py create mode 100644 blackjack/tests/test_player.py diff --git a/blackjack/.DS_Store b/blackjack/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fbcd765ee5132a7a91457110166e1907fe2ee690 GIT binary patch literal 6148 zcmeHK!AiqG5PefCO({r^9&_|0_y?g>!K;2iY}0~Zu+r+Gw|quF$`9~w>YLf6CT;4$ zgNV$)%u6(6RCMfWTIr0OxH~d8f zbnOOQtsE~{bM3y?FTX7p#k5>Z$Yve}H+`m?AxX~ZmI6_8J85>kmFRpJptLOR>i$jc&D0Yf?@ z9zG2JNTme_$UnwBn@%?zjlH%Ta wP@L|yDgA-2ro1ZPE`=Ai6_cx5@j2a$?WtZ6vxrqdw$S`Xz+~{?3jC@9pFWI%ZU6uP literal 0 HcmV?d00001 diff --git a/blackjack/__init__.py b/blackjack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/dealer.py b/blackjack/dealer.py index 949ca0a..f007a3a 100644 --- a/blackjack/dealer.py +++ b/blackjack/dealer.py @@ -1,3 +1,8 @@ +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 @@ -11,3 +16,33 @@ class Dealer: Collaborators: * on hit, tell dealer's Hand to get Card from Shoe * """ + + def __init__(self): + pass + + + def hit_test(self, a_hand): + list_of_a = [card.rank for card in a_hand.cards if card.rank == 'A'] + print("Length = {}".format(len(list_of_a))) + print("Value = {}".format(a_hand.value)) + if len(list_of_a) > 0: + 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): + return a_hand.cards[1] + + def __str__(self): + return "Dealer" + + def __repr__(self): + return self.__str__() diff --git a/blackjack/hand.py b/blackjack/hand.py index 8759cb5..a360d91 100644 --- a/blackjack/hand.py +++ b/blackjack/hand.py @@ -14,9 +14,9 @@ class Hand: * give Dealer the cards and value of the two hands * give user the cards and value of the two hands""" - def __init__(self): + def __init__(self, value=0): self.cards = [] - self.value = 0 + self.value = value def _str__(self): card_list = [str(card) for card in self.cards] @@ -44,6 +44,18 @@ def valuation(self): '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] - return sum(values) + 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 index b375afb..6c1015c 100644 --- a/blackjack/player.py +++ b/blackjack/player.py @@ -1,13 +1,31 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand + + class Player: """ Responsibilities: - * take inputs from the user - # of decks in shoe, hit or stay + * has chips + * bets chips + * wins chips + + Collaborators:""" + + def __init__(self, chips=100): + self.chips = chips + + def make_bet(self): + self.chips -= 10 + return self.chips + + def win_bet(self): + self.chips += 20 + return self.chips - Collaborators: - * - * get information from Hand about the player and dealer hands - * on hit, tell player's Hand to get another Card from Shoe""" + def __str__(self): + return "Player has {} chips.".format(self.chips) - def __init__(self): - self.chips = 100 + def __repr__(self): + return self.__str__() diff --git a/blackjack/shoe.py b/blackjack/shoe.py index 9d58b3b..3ba8998 100644 --- a/blackjack/shoe.py +++ b/blackjack/shoe.py @@ -20,7 +20,7 @@ class Shoe: def __init__(self, an_int, a_deck): self.decks = an_int - self.shuffle = random.shuffle(a_deck.cards * an_int) + self.shuffle = random.shuffle(a_deck.cards * an_int def __str__(self): 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_dealer.py b/blackjack/tests/test_dealer.py new file mode 100644 index 0000000..ac0e467 --- /dev/null +++ b/blackjack/tests/test_dealer.py @@ -0,0 +1,38 @@ +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_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) + 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')] + + assert dealer.hit_test(d_hand) == "Hit" + assert dealer.hit_test(e_hand) == "Hit" + assert dealer.hit_test(f_hand) == "Stand" diff --git a/blackjack/tests/test_hand.py b/blackjack/tests/test_hand.py index 52e8f5f..c2604d8 100644 --- a/blackjack/tests/test_hand.py +++ b/blackjack/tests/test_hand.py @@ -9,8 +9,28 @@ def test_get_card(): assert len(a_hand.cards) == 1 assert len(a_deck.cards) == 51 -def test_valuation(): +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..30cb968 --- /dev/null +++ b/blackjack/tests/test_player.py @@ -0,0 +1,15 @@ +from blackjack.card import Card +from blackjack.deck import Deck +from blackjack.hand import Hand +from blackjack.player import Player + +def test_make_bet(): + a_player = Player() + assert a_player.chips == 100 + a_player.make_bet() + assert a_player.chips == 90 + +def test_win_bet(): + a_player = Player(chips=90) + a_player.win_bet() + assert a_player.chips == 110 From a4a1675732939b4845d04775009a0b56314a9be5 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Fri, 23 Jan 2015 17:00:17 -0500 Subject: [PATCH 06/12] started on __main__ and game --- blackjack/__main__.py | 39 ++++++++++++++++++++++++++++++++++++ blackjack/game.py | 34 +++++++++++++++++++++++++++++++ blackjack/tests/test_game.py | 32 +++++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 blackjack/__main__.py create mode 100644 blackjack/game.py create mode 100644 blackjack/tests/test_game.py diff --git a/blackjack/__main__.py b/blackjack/__main__.py new file mode 100644 index 0000000..e8f75db --- /dev/null +++ b/blackjack/__main__.py @@ -0,0 +1,39 @@ +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 + + +if __name__ == "__main__": + + player = Player() + dealer = Dealer() + +# while True: + game = Game() + deck = game.create_and_shuffle_deck() + player_hand = Hand() + dealer_hand = Hand() + 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("Player hand: {}".format(player_hand.cards)) + print("Dealer hand: {}".format(dealer.shown(dealer_hand))) + print(player_hand.value) + print(dealer_hand.value) + + + hit_or_stand = (input("Hit or Stand? ")).upper() + while hit_or_stand == "HIT": + player_hand.get_card(deck) + player_hand.value = player_hand.valuation() + print("Player hand: {}".format(player_hand.cards)) + print("Dealer hand: {}".format(dealer.shown(dealer_hand))) + hit_or_stand = (input("Hit or Stand? ")).upper() diff --git a/blackjack/game.py b/blackjack/game.py new file mode 100644 index 0000000..2609d8d --- /dev/null +++ b/blackjack/game.py @@ -0,0 +1,34 @@ +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: + + def __init__(self): + pass + + def create_and_shuffle_deck(self): + deck = Deck() + deck.shuffle() + return deck + + def blackjack_check(self, hand): + pass + + def bust_check(self, hand): + if hand.value > 21: + return 'bust' + else: + return 'ok' + + 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/tests/test_game.py b/blackjack/tests/test_game.py new file mode 100644 index 0000000..54a0a50 --- /dev/null +++ b/blackjack/tests/test_game.py @@ -0,0 +1,32 @@ +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) == 'ok' + assert game.bust_check(b_hand) == 'ok' + assert game.bust_check(c_hand) == 'bust' + + +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' From 9a3cd6e098dd40d6b4620f6744521e5f2776b9fd Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Sat, 24 Jan 2015 11:32:01 -0500 Subject: [PATCH 07/12] most of the main program completed --- blackjack/__main__.py | 108 ++++++++++++++++++++++++------ blackjack/dealer.py | 12 ++-- blackjack/functions.py | 7 ++ blackjack/game.py | 9 ++- blackjack/tests/test_dealer.py | 12 ++-- blackjack/tests/test_functions.py | 9 +++ blackjack/tests/test_game.py | 6 +- 7 files changed, 125 insertions(+), 38 deletions(-) create mode 100644 blackjack/functions.py create mode 100644 blackjack/tests/test_functions.py diff --git a/blackjack/__main__.py b/blackjack/__main__.py index e8f75db..f72d102 100644 --- a/blackjack/__main__.py +++ b/blackjack/__main__.py @@ -5,35 +5,103 @@ from blackjack.dealer import Dealer from blackjack.game import Game +import blackjack.functions as fun if __name__ == "__main__": player = Player() dealer = Dealer() -# while True: - game = Game() - deck = game.create_and_shuffle_deck() - player_hand = Hand() - dealer_hand = Hand() - player_hand.get_card(deck) - dealer_hand.get_card(deck) - player_hand.get_card(deck) - dealer_hand.get_card(deck) + p_win = False + d_win = False + tie = False + p_bust = False + d_bust = False + p_blackjack = False + d_blackjack = False - player_hand.value = player_hand.valuation() - dealer_hand.value = dealer_hand.valuation() + while not (p_win or d_win or p_bust or d_bust or p_blackjack or d_blackjack): + game = Game() + deck = game.create_and_shuffle_deck() + player_hand = Hand() + dealer_hand = Hand() - print("Player hand: {}".format(player_hand.cards)) - print("Dealer hand: {}".format(dealer.shown(dealer_hand))) - print(player_hand.value) - print(dealer_hand.value) - - hit_or_stand = (input("Hit or Stand? ")).upper() - while hit_or_stand == "HIT": 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("Player hand: {}".format(player_hand.cards)) - print("Dealer hand: {}".format(dealer.shown(dealer_hand))) - hit_or_stand = (input("Hit or Stand? ")).upper() + print("Dealer shows: {}".format(dealer.shown(dealer_hand))) + print(player_hand.value) + print(dealer_hand.value) + 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("Player hand: {}".format(player_hand.cards)) + print("Dealer hand: {}".format(dealer.shown(dealer_hand))) + p_bust = game.bust_check(player_hand) + if p_bust == True: + break + hit_or_stand = 0 + if p_bust == True: + break + + print("Dealer's turn.") + print("Dealer has: {}".format(dealer_hand.cards)) + #d_blackjack = game.blackjack_check() + + hit_or_stand = dealer.hit_test(dealer_hand) + while hit_or_stand == "HIT": + print("Dealer hits.") + dealer_hand.get_card(deck) + dealer_hand.value = dealer_hand.valuation() + print("Dealer hand: {}".format(dealer_hand.cards)) + d_bust = game.bust_check(dealer_hand) + if d_bust == True: + break + hit_or_stand = dealer.hit_test(dealer_hand) + if d_bust == True: + break + + print("Dealer stands.") + 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: + #TIE GAME Conditions + else: + if p_blackjack: + #Player blackjack! + #deal out the appropriate chips + if d_blackjack: + #dealer has blackjack + if p_bust: + print("Sorry, you busted! Dealer wins.") + print("You have {} chips remaining.".format(player.chips)) + if d_bust: + print("Dealer busts! You win.") + player.win_bet + print("You have {} chips remaining.".format(player.chips)) diff --git a/blackjack/dealer.py b/blackjack/dealer.py index f007a3a..fcaae97 100644 --- a/blackjack/dealer.py +++ b/blackjack/dealer.py @@ -23,18 +23,18 @@ def __init__(self): def hit_test(self, a_hand): list_of_a = [card.rank for card in a_hand.cards if card.rank == 'A'] - print("Length = {}".format(len(list_of_a))) - print("Value = {}".format(a_hand.value)) + #print("Length = {}".format(len(list_of_a))) + #print("Value = {}".format(a_hand.value)) if len(list_of_a) > 0: if a_hand.value < 18: - return "Hit" + return "HIT" else: - return "Stand" + return "STAND" else: if a_hand.value < 17: - return "Hit" + return "HIT" else: - return "Stand" + return "STAND" diff --git a/blackjack/functions.py b/blackjack/functions.py new file mode 100644 index 0000000..146f3f9 --- /dev/null +++ b/blackjack/functions.py @@ -0,0 +1,7 @@ +def hit_stand(x): + if x == 'HIT': + return True + if x == 'STAND': + return True + else: + return False diff --git a/blackjack/game.py b/blackjack/game.py index 2609d8d..ef9e059 100644 --- a/blackjack/game.py +++ b/blackjack/game.py @@ -16,13 +16,16 @@ def create_and_shuffle_deck(self): return deck def blackjack_check(self, hand): - pass + if hand.value == 21: + return True + else: + return False def bust_check(self, hand): if hand.value > 21: - return 'bust' + return True else: - return 'ok' + return False def higher_hand(self, p_hand, d_hand): """if both player and dealer stand, checks to see who wins""" diff --git a/blackjack/tests/test_dealer.py b/blackjack/tests/test_dealer.py index ac0e467..038ed2e 100644 --- a/blackjack/tests/test_dealer.py +++ b/blackjack/tests/test_dealer.py @@ -22,9 +22,9 @@ def test_hit_test(): 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" + 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) @@ -33,6 +33,6 @@ def test_hit_test(): e_hand.cards = [Card('A', 'Hearts'), Card('6', 'Diamonds')] f_hand.cards = [Card('A', 'Hearts'), Card('7', 'Diamonds')] - 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(d_hand) == "HIT" + assert dealer.hit_test(e_hand) == "HIT" + assert dealer.hit_test(f_hand) == "STAND" diff --git a/blackjack/tests/test_functions.py b/blackjack/tests/test_functions.py new file mode 100644 index 0000000..1f02d16 --- /dev/null +++ b/blackjack/tests/test_functions.py @@ -0,0 +1,9 @@ +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 index 54a0a50..fe09fb3 100644 --- a/blackjack/tests/test_game.py +++ b/blackjack/tests/test_game.py @@ -11,9 +11,9 @@ def test_bust_check(): b_hand = Hand(value=21) c_hand = Hand(value=22) - assert game.bust_check(a_hand) == 'ok' - assert game.bust_check(b_hand) == 'ok' - assert game.bust_check(c_hand) == 'bust' + assert game.bust_check(a_hand) == False + assert game.bust_check(b_hand) == False + assert game.bust_check(c_hand) == True def test_higher_hand(): From 232d5ccd1515e1f4b9081c93e928806824898fce Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Sat, 24 Jan 2015 16:34:57 -0500 Subject: [PATCH 08/12] working game, normal mode --- blackjack/__main__.py | 224 ++++++++++++++++++++------------- blackjack/dealer.py | 4 + blackjack/hand.py | 4 + blackjack/player.py | 8 ++ blackjack/tests/test_dealer.py | 7 ++ blackjack/tests/test_hand.py | 8 ++ blackjack/tests/test_player.py | 10 ++ 7 files changed, 180 insertions(+), 85 deletions(-) diff --git a/blackjack/__main__.py b/blackjack/__main__.py index f72d102..70b7c15 100644 --- a/blackjack/__main__.py +++ b/blackjack/__main__.py @@ -12,96 +12,150 @@ player = Player() dealer = Dealer() - 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 p_bust or d_bust or p_blackjack or d_blackjack): - game = Game() - deck = game.create_and_shuffle_deck() - player_hand = Hand() - dealer_hand = Hand() - - - 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("Player hand: {}".format(player_hand.cards)) - print("Dealer shows: {}".format(dealer.shown(dealer_hand))) - print(player_hand.value) - print(dealer_hand.value) - 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("Player hand: {}".format(player_hand.cards)) - print("Dealer hand: {}".format(dealer.shown(dealer_hand))) - p_bust = game.bust_check(player_hand) - if p_bust == True: - break - hit_or_stand = 0 - if p_bust == True: - break - - print("Dealer's turn.") - print("Dealer has: {}".format(dealer_hand.cards)) - #d_blackjack = game.blackjack_check() - - hit_or_stand = dealer.hit_test(dealer_hand) - while hit_or_stand == "HIT": - print("Dealer hits.") + 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 + + player.make_bet() + + 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") + 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("Dealer hand: {}".format(dealer_hand.cards)) - d_bust = game.bust_check(dealer_hand) - if d_bust == True: + + print("Player hand: {} {}".format(player_hand.value, player_hand.cards)) + print("Dealer shows: {} [{}]".format(dealer.shown_value(dealer_hand), dealer.shown(dealer_hand))) + #print(dealer_hand.value) + 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("Player has: {} {}".format(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 == True: + break + hit_or_stand = 0 + if p_bust == 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) - if d_bust == True: - break - - print("Dealer stands.") - 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 + 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("Player has: {} {}".format(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 == True: + break + hit_or_stand = dealer.hit_test(dealer_hand) + if d_bust == 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)) - if p_blackjack and d_blackjack: - #TIE GAME Conditions - else: - if p_blackjack: - #Player blackjack! - #deal out the appropriate chips - if d_blackjack: - #dealer has blackjack - if p_bust: - print("Sorry, you busted! Dealer wins.") - print("You have {} chips remaining.".format(player.chips)) - if d_bust: - print("Dealer busts! You win.") - player.win_bet + 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 < 10: + print("You don't have enough chips to make another bet!") + 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/dealer.py b/blackjack/dealer.py index fcaae97..06cab57 100644 --- a/blackjack/dealer.py +++ b/blackjack/dealer.py @@ -41,6 +41,10 @@ def hit_test(self, a_hand): def shown(self, a_hand): return a_hand.cards[1] + def shown_value(self, a_hand): + card = a_hand.cards[1] + return card.rank + def __str__(self): return "Dealer" diff --git a/blackjack/hand.py b/blackjack/hand.py index a360d91..09f6647 100644 --- a/blackjack/hand.py +++ b/blackjack/hand.py @@ -29,6 +29,10 @@ def get_card(self, deck): card = deck.draw() return self.cards.append(card) + def new_card(self): + newest_card = self.cards[-1] + return newest_card + def valuation(self): value_dict = {'1':1, '2':2, diff --git a/blackjack/player.py b/blackjack/player.py index 6c1015c..4dfcce8 100644 --- a/blackjack/player.py +++ b/blackjack/player.py @@ -24,6 +24,14 @@ def win_bet(self): self.chips += 20 return self.chips + def win_blackjack(self): + self.chips += 25 + return self.chips + + def push(self): + self.chips += 10 + return self.chips + def __str__(self): return "Player has {} chips.".format(self.chips) diff --git a/blackjack/tests/test_dealer.py b/blackjack/tests/test_dealer.py index 038ed2e..b8d6577 100644 --- a/blackjack/tests/test_dealer.py +++ b/blackjack/tests/test_dealer.py @@ -13,6 +13,13 @@ def test_shown_cards(): 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' + + def test_hit_test(): dealer = Dealer() a_hand = Hand(value=16) diff --git a/blackjack/tests/test_hand.py b/blackjack/tests/test_hand.py index c2604d8..6666223 100644 --- a/blackjack/tests/test_hand.py +++ b/blackjack/tests/test_hand.py @@ -9,6 +9,14 @@ def test_get_card(): 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')] diff --git a/blackjack/tests/test_player.py b/blackjack/tests/test_player.py index 30cb968..1dc4b60 100644 --- a/blackjack/tests/test_player.py +++ b/blackjack/tests/test_player.py @@ -13,3 +13,13 @@ 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 From 40e1c7db2094471f2ce79eda87a9bc6cffecc886 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Sat, 24 Jan 2015 21:49:32 -0500 Subject: [PATCH 09/12] added variable betting --- blackjack/__main__.py | 21 +++++++++++++++++---- blackjack/dealer.py | 5 ++++- blackjack/player.py | 11 ++++++----- blackjack/tests/test_dealer.py | 5 ++++- blackjack/tests/test_player.py | 4 ++++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/blackjack/__main__.py b/blackjack/__main__.py index 70b7c15..29a6c23 100644 --- a/blackjack/__main__.py +++ b/blackjack/__main__.py @@ -12,6 +12,9 @@ player = Player() dealer = Dealer() + print("\n \n") + print("Let's play blackjack!") + play_game = True while play_game: @@ -23,8 +26,6 @@ p_blackjack = False d_blackjack = False - player.make_bet() - while not (p_win or d_win or tie or p_blackjack or d_blackjack): game = Game() deck = game.create_and_shuffle_deck() @@ -33,6 +34,18 @@ print ("\n \n") print ("New Hand\n") + + while True: + print("You have {} chips.".format(player.chips)) + print("What is your bet?") + new_bet = input("> ") + 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) @@ -144,8 +157,8 @@ player.push() print("You have {} chips remaining.".format(player.chips)) - if player.chips < 10: - print("You don't have enough chips to make another bet!") + 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() diff --git a/blackjack/dealer.py b/blackjack/dealer.py index 06cab57..6c5a1c2 100644 --- a/blackjack/dealer.py +++ b/blackjack/dealer.py @@ -43,7 +43,10 @@ def shown(self, a_hand): def shown_value(self, a_hand): card = a_hand.cards[1] - return card.rank + new_hand = Hand() + new_hand.cards = [card] + value = new_hand.valuation() + return value def __str__(self): return "Dealer" diff --git a/blackjack/player.py b/blackjack/player.py index 4dfcce8..121bf4d 100644 --- a/blackjack/player.py +++ b/blackjack/player.py @@ -13,23 +13,24 @@ class Player: Collaborators:""" - def __init__(self, chips=100): + def __init__(self, chips=100, bet=10): self.chips = chips + self.bet = bet def make_bet(self): - self.chips -= 10 + self.chips -= self.bet return self.chips def win_bet(self): - self.chips += 20 + self.chips += (2*self.bet) return self.chips def win_blackjack(self): - self.chips += 25 + self.chips += (2.5*self.bet) return self.chips def push(self): - self.chips += 10 + self.chips += self.bet return self.chips def __str__(self): diff --git a/blackjack/tests/test_dealer.py b/blackjack/tests/test_dealer.py index b8d6577..5ff9a4e 100644 --- a/blackjack/tests/test_dealer.py +++ b/blackjack/tests/test_dealer.py @@ -17,7 +17,10 @@ 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' + 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(): diff --git a/blackjack/tests/test_player.py b/blackjack/tests/test_player.py index 1dc4b60..55ba062 100644 --- a/blackjack/tests/test_player.py +++ b/blackjack/tests/test_player.py @@ -9,6 +9,10 @@ def test_make_bet(): 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() From d57598d32d5ab38e6fb81a35eac4deafa0490c58 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Sun, 25 Jan 2015 15:01:27 -0500 Subject: [PATCH 10/12] Doc strings and pep8 cleaning --- blackjack/__main__.py | 43 ++++++++++++++++++------------- blackjack/card.py | 1 - blackjack/dealer.py | 16 +++++++----- blackjack/dealer_hand.py | 8 ------ blackjack/deck.py | 21 ++++++++++----- blackjack/functions.py | 1 + blackjack/game.py | 4 +++ blackjack/hand.py | 40 ++++++++++++++-------------- blackjack/player.py | 10 ++++--- blackjack/shoe.py | 35 ------------------------- blackjack/tests/test_card.py | 2 ++ blackjack/tests/test_dealer.py | 1 + blackjack/tests/test_deck.py | 2 ++ blackjack/tests/test_functions.py | 1 + blackjack/tests/test_game.py | 7 ++--- blackjack/tests/test_hand.py | 9 ++++--- blackjack/tests/test_player.py | 4 +++ 17 files changed, 100 insertions(+), 105 deletions(-) delete mode 100644 blackjack/dealer_hand.py delete mode 100644 blackjack/shoe.py diff --git a/blackjack/__main__.py b/blackjack/__main__.py index 29a6c23..3d8aa91 100644 --- a/blackjack/__main__.py +++ b/blackjack/__main__.py @@ -32,8 +32,8 @@ player_hand = Hand() dealer_hand = Hand() - print ("\n \n") - print ("New Hand\n") + print("\n \n") + print("New Hand\n") while True: print("You have {} chips.".format(player.chips)) @@ -43,7 +43,6 @@ if player.bet <= player.chips: break - player.make_bet() player_hand.get_card(deck) @@ -54,9 +53,10 @@ player_hand.value = player_hand.valuation() dealer_hand.value = dealer_hand.valuation() - print("Player hand: {} {}".format(player_hand.value, player_hand.cards)) - print("Dealer shows: {} [{}]".format(dealer.shown_value(dealer_hand), dealer.shown(dealer_hand))) - #print(dealer_hand.value) + print("Player hand: {} {}".format( + player_hand.value, player_hand.cards)) + print("Dealer shows: {} [{}]".format( + dealer.shown_value(dealer_hand), dealer.shown(dealer_hand))) p_blackjack = game.blackjack_check(player_hand) d_blackjack = game.blackjack_check(dealer_hand) if p_blackjack is True: @@ -72,21 +72,25 @@ print("") print("{}".format(player_hand.new_card())) print("") - print("Player has: {} {}".format(player_hand.value, player_hand.cards)) - print("Dealer shows: {} [{}]".format(dealer.shown_value(dealer_hand), dealer.shown(dealer_hand))) + print("Player has: {} {}".format( + 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 == True: + if p_bust is True: break hit_or_stand = 0 - if p_bust == True: + 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)) + print("Dealer has: {} {}".format( + dealer_hand.value, dealer_hand.cards)) input("Press ENTER to continue. \n") print("") @@ -101,21 +105,24 @@ dealer_hand.value = dealer_hand.valuation() print("{}".format(dealer_hand.new_card())) print("") - print("Player has: {} {}".format(player_hand.value, player_hand.cards)) - print("Dealer has: {} {}".format(dealer_hand.value, dealer_hand.cards)) + print("Player has: {} {}".format( + 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 == True: + if d_bust is True: break hit_or_stand = dealer.hit_test(dealer_hand) - if d_bust == True: + 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)) - + 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': diff --git a/blackjack/card.py b/blackjack/card.py index 6225ef3..cd42cb9 100644 --- a/blackjack/card.py +++ b/blackjack/card.py @@ -4,7 +4,6 @@ class Card: Responsibilities: * Has a rank and a suit. - * Two cards with the same suit and rank should be equal to each other * Cards should have readable representations Collaborators: diff --git a/blackjack/dealer.py b/blackjack/dealer.py index 6c5a1c2..6057b59 100644 --- a/blackjack/dealer.py +++ b/blackjack/dealer.py @@ -3,6 +3,7 @@ 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 @@ -12,19 +13,20 @@ class Dealer: * 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: - * on hit, tell dealer's Hand to get Card from Shoe - * """ + * 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""" list_of_a = [card.rank for card in a_hand.cards if card.rank == 'A'] - #print("Length = {}".format(len(list_of_a))) - #print("Value = {}".format(a_hand.value)) if len(list_of_a) > 0: if a_hand.value < 18: return "HIT" @@ -36,12 +38,12 @@ def hit_test(self, a_hand): 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] diff --git a/blackjack/dealer_hand.py b/blackjack/dealer_hand.py deleted file mode 100644 index 8b6bd39..0000000 --- a/blackjack/dealer_hand.py +++ /dev/null @@ -1,8 +0,0 @@ -class Dealer_Hand: - """ A collection of 1-6 decks. - - Responsibilities: - * - - Collaborators: - * diff --git a/blackjack/deck.py b/blackjack/deck.py index 26d7e7a..f39fd4f 100644 --- a/blackjack/deck.py +++ b/blackjack/deck.py @@ -15,25 +15,32 @@ class Deck: Collaborators: * consists of cards""" - def __init__(self): - ranks = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] + 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() - + 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 index 146f3f9..486bc3d 100644 --- a/blackjack/functions.py +++ b/blackjack/functions.py @@ -1,4 +1,5 @@ def hit_stand(x): + "checks to see if input was an acceptable option" if x == 'HIT': return True if x == 'STAND': diff --git a/blackjack/game.py b/blackjack/game.py index ef9e059..cd50a8a 100644 --- a/blackjack/game.py +++ b/blackjack/game.py @@ -11,17 +11,21 @@ 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: diff --git a/blackjack/hand.py b/blackjack/hand.py index 09f6647..670e174 100644 --- a/blackjack/hand.py +++ b/blackjack/hand.py @@ -1,8 +1,9 @@ from blackjack.card import Card from blackjack.deck import Deck + class Hand: - """ The current cards in the hand + """ A hand (either for player or dealer) that can contain cards Responsibilities: * keep track of which cards are in the hand @@ -10,9 +11,7 @@ class Hand: Collaborators: - * get popped cards from the shoe - * give Dealer the cards and value of the two hands - * give user the cards and value of the two hands""" + * get popped cards from the shoe""" def __init__(self, value=0): self.cards = [] @@ -26,28 +25,32 @@ 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): - 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} + """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) @@ -56,7 +59,6 @@ def valuation(self): values = [value_dict[x] for x in hand_ranks] value = sum(values) - while a_counter > 0: if value > 21: value -= 10 diff --git a/blackjack/player.py b/blackjack/player.py index 121bf4d..e02b29c 100644 --- a/blackjack/player.py +++ b/blackjack/player.py @@ -4,32 +4,34 @@ class Player: - """ + """Keeps track of the player's betting Responsibilities: * has chips * bets chips - * wins chips - - Collaborators:""" + * wins chips of various values""" def __init__(self, chips=100, bet=10): self.chips = chips self.bet = bet def make_bet(self): + """makes initial bet, taking bet amount from chip count""" self.chips -= self.bet return self.chips def win_bet(self): + """returns original bet, plus bet amount for winning""" self.chips += (2*self.bet) return self.chips def win_blackjack(self): + """returns original bet, plus augmented blackjack winnings""" self.chips += (2.5*self.bet) return self.chips def push(self): + """returns original bet""" self.chips += self.bet return self.chips diff --git a/blackjack/shoe.py b/blackjack/shoe.py deleted file mode 100644 index 3ba8998..0000000 --- a/blackjack/shoe.py +++ /dev/null @@ -1,35 +0,0 @@ -import random - -from card import Card -from deck import Deck - - -class Shoe: - """ A collection of 1-6 decks. - - Responsibilities: - *take an argument for the number of decks - *combine and shuffle decks - *pop the last item off of the shuffled deck and send it to either - player_hand or dealer_hand - - Collaborators: - *gets decks to combine into shoe - * pops the last item off of the shuffled deck and send it to either - the dealer's Hand or the player's Hand""" - - def __init__(self, an_int, a_deck): - self.decks = an_int - self.shuffle = random.shuffle(a_deck.cards * an_int - - - def __str__(self): - card_list = [str(card) for card in self.shuffle] - return ', '.join(card_list) - - - def __repr__(self): - return self.__str__ - -a_shoe = Shoe(1) -print(a_shoe) diff --git a/blackjack/tests/test_card.py b/blackjack/tests/test_card.py index a6d3050..011a719 100644 --- a/blackjack/tests/test_card.py +++ b/blackjack/tests/test_card.py @@ -1,10 +1,12 @@ 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" diff --git a/blackjack/tests/test_dealer.py b/blackjack/tests/test_dealer.py index 5ff9a4e..d500447 100644 --- a/blackjack/tests/test_dealer.py +++ b/blackjack/tests/test_dealer.py @@ -4,6 +4,7 @@ from blackjack.player import Player from blackjack.dealer import Dealer + def test_shown_cards(): dealer = Dealer() a_hand = Hand() diff --git a/blackjack/tests/test_deck.py b/blackjack/tests/test_deck.py index 2b32e07..9d9d65c 100644 --- a/blackjack/tests/test_deck.py +++ b/blackjack/tests/test_deck.py @@ -1,10 +1,12 @@ 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() diff --git a/blackjack/tests/test_functions.py b/blackjack/tests/test_functions.py index 1f02d16..bbef33e 100644 --- a/blackjack/tests/test_functions.py +++ b/blackjack/tests/test_functions.py @@ -1,5 +1,6 @@ import blackjack.functions as fun + def test_hit_stand(): x = 'HIT' y = 'STAND' diff --git a/blackjack/tests/test_game.py b/blackjack/tests/test_game.py index fe09fb3..8a6f194 100644 --- a/blackjack/tests/test_game.py +++ b/blackjack/tests/test_game.py @@ -5,15 +5,16 @@ 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) == False - assert game.bust_check(b_hand) == False - assert game.bust_check(c_hand) == True + 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(): diff --git a/blackjack/tests/test_hand.py b/blackjack/tests/test_hand.py index 6666223..1003682 100644 --- a/blackjack/tests/test_hand.py +++ b/blackjack/tests/test_hand.py @@ -2,6 +2,7 @@ from blackjack.deck import Deck from blackjack.hand import Hand + def test_get_card(): a_deck = Deck() a_hand = Hand() @@ -9,6 +10,7 @@ def test_get_card(): 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')] @@ -19,9 +21,10 @@ def test_new_card(): def test_valuation_non_ace(): a_hand = Hand() - a_hand.cards =[Card('2', 'Hearts'), Card('10', 'Spades')] + 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() @@ -34,9 +37,9 @@ def test_valuation_ace_test(): Card('A', 'Spades'), Card('K', 'Clubs')] c_hand.cards = [Card('A', 'Hearts'), - Card('A', 'Spades'),] + Card('A', 'Spades')] d_hand.cards = [Card('A', 'Hearts'), - Card('5', 'Spades'),] + Card('5', 'Spades')] assert a_hand.valuation() == 16 assert b_hand.valuation() == 12 diff --git a/blackjack/tests/test_player.py b/blackjack/tests/test_player.py index 55ba062..f064310 100644 --- a/blackjack/tests/test_player.py +++ b/blackjack/tests/test_player.py @@ -3,6 +3,7 @@ from blackjack.hand import Hand from blackjack.player import Player + def test_make_bet(): a_player = Player() assert a_player.chips == 100 @@ -13,16 +14,19 @@ def test_make_bet(): 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() From d0372a6ec299847f96a336aa7c51ee3f6e916204 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Sun, 25 Jan 2015 21:22:33 -0500 Subject: [PATCH 11/12] added player naming, fixed a couple of bugs --- blackjack/__main__.py | 18 +++++++++++------- blackjack/dealer.py | 21 ++++++++++++++++++++- blackjack/game.py | 3 +++ blackjack/player.py | 16 +++++++++------- blackjack/tests/test_dealer.py | 4 ++++ blackjack/tests/test_player.py | 4 ++++ 6 files changed, 51 insertions(+), 15 deletions(-) diff --git a/blackjack/__main__.py b/blackjack/__main__.py index 3d8aa91..14ba9e0 100644 --- a/blackjack/__main__.py +++ b/blackjack/__main__.py @@ -13,7 +13,9 @@ dealer = Dealer() print("\n \n") - print("Let's play blackjack!") + player.name = input("What's your name? ") + print("") + print("Hi {}, let's play blackjack!".format(player.name)) play_game = True while play_game: @@ -39,6 +41,7 @@ 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 @@ -53,10 +56,11 @@ player_hand.value = player_hand.valuation() dealer_hand.value = dealer_hand.valuation() - print("Player hand: {} {}".format( - player_hand.value, player_hand.cards)) + 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: @@ -72,8 +76,8 @@ print("") print("{}".format(player_hand.new_card())) print("") - print("Player has: {} {}".format( - player_hand.value, player_hand.cards)) + print("{} has: {} {}".format( + player.name, player_hand.value, player_hand.cards)) print("Dealer shows: {} [{}]".format( dealer.shown_value(dealer_hand), dealer.shown( dealer_hand))) @@ -105,8 +109,8 @@ dealer_hand.value = dealer_hand.valuation() print("{}".format(dealer_hand.new_card())) print("") - print("Player has: {} {}".format( - player_hand.value, player_hand.cards)) + 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") diff --git a/blackjack/dealer.py b/blackjack/dealer.py index 6057b59..ba3870b 100644 --- a/blackjack/dealer.py +++ b/blackjack/dealer.py @@ -26,8 +26,27 @@ def __init__(self): 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: + if len(list_of_a) > 0 and value < 21: if a_hand.value < 18: return "HIT" else: diff --git a/blackjack/game.py b/blackjack/game.py index cd50a8a..44b6f04 100644 --- a/blackjack/game.py +++ b/blackjack/game.py @@ -6,6 +6,9 @@ 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 diff --git a/blackjack/player.py b/blackjack/player.py index e02b29c..f21753a 100644 --- a/blackjack/player.py +++ b/blackjack/player.py @@ -9,31 +9,33 @@ class Player: Responsibilities: * has chips * bets chips - * wins chips of various values""" + * wins chips of various values + * holds the player's name""" - def __init__(self, chips=100, bet=10): + 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 self.chips + return int(self.chips) def win_bet(self): """returns original bet, plus bet amount for winning""" self.chips += (2*self.bet) - return self.chips + return int(self.chips) def win_blackjack(self): """returns original bet, plus augmented blackjack winnings""" - self.chips += (2.5*self.bet) - return self.chips + self.chips += int(2.5*self.bet) + return int(self.chips) def push(self): """returns original bet""" self.chips += self.bet - return self.chips + return int(self.chips) def __str__(self): return "Player has {} chips.".format(self.chips) diff --git a/blackjack/tests/test_dealer.py b/blackjack/tests/test_dealer.py index d500447..34ad1e2 100644 --- a/blackjack/tests/test_dealer.py +++ b/blackjack/tests/test_dealer.py @@ -40,10 +40,14 @@ def test_hit_test(): 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_player.py b/blackjack/tests/test_player.py index f064310..261993f 100644 --- a/blackjack/tests/test_player.py +++ b/blackjack/tests/test_player.py @@ -4,6 +4,10 @@ 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 From 40512a66d82880918d3a8c925828bb9a93b33e68 Mon Sep 17 00:00:00 2001 From: Bret Runestad Date: Sun, 25 Jan 2015 21:33:25 -0500 Subject: [PATCH 12/12] updated README --- README.md | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fd1c204..029f26d 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,27 @@ # Blackjack -Blackjack is a game played between a Dealer and a Player. +Players can start the game in their console by typing: +python -m blackjack -1. At the start of the game, the Player has the choice of how many Decks they would like in the Shoe. The choice is from 1-6. +Blackjack is a game played between a Dealer and a Player. -2. Cards are dealt from a Shoe that consists of one or more Decks. -These cards constitute the Hands of each player, PlayerHand and DealerHand. +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.) -3. The player's PointTotal is the combined points of his hand. The dealer's PointTotal is the combined points of his hand. +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. -4. Points are ascribed as follows: - The ace is worth 11 points, unless the PointTotal of the hand with an 11-point ace is worth more than 21. In that case, it is worth 1 point. +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 -5. After the cards are dealt, the first Round takes place: - -ROUND: -a. the Player has the choice to Hit or Stay. Hitting means that another Card is drawn from the Shoe, the Card is added to the player's hand and the points from that card are added to the PointTotal of the Player's Hand. Stay means that no more cards are drawn, and his PointTotal remains at its current amount. Stay also means that he stays for all future rounds. +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. -b. 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. +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. -c. If the player has not busted, the Dealer either hits or stays based on its built in hit-or-stay algorithm. If the TotalPoints in DealerHand are less than 17, the Dealer will Hit. If the TotalPoints 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 PointTotal are increased by the point value of the card card. +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. -d. After Dealer plays, another win-condition check. If the player's last move was stay, and the Dealer's hand is greater than 17, the game ends. Whoever's hand has the greater PointTotal is the winner. -If the Dealer hits and busts(PointTotal greater than 21), the player wins. +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. -6. Repeat Rounds until one of the win conditions is met +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.