本文整理汇总了Python中vgdl.core.VGDLParser.getAvatars方法的典型用法代码示例。如果您正苦于以下问题:Python VGDLParser.getAvatars方法的具体用法?Python VGDLParser.getAvatars怎么用?Python VGDLParser.getAvatars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vgdl.core.VGDLParser
的用法示例。
在下文中一共展示了VGDLParser.getAvatars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runLunarLander
# 需要导入模块: from vgdl.core import VGDLParser [as 别名]
# 或者: from vgdl.core.VGDLParser import getAvatars [as 别名]
def runLunarLander():
# import lunar lander
from vgdl.examples.continuousphysics.lander import lander_game, lander_level
# build the game
g = VGDLParser().parseGame(lander_game)
g.buildLevel(lander_level)
# TODO: Determine how to not need to bring up the pygame display in order to run the game.
g._initScreen([1, 1])
ship = g.getAvatars()[0]
# store initial ship state
initState = [ship.rect.x, ship.rect.y, ship.speed, ship.orientation]
print "starting position: " + str(ship)
print "starting state: " + str(initState)
# get random actions
actions = generateInput(ACTIONS)
states = [initState]
# move ship based on random actions
print actions
for a in actions:
for i in range(REPEATS):
ship.action = a
updateGame(g, a)
if ended:
print a, i
break
states.append(makeState(ship))
endState = states[len(states)-1]
# confirm final position
print "first final position after actions: " + str(ship)
print "final state: " + str(endState)
# reroll ship back to initial state
setState(ship, initState)
# vary action sequence
# first pick a point to vary
random.seed(10466)
varyIndex = random.randint(0, len(actions) - 1)
# then change that action
oldAction = actions[varyIndex]
actions[varyIndex] = BASEDIRS[random.randint(0, len(BASEDIRS) - 1)]
# print out the change and the full list of actions
print "changed action " + str(varyIndex) + " to " + str(actions[varyIndex])
print "new actions: " + str(actions)
# predict through simple calculation how the final position should be
predictState = predictOutcome(states, actions, oldAction, varyIndex)
print "predicted state " + str(predictState)
# find out where the actual final position is
for a in actions:
for i in range(REPEATS):
updateGame(g, a)
if ended:
print a, i
break
endState = makeState(ship)
print "actual ending position: " + str(ship)
print "ending state: " + str(endState)
# get error
error = [endState[0] - predictState[0], endState[1] - predictState[1]]
print "prediction error: " + str(error)