本文整理汇总了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)
示例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]