Oop blackjack - methods - classes

Hey guys, I want to make a method for the Shoe class where I can tell it how many decks to add. Say I wanted to add 8 decks to the shoe I could do something like:
shoe = Shoe(8)
I tried
def build(self):
for deck in range(self.decks):
self.shoe.append(Deck.shuffle())

It didn’t work haha. How can I add ‘X’ instances of Deck.shuffle to self.shoe

LOL HELP ME

import random 

class Card:
    def __init__(self, r, s):
        self.rank = r
        self.suit = s
    
    def __repr__(self):
        return "{} of {}".format(self.rank, self.suit)

class Deck:
    def __init__(self):
        self.deck = []
        self.build()
    
    def build(self):
        for r in ['Ace', '2', '3', '4', '5', '6', '7',
             '8', '9', '10', 'Jack', 'Queen', 'King']:
             for s in ['Clubs', 'Diamonds', 'Hearts', 'Spades']:
                 self.deck.append(Card(r, s))

    def show(self):
        for c in self.deck:
            print(c)

    def shuffle(self):
        random.shuffle(self.deck)

class Shoe:
    def __init__(self, d):
        self.shoe = []
        self.decks = d
        self.build()

    def build(self):

random.shuffle() returns nothing, so if your method executed, you’d have a list with 8 elements:
[None, None, None, None, None, None, None, None]. It doesn’t execute though because shuffle can only be called on an instance of the Deck class. Your code is missing something if you want to create an instance of Deck to call the shuffle method on, but as I stated, it will return nothing. You probably want to create all of the decks first, and then shuffle each of them, or you could have your Deck class shuffle the deck immediately after building it.

2 Likes

I suspect that append is not the method you want to be using. If I’m correct, then your shoe build could just random.shuffle when build is called.