Move *.py into new pbot package.
authorW. Trevor King <wking@drexel.edu>
Tue, 7 Dec 2010 18:58:25 +0000 (13:58 -0500)
committerW. Trevor King <wking@drexel.edu>
Tue, 7 Dec 2010 18:58:25 +0000 (13:58 -0500)
README
pbot.py
pbot/__init__.py [new file with mode: 0644]
pbot/combinations.py [moved from combinations.py with 92% similarity]
pbot/deck.py [moved from deck.py with 99% similarity]
pbot/table.py [moved from table.py with 99% similarity]
pbot/tournament.py [new file with mode: 0644]

diff --git a/README b/README
index 83c157f95133b500840bf64326b292801a7ab551..7dfd38fad7b3a36c59f44f3ed3d8ae33e254bf05 100644 (file)
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ Multiplayer poker game.  Example usage:
 
 Run internal tests with
 
-  nosetests --with-doctest --doctest-test *.py
+  nosetests --with-doctest --doctest-test pbot pbotlib
 
 Profile with
 
diff --git a/pbot.py b/pbot.py
index 3a7ec5be12b9aedf3da18eaf38087a1bae2d430d..b824e3364cbe0fc735775d789eb5d7f264dd03fa 100755 (executable)
--- a/pbot.py
+++ b/pbot.py
@@ -1,31 +1,10 @@
-#!/usr/bin/python
+#!/usr/bin/env python
 
 """Run a poker championship.
 """
 
-from table import Player, Blinds, Table
-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=new_deck(), players=players, blinds=blinds,
-                      verbose=verbose)
-        while len(table.players) > 1 and table.hand_count < hand_limit:
-            table.play_round()
-            # keep bots up to date, so they can think in parallel
-            for player in players:
-                if player.brain:
-                    player.log_flush(table.log)
-        if len(table.players) == 1:
-            print "INFO WINNER: Player %s" % table.players[0]
-        else:
-            assert table.hand_count >= hand_limit
-            print "INFO Time expired"
-            for player in table.players:
-                print "INFO Tie: Player %s" % player
+from pbot.table import Player, Blinds
+from pbot.tournament import run
 
 
 if __name__ == '__main__':
diff --git a/pbot/__init__.py b/pbot/__init__.py
new file mode 100644 (file)
index 0000000..b66c5cd
--- /dev/null
@@ -0,0 +1,2 @@
+"""Define a framework for poker tournaments.
+"""
similarity index 92%
rename from combinations.py
rename to pbot/combinations.py
index 50b7bab397d36e98722a7fd8e80f42a5701faacd..0e11775661e1ef612662981627cf6e6d5799dffc 100644 (file)
@@ -1,8 +1,6 @@
 """Assorted useful combinatorics.
 """
 
-from __future__ import generators
-
 
 def xunique_combinations(items, n):
     """Iterate through unordered, length `n` subsets of `items`.
similarity index 99%
rename from deck.py
rename to pbot/deck.py
index 42d3076575aef3639185a69000de80c40fb746b2..d7cc3cc00c2ca761a6e1de455b35718ae5ad1728 100644 (file)
--- a/deck.py
@@ -1,7 +1,7 @@
 """Define a deck of cards, single-player scoring rules, and pretty-printing.
 """
 
-from combinations import xunique_combinations
+from .combinations import xunique_combinations
 
 
 SUITS = ['spades', 'hearts', 'diamonds', 'clubs']
similarity index 99%
rename from table.py
rename to pbot/table.py
index c47bb42b076228929a9e8519b1dc406800719f91..5188b6b67a0b52121b4a2f0bbc305a40b7d95819 100644 (file)
--- a/table.py
@@ -6,7 +6,7 @@ import random
 import sys
 import subprocess
 
-from deck import pp_hand, SevenChooseFiveHand
+from .deck import pp_hand, SevenChooseFiveHand
 
 
 class IllegalBet (ValueError):
diff --git a/pbot/tournament.py b/pbot/tournament.py
new file mode 100644 (file)
index 0000000..3a8f6af
--- /dev/null
@@ -0,0 +1,26 @@
+"""Define a poker championship.
+"""
+
+from .deck import new_deck
+from .table import Table
+
+
+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=new_deck(), players=players, blinds=blinds,
+                      verbose=verbose)
+        while len(table.players) > 1 and table.hand_count < hand_limit:
+            table.play_round()
+            # keep bots up to date, so they can think in parallel
+            for player in players:
+                if player.brain:
+                    player.log_flush(table.log)
+        if len(table.players) == 1:
+            print "INFO WINNER: Player %s" % table.players[0]
+        else:
+            assert table.hand_count >= hand_limit
+            print "INFO Time expired"
+            for player in table.players:
+                print "INFO Tie: Player %s" % player