Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class deck:
- card_type=['Hearts ','Diamonds','Spades','Clubs']
- card_rank=[2,3,4,5,6,7,8,9,10,'A','J','Q','K']
- full_deck=[]
- def build_deck(self):
- single={}
- for card in self.card_type:
- for n in self.card_rank:
- single={n: card}
- self.full_deck.append(single)
- shuffle(self.full_deck)
- def reshuffle (self):
- print('Re-shuffling again!')
- shuffle(self.full_deck)
- def choose_card(self):
- chosen=choice(self.full_deck)
- the_index= self.full_deck.index(chosen)
- self.full_deck.pop(the_index)
- return chosen
- def pick_hand(self, number_of_cards):
- hand=[]
- new_card={}
- for i in range(number_of_cards):
- new_card = self.choose_card()
- hand.append(new_card)
- return hand
- from classes import deck
- deck1= deck()
- deck1.build_deck()
- my_hand=deck1.pick_hand(3)
- compu_hand=deck1.pick_hand(3)
- export class deck {
- single_card: {
- cType: string;
- cNumber: any;
- };
- fullDeck: any[] = [];
- card_type=['Hearts ','Diamonds','Spades','Clubs'];
- card_rank=[2,3,4,5,6,7,8,9,10,'A','J','Q','K'];
- shuffle() {
- let counter = this.fullDeck.length;
- // While there are elements in the array
- while (counter > 0) {
- // Pick a random index
- let index = Math.floor(Math.random() * counter);
- // Decrease counter by 1
- counter--;
- // And swap the last element with it
- let temp = this.fullDeck[counter];
- this.fullDeck[counter] = this.fullDeck[index];
- this.fullDeck[index] = temp;
- }
- // return this.fullDeck;
- }
- buildDeck (){
- for (let t in this.card_type) {
- for ( let n in this.card_rank) {
- this.single_card.cType = this.card_type[t];
- this.single_card.cNumber = this.card_rank[n];
- this.fullDeck.push(this.single_card);
- console.log(this.single_card);
- }
- }
- // this.shuffle()
- }
- }
- import {deck} from './myclasses'
- $(document).ready (function(){
- let deck1= new deck;
- deck1.buildDeck();
- });
Add Comment
Please, Sign In to add comment