当前位置: 首页>>代码示例>>Python>>正文


Python VGDLParser.getAvatars方法代码示例

本文整理汇总了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)
开发者ID:sarobe,项目名称:VGDLEntityCreator,代码行数:76,代码来源:lunarlandertest.py


注:本文中的vgdl.core.VGDLParser.getAvatars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。