本文整理汇总了Python中GameState.GameState.getLongestRoads方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.getLongestRoads方法的具体用法?Python GameState.getLongestRoads怎么用?Python GameState.getLongestRoads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameState.GameState
的用法示例。
在下文中一共展示了GameState.getLongestRoads方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import getLongestRoads [as 别名]
#.........这里部分代码省略.........
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]
# Davis says to make code concise, use empty list as test for this
# if statement otherwise he will hit irakli. I like irakli, so this list
# is now the test for this if statement.
if adjplayers:
self.state.phaseinfo = adjplayers
self.state.phase = 'chooseplayer'
move = self.getValidMove(self.state.turn)
self.doMove(move)
def getValidMove(self, player):
self.updateView()
move = self.players[player].getMove(self.state)
# loop until valid move receied
while not self.isValid(move):
self.logger.error("INVALID MOVE RECEIVED: Player %d, Move: %s, Phase %s" % (player,str(move), self.state.phase))
move = self.players[player].getMove(self.state)
return move
def isValid(self, move):
return self.validator.validateMove(move)
def doMove(self, move):
if move.typ == 'build':
if move.structure == 'road':
# 1 brick, 1 wood
self.state.addRoad(move.playerid, move.location[0], move.location[1])
if self.state.phase != 'buildroad':
self.state.removeResource(move.playerid, 'brick', 1)
self.state.removeResource(move.playerid, 'wood', 1)
else:
if move.structure == 'settlement':
# 1 brick, 1 wood, 1 wheat, 1 sheep settlement
if self.state.phase != 'buildsettle':
self.state.removeResource(move.playerid, 'wood', 1)
self.state.removeResource(move.playerid, 'wheat', 1)
self.state.removeResource(move.playerid, 'brick', 1)
self.state.removeResource(move.playerid, 'sheep', 1)
elif move.structure == 'city':
# 2 wheat, 3 ore city
self.state.removeResource(move.playerid, 'wheat', 2)
self.state.removeResource(move.playerid, 'ore', 3)
else:
self.logger.error("Unrecognized build type %s" % move.structure)
self.state.addBuilding(move.playerid, move.structure, move.location)
# check to see if building changed longest road count
l = self.state.getLongestRoads()
currentlongest = 0
if self.state.longestroad is not None:
currentlongest = l[self.state.longestroad]
newlongestid = self.state.longestroad
for i in xrange(0, self.nplayers):
if l[i] > currentlongest:
newlongestid = i
currentlongest = l[i]
#need to check if road breaking resulted in a tie
if newlongestid != self.state.longestroad:
if currentlongest<5:
self.state.longestroad = None
elif l.count(currentlongest) != 1:
self.state.longestroad = None
else:
self.state.longestroad = newlongestid
# update remaining building count
self.state.updateRemaining(move.playerid)
#self.updateView()
elif move.typ == 'trade':
self.logger.error("TRADE MOVE NOT SUPPORTED")
elif move.typ == 'navaltrade':
self.state.removeResource(move.playerid,move.offer,4)
self.state.addResource(move.playerid,move.want,1)
elif move.typ == 'robber':
#set robber tile
self.state.setRobberTile(move.location)
elif move.typ == 'takecard':
# Remove card from target, add to initiator
rectoremove = self.state.getRandomResource(move.target)
self.state.removeResource(move.target, rectoremove, 1)
self.state.addResource(move.playerid, rectoremove, 1)
#self.updateView()
elif move.typ == 'playcard':
#yell when things are important
self.logger.error("PLAY CARD MOVE NOT SUPPORTED")
elif move.typ == 'discard':
# Need to add ability to discard more than one at a time
self.state.removeResource(move.playerid, move.card, 1)
elif move.typ == 'endturn':
self.state.phase = 'endturn'