From: W. Trevor King Date: Tue, 7 Dec 2010 18:58:25 +0000 (-0500) Subject: Move *.py into new pbot package. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=443778734ddf76ce2d7de93b8d2ec7928e600c56;p=poker.git Move *.py into new pbot package. --- diff --git a/README b/README index 83c157f..7dfd38f 100644 --- 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 3a7ec5b..b824e33 100755 --- 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 index 0000000..b66c5cd --- /dev/null +++ b/pbot/__init__.py @@ -0,0 +1,2 @@ +"""Define a framework for poker tournaments. +""" diff --git a/combinations.py b/pbot/combinations.py similarity index 92% rename from combinations.py rename to pbot/combinations.py index 50b7bab..0e11775 100644 --- a/combinations.py +++ b/pbot/combinations.py @@ -1,8 +1,6 @@ """Assorted useful combinatorics. """ -from __future__ import generators - def xunique_combinations(items, n): """Iterate through unordered, length `n` subsets of `items`. diff --git a/deck.py b/pbot/deck.py similarity index 99% rename from deck.py rename to pbot/deck.py index 42d3076..d7cc3cc 100644 --- a/deck.py +++ b/pbot/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'] diff --git a/table.py b/pbot/table.py similarity index 99% rename from table.py rename to pbot/table.py index c47bb42..5188b6b 100644 --- a/table.py +++ b/pbot/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 index 0000000..3a8f6af --- /dev/null +++ b/pbot/tournament.py @@ -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