I built a deck of cards that can be shuffled. I built the player module and had the dealer class inherit the deck. (as the dealer is the one to shuffle the cards, rather than the deck of cards shuffling itself) I tried to import both into a main and have the dealer shuffle. Nope, things start breaking.
After a while, I started just doing trial and error, adding random ()'s and self
's and whatever you can think of. Nothing worked. The main file is pretty much erased at this point, because I'm not just understanding anything from youtube or anything, really.
import random as rd
class Card:
card_rank = [str(n) for n in range(2, 10)]
card_rank.extend(['Ten', 'Jack', 'Queen', 'King', 'Ace'])
card_suit = ['Spades', 'Clubs', 'Diamonds', 'Hearts']
def __init__(self, rank, suit):
assert 2 <= rank <= 14 and 1 <= suit <= 4
self.rank = rank
self.suit = suit
def __str__(self):
return '{} of {}'.format(Card.card_rank[self.rank - 2], Card.card_suit[self.suit - 1])
class Deck:
def __init__(self):
self.cards = [Card(rank, suit) for rank in range(2, 14 + 1) for suit in range(1, 4 + 1)]
def is_empty(self):
return not self.cards
def pick(self):
rd.shuffle(self.cards)
return self.cards.pop()
import CardDeck class Player: def __init__(self): self.hand = [] class Human(Player): def __init__(self): super(Human, self).__init__() self.name = input() class Dealer(Player, CardDeck.Deck): def __init__(self): super(Dealer, self).__init__() def deck_shuffle(self): while not CardDeck.Deck.is_empty: print(CardDeck.Deck.pick)
> import CardDeck as cd
> import Players as pl
>
>
> dealer = pl.Dealer
>
>
> dealer.deck_shuffle
I want the dealer to shuffle the cards. I'm looking to see if it works by printing out the deck. I plan on doing more, but for now, I'm very stuck. (sorry for the formatting, this site confuses me on that)