Run internal tests with
- nosetests --with-doctest --doctest-test *.py
+ nosetests --with-doctest --doctest-test pbot pbotlib
Profile with
-#!/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__':
--- /dev/null
+"""Define a framework for poker tournaments.
+"""
"""Assorted useful combinatorics.
"""
-from __future__ import generators
-
def xunique_combinations(items, n):
"""Iterate through unordered, length `n` subsets of `items`.
"""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']
import sys
import subprocess
-from deck import pp_hand, SevenChooseFiveHand
+from .deck import pp_hand, SevenChooseFiveHand
class IllegalBet (ValueError):
--- /dev/null
+"""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