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


Python World.init方法代码示例

本文整理汇总了Python中world.World.init方法的典型用法代码示例。如果您正苦于以下问题:Python World.init方法的具体用法?Python World.init怎么用?Python World.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在world.World的用法示例。


在下文中一共展示了World.init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Scenario

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import init [as 别名]
class Scenario(object):  # abstract
    __metaclass__ = ScenarioRegistrar
    world_size = (640, 480)  # Override this to customize world size
    walls = True

    def __init__(self, parameter, agent):
        self.parameter = parameter
        self.agent = agent
        self.world = World(self.world_size)
        self.world.init()
        self.init()

        if self.walls:
            self.add_walls()

        self.world.add_unit(agent)

    def __repr__(self):
        return "{0}({1})".format(self.__class__.__name__, self.parameter)

    def add_walls(self):
        """ Convenience method to add obstacles along all borders of the rendered world.

        Call this when setting up the world to prevent units from "escaping"
        """
        self.world.add_obstacle(obstacle.Line(Vec2d(0, 0), Vec2d(0, self.world_size[1])))
        self.world.add_obstacle(obstacle.Line(Vec2d(0, self.world_size[1]), Vec2d(self.world_size[0], self.world_size[1])))
        self.world.add_obstacle(obstacle.Line(Vec2d(self.world_size[0], self.world_size[1]), Vec2d(self.world_size[0], 0)))
        self.world.add_obstacle(obstacle.Line(Vec2d(self.world_size[0], 0), Vec2d(0, 0)))

    def update(self, dt):
        pass

    def run(self):
        overtime = -1
        agent_out_time = 0
        while 1:
            if self.agent.position.distance_to(self.agent.goal) <= self.agent.radius:
                ## for Crossing scenario only
                if (agent_out_time == 0):
                    self.world.remove_unit(self.agent)
                    agent_out_time = self.world._time
                overtime = overtime + 1
                if overtime == 0:
                    if(len(self.world.avg_groundspeed_list)):
                        print "Average Average Ground Speed:", sum(self.world.avg_groundspeed_list) / len(self.world.avg_groundspeed_list)
                        print "Agent Ground Speed:", self.agent.travel_length / agent_out_time
                    if(len(self.world.collision_list)):
                        print "Average Collisions:", sum(self.world.collision_list) / len(self.world.collision_list)
                        print "Agent Collisions:", self.agent.collisions
                    return True

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    return False

            dt = self.world.advance()
            self.update(dt)
开发者ID:carson,项目名称:keiro,代码行数:60,代码来源:scenario.py

示例2: init

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import init [as 别名]
    def init(self):
        # create 9 worlds and collect them
        for i in xrange(0,9):
            newWorld = World()
            newWorld.init(i)
            self.worlds.append(newWorld)

        # grab first 3 worlds
        self.visibleWorlds = self.worlds[:3]
开发者ID:karsithe,项目名称:PyWeek-12,代码行数:11,代码来源:worldview.py


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