Guest User

Untitled

a guest
Jun 25th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import sys
  3. import random
  4.  
  5. class Deck(object):
  6. def __init__(self,max_cards):
  7. self.suit_list = ['heart','diamond','club','spade']
  8. self.cards_held = []
  9. self.max = max_cards
  10. # if 52 create a new deck
  11. if self.max == 52:
  12. for card_num in range(0,52):
  13. face = str(card_num % 13)
  14. if face == '0':
  15. face = 'K'
  16. if face == '1':
  17. face = 'A'
  18. if face == '12':
  19. face = 'Q'
  20. if face == '11':
  21. face = 'J'
  22. suit_index = (card_num/13) % 13
  23. suit = self.suit_list[suit_index]
  24. self.cards_held.append((face,suit))
  25.  
  26. def draw(self):
  27. next = self.cards_held.pop(random.randint(0,len(self.cards_held)-1))
  28. return next
  29.  
  30. def pickup(self,new_card):
  31. if len(self.cards_held) <= self.max:
  32. self.cards_held.append(new_card)
  33. return 0
  34. else:
  35. return -1
  36.  
  37. my_deck = Deck(52)
  38. print(my_deck.suit_list)
  39. print(my_deck.max)
  40. print(my_deck.cards_held)
  41.  
  42. first_hand = Deck(5)
  43. second_hand = Deck(5)
  44. first_hand.pickup(my_deck.draw())
  45. print(first_hand.cards_held)
  46.  
  47. sys.exit(0)
Add Comment
Please, Sign In to add comment