From: <umg...@us...> - 2007-06-13 15:11:44
|
Revision: 415 http://svn.sourceforge.net/pybridge/?rev=415&view=rev Author: umgangee Date: 2007-06-13 08:11:39 -0700 (Wed, 13 Jun 2007) Log Message: ----------- Add a isNextGameReady() method to BridgeGame, add startNextGame() to BridgePlayer. Modified Paths: -------------- trunk/pybridge/pybridge/bridge/game.py trunk/pybridge/pybridge/interfaces/game.py Modified: trunk/pybridge/pybridge/bridge/game.py =================================================================== --- trunk/pybridge/pybridge/bridge/game.py 2007-06-11 13:10:16 UTC (rev 414) +++ trunk/pybridge/pybridge/bridge/game.py 2007-06-13 15:11:39 UTC (rev 415) @@ -26,6 +26,7 @@ from bidding import Bidding from board import Board from playing import Playing +from scoring import scoreDuplicate from call import Bid, Pass, Double, Redouble from card import Card @@ -72,8 +73,8 @@ def start(self, board=None): - if self.inProgress(): - raise GameError, "Game in progress" + if not self.isNextGameReady(): + raise GameError, "Not ready to start game" if board: # Use specified board. self.board = board @@ -103,6 +104,10 @@ return False + def isNextGameReady(self): + return (not self.inProgress()) and len(self.players) == 4 + + def getState(self): state = {} @@ -374,7 +379,7 @@ result = {'contract' : contract, 'tricksMade' : tricksMade, 'vulnerable' : vulnerable, } - return self.scoring(result) + return scoreDuplicate(result) @@ -384,7 +389,7 @@ def __init__(self, game): - self.__game = game # Provide access to game only through this object. + self.__game = game # Access to game is private to this object. def getHand(self): @@ -393,16 +398,21 @@ def makeCall(self, call): - return self.__game.makeCall(call, player=self) + try: + return self.__game.makeCall(call, player=self) + except TypeError, e: + raise GameError, e def playCard(self, card): - # TODO: need try/except block on each. - return self.__game.playCard(card, player=self) + try: + return self.__game.playCard(card, player=self) + except TypeError, e: + raise GameError, e - def nextGame(self): - pass + def startNextGame(self): + self.__game.start() # Raises GameError if not ready to start next game. # Aliases for remote-callable methods. @@ -410,4 +420,5 @@ remote_getHand = getHand remote_makeCall = makeCall remote_playCard = playCard + remote_startNextGame = startNextGame Modified: trunk/pybridge/pybridge/interfaces/game.py =================================================================== --- trunk/pybridge/pybridge/interfaces/game.py 2007-06-11 13:10:16 UTC (rev 414) +++ trunk/pybridge/pybridge/interfaces/game.py 2007-06-13 15:11:39 UTC (rev 415) @@ -84,6 +84,13 @@ """ + def isNextGameReady(self): + """Indicates whether the next game is ready to start. + + @return: True if next game is ready to start, False otherwise. + """ + + class ICardGame(IGame): """ICardGame defines methods specific to card games. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |