当前位置: 首页>>代码示例>>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;未经允许,请勿转载。