cards.py 955 B

123456789101112131415161718192021222324252627282930313233343536
  1. import random
  2. suits = ["hearts", "spades", "clubs", "diamonds"]
  3. denoms = ["ace", "king", "queen", "jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"]
  4. class Card(object):
  5. def __init__(self, uid, suit, denom):
  6. self.uid = uid
  7. self.suit = suit
  8. self.denom = denom
  9. def __eq__(self, other):
  10. if isinstance(other, self.__class__):
  11. return self.__dict__ == other.__dict__
  12. elif isinstance(other, dict):
  13. return self.__dict__ == other
  14. else:
  15. return False
  16. def __ne__(self, other):
  17. return not self.__eq__(other)
  18. def shuffle(number_of_decks):
  19. deck = [(x, y) for x in suits for y in denoms] + [(None, "joker") for _ in range(3)]
  20. stock = deck * number_of_decks
  21. stock = zip(stock, range(len(stock)))
  22. stock = [Card(uid, x, y) for ((x, y), uid) in stock]
  23. random.shuffle(stock)
  24. return stock
  25. if __name__ == "__main__":
  26. print(shuffle(2))