Advertisement
dmesticg

Untitled

Jun 5th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import random
  2.  
  3. class deck: #!
  4. def __init__(self,numsuit,numcard):
  5. self.numsuit = numsuit
  6. self.numcard = numcard
  7. self.deck = [[True] * numsuit for i in range (numcard)]
  8.  
  9. def createCard(self): #!
  10. if self.deck.count:
  11. suitval = random.randint(0,self.numsuit-1)
  12. cardval = random.randint(0,self.numcard-1)
  13. while self.deck[cardval][suitval] == False:
  14. suitval = random.randint(0,self.numsuit-1)
  15. cardval = random.randint(0,self.numcard-1)
  16. self.deck[cardval][suitval] = False
  17. return((cardval,suitval))
  18.  
  19. def createHand(self,handSize):
  20. cards = []
  21. for i in range(handSize):
  22. card = deck.createCard(self)
  23. cards.append(card)
  24. return(cards)
  25.  
  26. def changeHand(self,hand,indexList):
  27. for i in range(len(indexList)):
  28. hand[indexList[i]] = deck.createCard(self)
  29. return(hand)
  30.  
  31. theDeck = deck(4,13)
  32. theHand = theDeck.createHand(5)
  33. print(theHand)
  34. theHand = theDeck.changeHand(theHand,[0,1])
  35. print(theHand)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement