本文整理汇总了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 )