-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added Blackjack #591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Blackjack #591
Conversation
Blackjack/blackjack.py
Outdated
|
||
import random | ||
|
||
suits = ('Hearts', 'Diamonds', 'Spades', 'Clubs') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make the suits and ranks as class variables of Card class and values in Hand class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@mehabhalodiya I guess I made an error in the suggestion: class Deck: # creates a deck of cards
suits = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
ranks = ('Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Jack', 'Queen', 'King', 'Ace')
def __init__(self):
self.deck = [] # haven't created a deck yet
for suit in Deck.suits:
for rank in Deck.ranks:
self.deck.append(Card(suit, rank)) Implement the same in Hand class. |
So i have to remove |
Yes
Nope, only values in Hand class. Make sure to update the access method: def __init__(self):
self.deck = [] # haven't created a deck yet
for suit in Deck.suits:
for rank in Deck.ranks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mehabhalodiya did you run the script after updating?
Exactly, this error will pop up because as you made the "values" class variable, it will be accessed as Class_name.values. Mentioned this in #591 (comment) but you updated it for one class only |
Sorry for this! I forgot! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM..Great Work
Description
While building the game, one will explore a few handy Python concepts, such as object-oriented programming using classes and how to manage a game loop.
I have used Python's
random
library, which has various functions used in generating randomness. In particular, we employshuffle
, which takes any list and returns it in random order, to shuffle our deck of cards.Initially, we will begin by defining the classes that will be used in order to separate out different aspects of the game of blackjack. We will model three of the components of the game:
Card
: A basic playing card. The card belongs to a suit (hearts ♥, diamonds ♦, spades ♠, or clubs ♣) and is worth a certain value.Deck
: A collection of cards. The deck shrinks as cards are drawn and contains 52 unique cards.Hand
: Each player's assigned cards. A hand is what defines each player's score and thus who wins.Chips
: To keep track.Further, create all the list of functions which perform various actions and finally, the game loop!
Fixes #549 Blackjack
Have you read the Contributing Guidelines on Pull Requests?
Type of change
Checklist:
README.md
Template for README.md