Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added blackjack/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions blackjack/card.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions blackjack/dealer_hand.py
Original file line number Diff line number Diff line change
@@ -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"""
63 changes: 63 additions & 0 deletions blackjack/deck.py
Original file line number Diff line number Diff line change
@@ -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())
8 changes: 8 additions & 0 deletions blackjack/game_manager.py
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions blackjack/player_hand.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added blackjack/tests/__init__.py
Empty file.
17 changes: 17 additions & 0 deletions blackjack/tests/test_card.py
Original file line number Diff line number Diff line change
@@ -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')"
Empty file.
19 changes: 19 additions & 0 deletions blackjack/tests/test_deck.py
Original file line number Diff line number Diff line change
@@ -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
Empty file.
8 changes: 8 additions & 0 deletions blackjack/tests/test_player_hand.py
Original file line number Diff line number Diff line change
@@ -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_
Empty file added blackjack/tests/test_user.py
Empty file.
25 changes: 25 additions & 0 deletions blackjack/user.py
Original file line number Diff line number Diff line change
@@ -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!
10 changes: 10 additions & 0 deletions blackjack_game.py
Original file line number Diff line number Diff line change
@@ -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()