To run: python main.py
Tested using Python 3.4.1
Written for insight data fellows program. Would love to refactor more and add split, but am leaving for vacation tomorrow morning!
- Player starts with 100 chips
- Bets between 1 and the amount of chips the player has are allowable
- Allowable actions for the player:
- (H)it
- player is dealt one additional card
- if the player doesn't bust, they can take additional action(s)
- (S)tand
- player is dealt no additional cards
- player can take no additional action(s)
- (D)ouble
- player doubles bet
- player is dealt one additional card
- player can take no additional action(s)
- (H)it
- Dealer must hit until their hand totals at least 17, then cannot hit
- Dealer does not hit soft 17
- Game Outcomes:
- Push: the player and dealer tie - the bet is returned to the player
- Dealer Wins: dealer has more than player and less than 21 - bet is forfeited by the player
- Player Wins: player has more than dealer and less than 21 - player is paid their bet
- Dealer Bust: dealer has more than 21 - player is paid their bet
- Player Bust: player has more than 21 - bet is foreited by the player
- Player Blackjack: player is dealt 21 (first two cards) - player is paid 1.5 times their bet
- Dealer Blackjack: dealer is dealt 21 (first two cards) - bet is forfeited by player
Simple class to represent a card.
- Attributes:
value
suit
- Methods:
__init__
- creates card with given value and suitprettyPrint
- print value of card between vertical bars
Class to represent a deck.
- Attributes:
sequence
- array containing deck cards in orderdiscard
- array containing cards previously dealt
- Methods:
__init__
- generates full deck in ordershuffle
- implements Fisher-Yates shuffleswap
- swaps cards to support shuffledeal
- pops card off deck, adds to discard, returns to callerprintDeck
- prints the current sequence of cards to console
Class to encapsulate common game functions to allow main to focus on data input/output.
- Attributes:
gameDeck
- Deck instance holding current deckplayerHand
- array that holds player cardsdealerHand
- array that holds dealer cards
- Methods:
__init__
- initializesgameDeck
newGame
- shufflesgameDeck
, initializesplayerHand
anddealerHand
deal
- deals 2 cards to player and dealer by alternatinghitPlayer
- deals card to playerhitDealer
- deals card to dealerisPlayerBusted
- returns True if hand is over 21isDealerBusted
- returns True if hand is over 21isDealerComplete
- returns True if dealer hand is over 16didPlayerBlackjack
- returns True if first two cards total 21didDealerBlackjack
- returns True if first two cards total 21handResult
- evaluates hands, returns "dealer win", "player win", or "push" depending on resultprintGame
- prints hands of player and dealer to consoleevaluateHand
-classmethod
- returns numeric value of handgetCardValue
-classmethod
- returns numberic value of cardcheckBlackjack
-classmethod
- checks whether hand is blackjackisBusted
-classmethod
- checks whether hand is over 21payBlackjack
-staticmethod
- returns 3/2 * betpayWin
-staticmethod
- returns betprintHand
-staticmethod
- prints each card in handprintHidden
-staticmethod
- prints the second dealer card as X to hide it
Handles input / output for general gameplay. Manages general gameplay and player bank using an instance of Blackjack
.