Mostly working, also added a TODO at the top.

This commit is contained in:
Jeremy Fincher 2004-10-15 16:24:09 +00:00
parent 322143f2bd
commit 2f7ed33f3f
1 changed files with 32 additions and 17 deletions

View File

@ -37,6 +37,19 @@ __revision__ = "$Id$"
__author__ = supybot.authors.jemfinch __author__ = supybot.authors.jemfinch
__contributors__ = {} __contributors__ = {}
###
# TODO:
#
# Betting timeouts.
# Change the "bet" command to allow saying a specific amount to bet to.
# Change the stack command to see another person's stack.
# Keep a bankroll in the users registry.
# Allow the "sit" command to have specified a stack size, subtracting it from
# the bankroll.
# Write a command to allow Owner users to give a person money.
# Re-expand the commands using forwarder so they can have better help.
###
import sets import sets
import random import random
import operator import operator
@ -115,13 +128,13 @@ class Table(object):
s = self._color(s) s = self._color(s)
self.irc.reply(s, to=users[player.user], private=True) self.irc.reply(s, to=users[player.user], private=True)
def error(self, player, s): def error(self, s):
s = self._color('%s: %s' % (player.nick(), s)) s = self._color('%s: %s' % (self.irc.msg.nick, s))
self.irc.reply(s) self.irc.reply(s, to=self.channel)
def sit(self, player): def sit(self, player):
if player in self.players: if player in self.players:
self.error(player, 'You\'re already seated.') self.error('You\'re already seated.')
return return
self.waitingToJoin.append(player) self.waitingToJoin.append(player)
self.irc.reply('You will be dealt in when the next hand begins.') self.irc.reply('You will be dealt in when the next hand begins.')
@ -133,10 +146,11 @@ class Table(object):
elif player in self.waitingToJoin: elif player in self.waitingToJoin:
self.waitingToJoin.remove(player) self.waitingToJoin.remove(player)
else: else:
self.error(player, 'You aren\'t currently seated.') self.error('You aren\'t currently seated.')
def deal(self, startingPlayer): def deal(self, startingPlayer):
# Ignore player. # Ignore player.
self.color = self.colors.next()
self.blind = conf.get(conf.supybot.plugins.Holdem.blind, self.channel) self.blind = conf.get(conf.supybot.plugins.Holdem.blind, self.channel)
if self.waitingToJoin: if self.waitingToJoin:
self.players.extend(self.waitingToJoin) self.players.extend(self.waitingToJoin)
@ -166,7 +180,6 @@ class Table(object):
self._waitingOn = self.button self._waitingOn = self.button
self.deck = poker.deck[:] self.deck = poker.deck[:]
random.shuffle(self.deck) random.shuffle(self.deck)
self.color = self.colors.next()
for player in self.players: for player in self.players:
self.hands[player] = [self.deck.pop()] self.hands[player] = [self.deck.pop()]
for player in self.players: for player in self.players:
@ -312,7 +325,7 @@ class Table(object):
def checkNoCurrentBet(self): def checkNoCurrentBet(self):
if self.currentBet: if self.currentBet:
self.error(player, 'There\'s a bet of %s, you must call it, ' self.error('There\'s a bet of %s, you must call it, '
'raise it, or fold.' % self.currentBet) 'raise it, or fold.' % self.currentBet)
return True return True
return False return False
@ -321,7 +334,7 @@ class Table(object):
try: try:
self.private(player, 'Your hand is %s.' % self.hands[player]) self.private(player, 'Your hand is %s.' % self.hands[player])
except KeyError: except KeyError:
self.error(player, 'You\'re not dealt in right now.') self.error('You\'re not dealt in right now.')
def table(self, player): def table(self, player):
self.public('The table shows %s.' % self.tableCards) self.public('The table shows %s.' % self.tableCards)
@ -338,8 +351,9 @@ class Table(object):
def check(self, player): def check(self, player):
if self.checkWrongPlayer(player): if self.checkWrongPlayer(player):
return return
if self.checkNoCurrentBet(): if self.currentBet and self.currentBets[player] < self.currentBet:
return self.error('There is a bet of %s, you must call it, raise it, '
'or fold.' % self.currentBet)
self.public('%s checks.' % player.nick()) self.public('%s checks.' % player.nick())
self.couldBet[player] = True self.couldBet[player] = True
self.checkEndOfRound() self.checkEndOfRound()
@ -355,7 +369,8 @@ class Table(object):
def call(self, player): def call(self, player):
if self.checkWrongPlayer(player): if self.checkWrongPlayer(player):
return return
bet = self.addCurrentBet(player, min(self.currentBet, player.stack)) toCall = self.currentBet - self.currentBets[player]
bet = self.addCurrentBet(player, min(toCall, player.stack))
self.public('%s calls %s.' % (player.nick(), bet)) self.public('%s calls %s.' % (player.nick(), bet))
self.checkEndOfRound() self.checkEndOfRound()
@ -365,12 +380,12 @@ class Table(object):
if self.checkNoCurrentBet(): if self.checkNoCurrentBet():
return return
if amount > player.stack: if amount > player.stack:
self.error(player, 'You only have %s in your stack, you can\'t ' self.error('You only have %s in your stack, you can\'t '
'bet that much. Perhaps you should use the allin ' 'bet that much. Perhaps you should use the allin '
'command.' % player.stack) 'command.' % player.stack)
return return
if amount < 2*self.blind: if amount < 2*self.blind:
self.error(player, 'You must bet at least the big blind.') self.error('You must bet at least the big blind.')
return return
bet = self.addCurrentBet(player, amount) bet = self.addCurrentBet(player, amount)
self.public('%s bets %s.' % (player.nick(), bet)) self.public('%s bets %s.' % (player.nick(), bet))
@ -380,11 +395,11 @@ class Table(object):
if self.checkWrongPlayer(player): if self.checkWrongPlayer(player):
return return
if not self.currentBet: if not self.currentBet:
self.error(player, 'You can\'t raise when there\'s no current ' self.error('You can\'t raise when there\'s no current '
'bet. Perhaps you should use the bet command.') 'bet. Perhaps you should use the bet command.')
return return
if amount < 2*self.currentBet: if amount < self.currentBet:
self.error(player, 'You can\'t raise less than twice the current ' self.error('You can\'t raise by less than the current '
'bet of %s.' % self.currentBet) 'bet of %s.' % self.currentBet)
return return
totalRaise = amount + self.currentBet - self.currentBets[player] totalRaise = amount + self.currentBet - self.currentBets[player]