本文整理汇总了Python中GameState.GameState.addResource方法的典型用法代码示例。如果您正苦于以下问题:Python GameState.addResource方法的具体用法?Python GameState.addResource怎么用?Python GameState.addResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GameState.GameState
的用法示例。
在下文中一共展示了GameState.addResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTest
# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import addResource [as 别名]
def makeTest():
g = GameState(2)
g.phase = "buildroad"
g.addBuilding(0, 'settlement', 33)
g.addRoad(0, 33, 34)
g.addRoad(0, 34, 35)
g.addBuilding(1, 'settlement', 28)
g.addRoad(1, 28, 29)
g.addRoad(1, 29, 30)
g.addResource(0, 'ore', 2)
g.addResource(1, 'brick', 3)
g.updateScore(0)
g.updateScore(1)
return g
示例2: Controller
# 需要导入模块: from GameState import GameState [as 别名]
# 或者: from GameState.GameState import addResource [as 别名]
class Controller(object):
def __init__(self, players, updater=None):
self.players = players
self.nplayers = len(players)
self.state = GameState(self.nplayers)
self.validator = Validator(self.state)
self.logger = logging.getLogger(__name__)
if updater is not None:
self.update = ViewUpdater()
else:
self.update = updater
self.delay = 0.5
self.stalematecond = 2000
def play(self):
self.setup()
while not self.gameEnded():
currTime = int(round(time.time() * 1000))
self.roll() #resource/bandit
self.takeTurn() #actions
self.nextPlayerTurn()
while int(round(time.time() * 1000)) < currTime + 1000:
pass
self.end()
def end(self):
#tell everyone the game is over
self.updateView()
for player in self.players:
player.getMove(self.state)
def setup(self):
# Send initial state for display
self.update.sendTiles(self.state)
#Decide first player randomly
self.state.turn = random.randrange(0,self.nplayers)
builtcount = 0
turnorder = []
for i in range(0, self.nplayers):
turnorder.append((self.state.turn + i) % self.nplayers)
turnorderbckwd = copy.deepcopy(turnorder)
turnorderbckwd.reverse()
turnorder += turnorderbckwd
print "Turnorder: %s" %(str(turnorder))
for i in range(0, self.nplayers*2):
self.state.turn = turnorder[i]
self.state.phase = "buildsettle"
self.updateView()
bs_move = self.getValidMove(self.state.turn)
self.doMove(bs_move)
self.state.phase = "buildroad"
self.updateView()
move = self.getValidMove(self.state.turn)
self.doMove(move)
#if this is second settle built do resource init
if builtcount >= self.nplayers:
for rec in self.state.getSurroundingResources(bs_move.location):
if rec != 'desert':
self.state.addResource(self.state.turn, rec, 1)
#initial resource allocation
self.state.phase = 'standard'
def nextPlayerTurn(self):
self.state.turn = (self.state.turn + 1) % self.nplayers
def takeTurn(self):
#loop action (trade, build, play, buy) until turn ended
while not self.turnEnded():
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:
#.........这里部分代码省略.........