本文整理匯總了Python中GameState.addHand方法的典型用法代碼示例。如果您正苦於以下問題:Python GameState.addHand方法的具體用法?Python GameState.addHand怎麽用?Python GameState.addHand使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類GameState
的用法示例。
在下文中一共展示了GameState.addHand方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: players
# 需要導入模塊: import GameState [as 別名]
# 或者: from GameState import addHand [as 別名]
#.........這裏部分代碼省略.........
self.broadcastMessage('BID_ANNOUNCE %d %d' % (playerNum, bid) )
break
else:
self.players[self.dealer].sendMessage('BADBID %d' % bid)
#
# play a hand
#
def playHand( self ):
hand = HandState(len(self.players), self.trickNums[self.handNum],
self.trump, self.dealer)
for i in range(len(self.players)):
cards = []
for c in range(52):
if self.players[i].hasCard(c):
cards.append(c)
hand.setHand(i, cards)
hand.setBid(i, self.players[i].bid)
playerNum = self.nextPlayer(self.dealer)
for i in range(self.trickNums[self.handNum]):
winnerNum, trick = self.playTrick(playerNum)
hand.addTrick(trick)
self.players[winnerNum].wonTrick()
playerNum = winnerNum
self.broadcastMessage( 'TRICK_WINNER %d' % winnerNum)
## if self.trump == -1:
## trumpSuite = None
## else:
## trumpSuite = cardSuit(self.trump)
for i in range(len(self.players)):
hand.setTricksMade(i, self.players[i].numTricks)
self.gameState.addHand(hand)
xmlFile = open(self.xmlFileName, "w")
xmlFile.write( self.gameState.generateXML() )
xmlFile.close()
deltas = self.updateScores()
message = 'END_HAND '
for delta in deltas:
message = message + '%d ' % delta
self.broadcastMessage(message)
#
# play a trick of a hand
# Parameter:
# leadPlayerNum - index of player to lead
#
def playTrick(self, leadPlayerNum):
playerNum = leadPlayerNum
firstCard = -1
cards = []
trick = TrickState()
for i in range(self.numPlayers):
player = self.players[playerNum]
cardOK = 0
while not cardOK:
card = self.playCard(player, firstCard)
cardOK = card >= 0
if firstCard == -1:
firstCard = card
self.broadcastMessage('CARD_PLAYED %d %d' % (playerNum, card))
cards.append( (playerNum, card) )
trick.addCard( playerNum, card )