From: W. Trevor King Date: Tue, 7 Dec 2010 18:37:41 +0000 (-0500) Subject: deck.DECK -> deck.new_deck() to avoid globals (better for multi-table play). X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d61ac107b8d3eb7742d739edcda82abdad8a1938;p=poker.git deck.DECK -> deck.new_deck() to avoid globals (better for multi-table play). --- diff --git a/deck.py b/deck.py index 364f0e7..42d3076 100644 --- 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. diff --git a/pbot.py b/pbot.py index 0e7f32e..3a7ec5b 100755 --- a/pbot.py +++ b/pbot.py @@ -4,14 +4,14 @@ """ from table import Player, Blinds, Table -from deck import DECK +from deck import new_deck def run(players, blinds, start_stack, hand_limit, tournaments, verbose=False): for n in xrange(tournaments): for player in players: player.cash = start_stack - table = Table(deck=DECK, players=players, blinds=blinds, + table = Table(deck=new_deck(), players=players, blinds=blinds, verbose=verbose) while len(table.players) > 1 and table.hand_count < hand_limit: table.play_round()