diff --git a/blackjack/__init__.py b/blackjack/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/card.py b/blackjack/card.py new file mode 100644 index 0000000..9bec65c --- /dev/null +++ b/blackjack/card.py @@ -0,0 +1,28 @@ +suits = ("Spades", "Clubs", "Hearts", "Diamonds") +ranks = ("Ace", "King", "Queen", "Jack", 10, 9, 8, 7, 6, 5, 4, 3, 2,) + + +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 __eq__(self, other): + """test equality for two cards.""" + return self.suit == other.suit and self.rank == other.rank + + def __repr__(self): + return "Card(rank = {}, suit = {})".format(self.rank, self.suit) diff --git a/blackjack/dealer_hand.py b/blackjack/dealer_hand.py new file mode 100644 index 0000000..10a4e41 --- /dev/null +++ b/blackjack/dealer_hand.py @@ -0,0 +1,15 @@ +class Dealer_hand: + """Current hand count + + Responsibilities: + + *Sums cards in hand + *Contains action possibilities + if < 17 == hit + if > 17 and <22 == stay + if > 21 == bust + + Collaboraters: + + *Recieves cards from Deck + *Sends results to Game_manager class""" diff --git a/blackjack/deck.py b/blackjack/deck.py new file mode 100644 index 0000000..2d8350f --- /dev/null +++ b/blackjack/deck.py @@ -0,0 +1,63 @@ +from blackjack.card import Card, ranks, suits +from blackjack.player_hand import Player_hand +import random + +class Deck: + """a deck of cards + + Responsibilites: + + *holds collection of cards + *new deck shoul have all 52 cards + *allow others to draw cards + *shuffles cards or re-shuffle + *report its current size + + *deals cards + *dealer gets first card down + + Collaboraters: + + *collected from card class + *deals cards to Hand""" + + + #def __eq__(self, other): + + + def __init__(self): + self.__cards__ = [Card(rank, suit) + for rank in ranks + for suit in suits] + + def __len__(self): + return len(self.__cards__) + + + def __str__(self): + return str(self.__card__) + + + def shuffle_deck(self): + random.shuffle(self.__cards__) + return self.__cards__ + +#"""take a card from the deck and return it.""" + + def deal_cards(self): + return self.__cards__.pop() + + + #for num in num cards: + + #player_hand.card1 = shuffled_deck.pop() + #player_hand.card2 = shuffled_deck.pop() + #dealer_hand.card1 = shuffled_deck.pop() + #dealer_hand.card2 = shuffled_deck.pop() + #print(player_hand.card1, player_hand.card2) + #return True + #new_deck = Deck() + #print(type(new_deck.card_deck)) + +#print(Deck.deal_cards(2, Deck.huffle_deck())) +#print(Deck.shuffle_deck()) diff --git a/blackjack/game_manager.py b/blackjack/game_manager.py new file mode 100644 index 0000000..591c6c3 --- /dev/null +++ b/blackjack/game_manager.py @@ -0,0 +1,8 @@ +class Game_manager: + """Controls who wins and loses + + Responsibilities: + + *Look at results and decides who wins and loses + *double user bet if user win + *If tie, then insert push rules diff --git a/blackjack/player_hand.py b/blackjack/player_hand.py new file mode 100644 index 0000000..26152d3 --- /dev/null +++ b/blackjack/player_hand.py @@ -0,0 +1,38 @@ +class Player_hand: + """current card count. + + Responsibilites: + + *sum cards in hand + *holds the possibilites of action + hit + stay + double down + split + if >= 22 == bust + + Collaboraters: + + *Recieves card from deck + *Gives actionable choices to player""" + + + def __init__(self, cards): + self.cards = cards + + def __str__(self): + return "Your cards our\n{}".format(self.cards) + + def player_card_count(self, cards): + count = 0 + for card in cards: + if card.rank in(2,3) + + + + #def initial_hand(self): + # initial_hand = sum([cards.points() for cards in self]) + # aces = len([card for card in self if card == card.rank == 'A']) + # # implement ace logic here + # score = initial_hand - max(0,10*min(int((initial_hand-22)/10)+1, aces)) + # return score 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..328d10e --- /dev/null +++ b/blackjack/tests/test_card.py @@ -0,0 +1,17 @@ +from blackjack.card import Card, ranks, suits +from blackjack.deck import Deck + +def test_suit_and_rand_are_set(): + new_card = Card("Q", "Hearts") + assert new_card.rank == "Q" + assert new_card.suit == "Hearts" + +def test_identical_cards_are_equal(): + queen1 = Card("Q", "Hearts") + queen2 = Card("Q", "Hearts") + + assert queen1 == queen2 + +#def test_card_representation_is_readable(): +# queen = Card +# assert repr(queen) == "Card('Q')" diff --git a/blackjack/tests/test_dealer_hand.py b/blackjack/tests/test_dealer_hand.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/tests/test_deck.py b/blackjack/tests/test_deck.py new file mode 100644 index 0000000..d51ab12 --- /dev/null +++ b/blackjack/tests/test_deck.py @@ -0,0 +1,19 @@ +from blackjack.card import Card, ranks, suits +from blackjack.deck import Deck + +def test_new_deck_has_52_cards(): + assert len(Deck()) == 52 + +def test_new_deck_can_draw_card(): + deck = Deck() + card = deck.deal_cards() + + assert card is not None + assert len(deck) == 51 + +def test_deck_can_be_shuffled(): + shuffled_deck = Deck() + straight_deck = Deck() + shuffled_deck.shuffle_deck() + + assert straight_deck != shuffled_deck diff --git a/blackjack/tests/test_game_manager.py b/blackjack/tests/test_game_manager.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/tests/test_player_hand.py b/blackjack/tests/test_player_hand.py new file mode 100644 index 0000000..1dade85 --- /dev/null +++ b/blackjack/tests/test_player_hand.py @@ -0,0 +1,8 @@ +from blackjack.player_hand import Player_hand +from blackjack.dealer_hand import Dealer_hand + +def test_get_hand(): + new_cards = Player_hand(["7 of Diamonds","10 of Hearts"]) + assert new_cards.cards == ["7 of Diamonds","10 of Hearts"] + +def test_ diff --git a/blackjack/tests/test_user.py b/blackjack/tests/test_user.py new file mode 100644 index 0000000..e69de29 diff --git a/blackjack/user.py b/blackjack/user.py new file mode 100644 index 0000000..531bdd1 --- /dev/null +++ b/blackjack/user.py @@ -0,0 +1,25 @@ +class User: + """User's actions + + Responsibilites: + + *Gives initial chip count + 500 + + *Chooses game settings + Change bet + Deal hand + + *Gives possible bet choice + 10 + 50 + 100 + + + Collaboraters: + + *choose possible actions passed from Hand + *choose how much to bet + #*Payout class will pull User bet + *Game_manager class sends user double bet if wins. + *possible push scenario...madness! diff --git a/blackjack_game.py b/blackjack_game.py new file mode 100644 index 0000000..7f08c72 --- /dev/null +++ b/blackjack_game.py @@ -0,0 +1,10 @@ +from card import Card +from deck import Deck + + +print(Card.card_list) +dealer = Dealer() +player = Player(100) #start with 100 units of currency +game = Game(dealer, [player]) #create a game with 1 dealer and 1-player +game.reset_hands() +game.deal()