本文整理汇总了Python中vgdl.core.VGDLParser._initScreen方法的典型用法代码示例。如果您正苦于以下问题:Python VGDLParser._initScreen方法的具体用法?Python VGDLParser._initScreen怎么用?Python VGDLParser._initScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vgdl.core.VGDLParser
的用法示例。
在下文中一共展示了VGDLParser._initScreen方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testInteractions
# 需要导入模块: from vgdl.core import VGDLParser [as 别名]
# 或者: from vgdl.core.VGDLParser import _initScreen [as 别名]
def testInteractions():
from vgdl.core import VGDLParser
from examples.gridphysics.aliens import aliens_level, aliens_game
from pygame.locals import K_SPACE
# from examples.gridphysics.sokoban import so
from pybrain.rl.agents.agent import Agent
class DummyAgent(Agent):
total = 4
def getAction(self):
# res = randint(0, self.total - 1)
return 1
map_str, game_str = aliens_level, aliens_game
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
g._initScreen(g.screensize,headless=True)
for _ in range(300):
win, _ = g.tick(K_SPACE)
if win is not None:
break
示例2: runLunarLander
# 需要导入模块: from vgdl.core import VGDLParser [as 别名]
# 或者: from vgdl.core.VGDLParser import _initScreen [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)