Skip to content

Conversation

mehabhalodiya
Copy link
Contributor

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 employ shuffle, 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?

  • Yes
  • No

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the style guidelines(Clean Code) of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have created a helpful and easy to understand README.md
  • My documentation follows Template for README.md
  • My changes generate no new warnings
  • I have added tests/screenshots that prove my script is effective or that my feature works.


import random

suits = ('Hearts', 'Diamonds', 'Spades', 'Clubs')
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@kaustubhgupta kaustubhgupta added the minor-change-not-bug Suggested a minor change in code, not a bug label Mar 16, 2021
@kaustubhgupta
Copy link
Contributor

@mehabhalodiya I guess I made an error in the suggestion:
The suits and ranks were part of Deck class and not Card class. Also, they need to be accessed via class name:

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.

@mehabhalodiya
Copy link
Contributor Author

So i have to remove suits and ranks from Card class and have to add in Deck class?
Further, suits and ranks should be added in Hand class too. Right?

@kaustubhgupta
Copy link
Contributor

So i have to remove suits and ranks from Card class and have to add in Deck class?

Yes

Further, suits and ranks should be added in Hand class too. Right?

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:

Copy link
Contributor

@kaustubhgupta kaustubhgupta left a 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?

@mehabhalodiya
Copy link
Contributor Author

Yes, I have checked it and it is now showing error messages as below:

bj

@kaustubhgupta
Copy link
Contributor

Yes, I have checked it and it is now showing error messages as below:

bj

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

@mehabhalodiya
Copy link
Contributor Author

Yes, I have checked it and it is now showing error messages as below:
bj

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!
Now I have modified.

@kaustubhgupta kaustubhgupta added next review needed Approved by some mentors, more approvals needed and removed minor-change-not-bug Suggested a minor change in code, not a bug labels Mar 17, 2021
Copy link
Contributor

@antrikshmisri antrikshmisri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

Copy link
Contributor

@santushtisharma10 santushtisharma10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@santushtisharma10 santushtisharma10 added Approved PR Approved and Ready to Merge gssoc23 Issues created for/by the GirlScript Summer of Code'23 Participants level1 Wiki or Major Documentation Work and removed next review needed Approved by some mentors, more approvals needed labels Mar 18, 2021
Copy link
Owner

@avinashkranjan avinashkranjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM..Great Work

@avinashkranjan avinashkranjan merged commit 60b3532 into avinashkranjan:master Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved PR Approved and Ready to Merge gssoc23 Issues created for/by the GirlScript Summer of Code'23 Participants level1 Wiki or Major Documentation Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blackjack
5 participants