deck.DECK -> deck.new_deck() to avoid globals (better for multi-table play).
[poker.git] / deck.py
diff --git a/deck.py b/deck.py
index 364f0e743d39a02dda7434a8344d3162fcdb0906..42d3076575aef3639185a69000de80c40fb746b2 100644 (file)
--- a/deck.py
+++ b/deck.py
@@ -12,18 +12,25 @@ FACE_CARDS = ['ten', 'jack', 'queen', 'king', 'ace']
 """Ordered list of face cards.
 """
 
-DECK = [(c/4, c%4) for c in range(52)]
-"""Cards in the deck are stored as (n,m), where `n` is the rank number
-`n=[0,12]`, and `m` is the suit `m=[0,3]`.
+def new_deck():
+    """Generate a new deck.
 
-Examples: 
- (0,1)  is a two of hearts, 
- (11,0) is a king of spades,
- (12,3) is an ace of clubs
+    Cards in the deck are stored as `(n,m)`, where `n` is the rank
+    number `n=[0,12]`, and `m` is the suit `m=[0,3]`.
 
->>> DECK[:5]
-"""
+    Examples:
 
+    * `(0,1)`  is a two of hearts, 
+    * `(11,0)` is a king of spades,
+    * `(12,3)` is an ace of clubs
+    
+    >>> deck = new_deck()
+    >>> deck[:6]
+    [(0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1)]
+    >>> [pp_card(c) for c in deck[:6]]
+    ['2s', '2h', '2d', '2c', '3s', '3h']
+    """
+    return [(c/4, c%4) for c in range(52)]
 
 def pp_card(card):
     """Pretty-print a card.