本文整理匯總了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()