本文整理汇总了Python中GameState.GameState.countResources方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.countResources方法的具体用法?Python GameState.countResources怎么用?Python GameState.countResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameState.GameState
的用法示例。
在下文中一共展示了GameState.countResources方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import countResources [as 别名]
#.........这里部分代码省略.........
self.updateView()
move = self.getValidMove(self.state.turn)
self.doMove(move)
self.state.updateAllScores()
self.state.phase = 'standard'
self.state.numturns += 1
def updateView(self):
self.update.sendGameState(self.state)
def gameEnded(self):
if self.state.maxPlayerScore() >= 10:
self.state.phase = 'ended'
self.state.phaseinfo = 'won'
return True
elif self.state.numturns >= self.stalematecond:
self.state.phase = 'ended'
self.state.phaseinfo = 'stalemate'
return True
else:
return False
def turnEnded(self):
return self.state.phase == 'endturn'
def roll(self):
self.state.lastroll = random.randint(1,6) + random.randint(1,6)
#self.updateView()
if self.state.lastroll == 7:
turn = self.state.turn
#resource discard
for i in range(0, self.nplayers):
self.state.turn = i
nresources = self.state.countResources(i)
if nresources > 7:
reqresources = (nresources+1)/2
self.state.phase = "discard"
while nresources > reqresources:
# number you need to discard
self.state.phaseinfo = nresources - reqresources
# should we change whose turn it is in state?
move = self.getValidMove(i)
self.doMove(move)
nresources = self.state.countResources(i)
self.state.turn = turn
#robber movement
self.moveRobber()
else: #resource collection
for (r,p,b) in self.state.getBuildings(self.state.lastroll):
mult = 1 if b == 'settlement' else 2
self.state.addResource(p, r, mult)
#self.updateView()
self.state.phase = 'standard'
def moveRobber(self):
self.state.phase = 'moverobber'
move = self.getValidMove(self.state.turn)
self.doMove(move)
#list of playerid's next to robber
adjplayers = self.state.getAdjacentPlayers(self.state.getRobberTile())
if self.state.turn in adjplayers:
adjplayers.remove(self.state.turn)
#remove players who have no cards from adjacent list
for i in xrange(len(adjplayers) - 1, -1, -1):
if self.state.countResources(adjplayers[i]) == 0:
del adjplayers[i]