Guest User

Untitled

a guest
Dec 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. class deck:
  2. card_type=['Hearts ','Diamonds','Spades','Clubs']
  3. card_rank=[2,3,4,5,6,7,8,9,10,'A','J','Q','K']
  4. full_deck=[]
  5.  
  6. def build_deck(self):
  7. single={}
  8. for card in self.card_type:
  9. for n in self.card_rank:
  10. single={n: card}
  11. self.full_deck.append(single)
  12. shuffle(self.full_deck)
  13.  
  14.  
  15. def reshuffle (self):
  16. print('Re-shuffling again!')
  17. shuffle(self.full_deck)
  18.  
  19.  
  20. def choose_card(self):
  21. chosen=choice(self.full_deck)
  22. the_index= self.full_deck.index(chosen)
  23. self.full_deck.pop(the_index)
  24.  
  25. return chosen
  26.  
  27. def pick_hand(self, number_of_cards):
  28. hand=[]
  29. new_card={}
  30.  
  31. for i in range(number_of_cards):
  32. new_card = self.choose_card()
  33. hand.append(new_card)
  34.  
  35. return hand
  36.  
  37. from classes import deck
  38.  
  39. deck1= deck()
  40. deck1.build_deck()
  41. my_hand=deck1.pick_hand(3)
  42. compu_hand=deck1.pick_hand(3)
  43.  
  44. export class deck {
  45.  
  46. single_card: {
  47. cType: string;
  48. cNumber: any;
  49. };
  50.  
  51. fullDeck: any[] = [];
  52. card_type=['Hearts ','Diamonds','Spades','Clubs'];
  53. card_rank=[2,3,4,5,6,7,8,9,10,'A','J','Q','K'];
  54.  
  55. shuffle() {
  56. let counter = this.fullDeck.length;
  57.  
  58. // While there are elements in the array
  59. while (counter > 0) {
  60. // Pick a random index
  61. let index = Math.floor(Math.random() * counter);
  62.  
  63. // Decrease counter by 1
  64. counter--;
  65.  
  66. // And swap the last element with it
  67. let temp = this.fullDeck[counter];
  68. this.fullDeck[counter] = this.fullDeck[index];
  69. this.fullDeck[index] = temp;
  70. }
  71.  
  72. // return this.fullDeck;
  73. }
  74.  
  75.  
  76. buildDeck (){
  77.  
  78. for (let t in this.card_type) {
  79. for ( let n in this.card_rank) {
  80. this.single_card.cType = this.card_type[t];
  81. this.single_card.cNumber = this.card_rank[n];
  82. this.fullDeck.push(this.single_card);
  83. console.log(this.single_card);
  84. }
  85. }
  86. // this.shuffle()
  87.  
  88. }
  89.  
  90. }
  91.  
  92. import {deck} from './myclasses'
  93.  
  94. $(document).ready (function(){
  95. let deck1= new deck;
  96. deck1.buildDeck();
  97. });
Add Comment
Please, Sign In to add comment