deck.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. '''
  2. * This file is part of the Chinchon (https://notabug.org/alkeon/chinchon.
  3. * Copyright (c) 2020 Alejandro "alkeon" Castilla.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, version 3.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. '''
  17. from card import Card
  18. from random import shuffle
  19. class Deck:
  20. def __init__(self, provided_list = list()):
  21. if(len(provided_list) < 1):
  22. self.cards = list()
  23. temporal_deck = sum(list(map( lambda n: [str(n)+'🗡',str(n)+'🏏',str(n)+'🥇',str(n)+'🍷'], [1,2,3,4,5,6,7,8,9,10,11,12])),[])
  24. shuffle(temporal_deck)
  25. i = 0
  26. while(i < len(temporal_deck)):
  27. card = temporal_deck[i]
  28. self.cards.append(Card(int(card[:-1]), card[-1:]))
  29. i += 1
  30. else:
  31. self.cards = provided_list
  32. def insert(self,position, card):
  33. self.cards.insert(position, card)
  34. def top(self):
  35. return self.cards[0]
  36. def get(self, position):
  37. return self.cards[position]
  38. def add_cards(self, deck):
  39. self.cards += deck.copy()
  40. def get_top_and_pop(self):
  41. card = self.cards[0]
  42. self.cards.pop(0)
  43. return card
  44. def pop(self, position):
  45. self.cards.pop(position)
  46. def shuffle(self):
  47. shuffle(self.cards)
  48. def size(self):
  49. return len(self.cards)
  50. def clear(self):
  51. self.cards.clear()
  52. def get_cards(self):
  53. return self.cards.copy()
  54. def ___str__(self):
  55. i = 0
  56. string_result = string()
  57. while(i < self.size()):
  58. string_result += str(i) + " " + self.get(i)
  59. i += 1
  60. return string_result