當前位置: 首頁>>代碼示例>>Python>>正文


Python Deck.hasNext方法代碼示例

本文整理匯總了Python中Deck.hasNext方法的典型用法代碼示例。如果您正苦於以下問題:Python Deck.hasNext方法的具體用法?Python Deck.hasNext怎麽用?Python Deck.hasNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Deck的用法示例。


在下文中一共展示了Deck.hasNext方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Game

# 需要導入模塊: import Deck [as 別名]
# 或者: from Deck import hasNext [as 別名]
class Game():
   def __init__(self, numPlayers, maxSimulationDepth):
      self._players = []
      self._currentPlayerIndex = 0
      self._deck = Deck()
      self._cardDrawManager = CardDrawManager(self)

      print "==========="
      self._deck.printCards()

      for playerIndex in range(numPlayers):
         player = Player(self, playerIndex)
         self._players.append(player)
         for drawIndex in range(InitialDrawCount):
            self._cardDrawManager.handleDrawFor(player)

      for player in self._players:
         print player
         print "============="

      self._progress = {}
      for suit in SUITS:
         self._progress[suit] = 0

      self._hintTokens = InitialHintTokens
      self._deathTokens = InitialDeathTokens
      self._maxSimulationDepth = maxSimulationDepth

   def deck(self):
      return self._deck

   def currentPlayerIndex(self):
      return self._currentPlayerIndex

   def iteratePlayerIndex(self):
      self._currentPlayerIndex += 1
      self._currentPlayerIndex %= len(self._players)

   def play(self):
      while self._deck.hasNext() and self._deathTokens > 0:
         self.doTurn()

      for i in range(len(self._players)):
         if self._deathTokens == 0:
            break
         self.doTurn()        

      if self._deathTokens == 0:
         print "Ended early because we fucked up."

      print self._progress

   def doTurn(self):
      simulation = Simulation(self, self._players[self._currentPlayerIndex])
      self.simulateSingleTurn(simulation)
      self.iteratePlayerIndex()

   def simulateSingleTurn(self, simulation):
      canPrint = simulation._depth == 0
      action, score = self._players[self._currentPlayerIndex].getActionForTurn(simulation)
      if canPrint:
         print "--------"
         print str.format("{} will do: {}. Score at depth: {}", self.currentPlayer(), action, score)
         self.printProgress()
      self.processAction(action, simulation.isSimulating())
      if canPrint:
         print str.format("Score after play: {}. Hint tokens: {}. Death Tokens: {}", self.score(None), self._hintTokens, self._deathTokens)
         print "--------"

      return score # Represents the best score at the deepest sim level.

   def processAction(self, action, isSimulating):
      if action.actionName() == "Hint":
         self.processHint(action)
      else:
         self.processBurnOrPlay(action, isSimulating)

   def processHint(self, hint):
      hint.player().receiveHint(hint)
      self._hintTokens -= 1

   def processBurnOrPlay(self, action, isSimulating):
      player = action.player()
      cardFact = action.cardFact()
      player.dropCard(cardFact)

      if action.actionName() == "Burn":
         self._hintTokens += 1
      else: # Play:
         card = cardFact.card()
         suit = card.suit()
         number = card.number()
         if self.progress(suit) == number - 1:
            self._progress[suit] = number  # :)
         else:
            self._deathTokens -= 1 # :(

      if not isSimulating:
         self._cardDrawManager.handleDrawFor(player)

#.........這裏部分代碼省略.........
開發者ID:astennent,項目名稱:hanabi-ai,代碼行數:103,代碼來源:Game.py


注:本文中的Deck.hasNext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。