-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshoe.py
55 lines (42 loc) · 1.31 KB
/
shoe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#encoding: utf8
__author__ = 'Diogo Gomes'
__email__ = '[email protected]'
__license__ = "GPL"
__version__ = "0.1"
from card import Card
import random
class Shoe(object):
#Represents one or more decks of cards use to
#take cards for players and dealer
def __init__(self, number_decks=1):
self.cards = []
for i in range(number_decks):
self.cards += [Card(suit, rank) for suit in range(4) for rank in range(1,14)]
def __str__(self):
res = []
for card in self.cards:
res.append(str(card))
return '\n'.join(res)
def pop_card(self, i=-1):
"""Removes and returns a card from the deck.
i: index of the card to pop; by default, pops the last card.
"""
return self.cards.pop(i)
def shuffle(self):
"""Shuffles the cards in this deck."""
random.shuffle(self.cards)
def sort(self):
"""Sorts the cards in ascending order."""
self.cards.sort()
def deal_cards(self, num):
"""Moves the given number of cards from the deck
num: integer number of cards to move
"""
deal = []
for i in range(num):
deal.append(self.pop_card())
return deal
if __name__ == '__main__':
shoe = Shoe()
shoe.shuffle()
print(shoe.deal_cards(2))