Move *.py into new pbot package.
[poker.git] / pbot / tournament.py
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