本文整理汇总了Python中layout.getNumGhosts方法的典型用法代码示例。如果您正苦于以下问题:Python layout.getNumGhosts方法的具体用法?Python layout.getNumGhosts怎么用?Python layout.getNumGhosts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类layout
的用法示例。
在下文中一共展示了layout.getNumGhosts方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replayGame
# 需要导入模块: import layout [as 别名]
# 或者: from layout import getNumGhosts [as 别名]
def replayGame( layout, actions, display ):
import pacmanAgents, ghostAgents
rules = ClassicGameRules()
agents = [pacmanAgents.GreedyAgent()] + [ghostAgents.RandomGhost(i+1) for i in range(layout.getNumGhosts())]
game = rules.newGame( layout, agents[0], agents[1:], display )
state = game.state
display.initialize(state.data)
for action in actions:
# Execute the action
state = state.generateSuccessor( *action )
# Change the display
display.update( state.data )
# Allow for game specific conditions (winning, losing, etc.)
rules.process(state, game)
display.finish()
示例2: replayGame
# 需要导入模块: import layout [as 别名]
# 或者: from layout import getNumGhosts [as 别名]
def replayGame( layout, actions, display ):
import pacmanAgents, ghostAgents
rules = ClassicGameRules()
agents = [pacmanAgents.GreedyAgent()] + [ghostAgents.RandomGhost(i+1) for i in range(layout.getNumGhosts())]
game = rules.newGame( layout, agents[0], agents[1:], display )
state = game.state
display.initialize(state.data)
for action in actions:
# Execute the action
state = state.generateSuccessor( *action )
# Change the display
display.update( state.data )
# Allow for game specific conditions (winning, losing, etc.)
rules.process(state, game)
display.finish()
示例3: newGame
# 需要导入模块: import layout [as 别名]
# 或者: from layout import getNumGhosts [as 别名]
def newGame( self, layout, pacmanAgent, ghostAgents, display, quiet = False, catchExceptions=False):
agents = [pacmanAgent] + ghostAgents[:layout.getNumGhosts()]
initState = GameState()
initState.initialize( layout, len(ghostAgents) )
game = Game(agents, display, self, catchExceptions=catchExceptions)
game.state = initState
self.initialState = initState.deepCopy()
self.quiet = quiet
return game
示例4: newGame
# 需要导入模块: import layout [as 别名]
# 或者: from layout import getNumGhosts [as 别名]
def newGame( self, layout, pacmanAgent, ghostAgents, display, quiet = False, catchExceptions=False):
agents = [pacmanAgent] + ghostAgents[:layout.getNumGhosts()]
initState = GameState()
initState.initialize( layout, len(ghostAgents) )
game = Game(agents, display, self, catchExceptions=catchExceptions)
game.state = initState
self.initialState = initState.deepCopy()
self.quiet = quiet
return game
示例5: newGame
# 需要导入模块: import layout [as 别名]
# 或者: from layout import getNumGhosts [as 别名]
def newGame( self, layout, pacmanAgent, ghostAgents, display, quiet = False, catchExceptions=False):
agents = [pacmanAgent] + ghostAgents[:layout.getNumGhosts()]
initState = GameState()
initState.initialize( layout, len(ghostAgents) )
game = Game(agents, display, self, catchExceptions=False)
game.state = initState
self.initialState = initState.deepCopy()
self.quiet = quiet
return game
示例6: replayGameFromStates
# 需要导入模块: import layout [as 别名]
# 或者: from layout import getNumGhosts [as 别名]
def replayGameFromStates( layout, states_file, display ) :
import pacmanAgents, ghostAgents
lambda_states = load_states( layout, states_file )
rules = ClassicGameRules()
agents = [pacmanAgents.GreedyAgent()] + [ghostAgents.RandomGhost(i+1) for i in range(layout.getNumGhosts())]
game = rules.newGame( layout, agents[0], agents[1:], display )
state = game.state
display.initialize(state.data)
for i, s in enumerate(lambda_states, 0):
print("Planner state {}: {}".format(i, s))
print("Starting replay")
for i, (s, sprime) in enumerate(zip(lambda_states, lambda_states[1:]), 0):
print("Planner state {}: {}".format(i, s))
print("Pacman Position according to Pacman Engine: {}".format(state.data.agentStates[0].configuration.pos))
nx, ny = s['at(the_pacman)']
ox, oy = state.data.agentStates[0].configuration.pos
assert nx == ox and ny == oy
nxprime, nyprime = sprime['at(the_pacman)']
vector_move = (nxprime - nx, nyprime - ny)
pacman_action = Actions.vectorToDirection(vector_move)
state = state.generateSuccessor(0, pacman_action)
display.update(state.data)
rules.process(state,game)
if state.isWin() or state.isLose() : break
for ghost_idx in range(1, len(state.data.agentStates)) :
idx = 'at(g{})'.format(ghost_idx-1)
nx, ny = s[idx]
ox, oy = state.data.agentStates[ghost_idx].configuration.pos
assert nx == ox and ny == oy
nxprime, nyprime = sprime[idx]
vector_move = (nxprime - nx, nyprime - ny)
ghost_action = Actions.vectorToDirection(vector_move)
state = state.generateSuccessor(ghost_idx, ghost_action)
display.update(state.data)
rules.process(state,game)
if state.isWin() or state.isLose() : continue
if state.isWin() or state.isLose() : break
display.finish()