本文整理汇总了Python中simulation.Simulation.stats方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.stats方法的具体用法?Python Simulation.stats怎么用?Python Simulation.stats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulation.Simulation
的用法示例。
在下文中一共展示了Simulation.stats方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import stats [as 别名]
class Display:
def __init__(self):
self.width = Environment_s.width * Graphics_s.tile_length
self.height = Environment_s.height * Graphics_s.tile_length
self.restart = True
while self.restart:
self.sim = Simulation()
self.restart = False
self.bg_rendered = False
self.start()
def start(self):
pygame.init()
screen = pygame.display.set_mode((self.width, self.height))
pygame.display.set_caption(Graphics_s.window_title)
clock = pygame.time.Clock()
status_exit = False
move = False
sleep_time = 0.05
old_crits = []
old_food = []
while not status_exit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
status_exit = True
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
status_exit =True
elif event.key == pygame.K_BACKSPACE:
self.restart = True
status_exit = True
elif event.key == pygame.K_SPACE:
move = (True, False)[move]
elif event.key == pygame.K_TAB:
for line in self.sim.stats():
print line
print "\n"
elif event.key == pygame.K_PLUS:
sleep_time += 0.05
print sleep_time
elif event.key == pygame.K_MINUS:
sleep_time -= (0.05, 0)[sleep_time < 0.1]
print sleep_time
elif event.key == pygame.K_RIGHT:
old_crits = self.sim.population.keys()
old_food = self.sim.food.food.keys()
self.sim.step()
elif event.key == pygame.K_BACKSLASH:
cmd = raw_input("insert command:")
parse_cmd(cmd)
print cmd
elif event.key == pygame.K_s:
for i, critter in enumerate(self.sim.population.values()):
critter.brain.save(Graphics_s.brain_path + str(i) + Graphics_s.brain_ext)
print "Saved"
elif event.key == pygame.K_l:
for i, critter in enumerate(self.sim.population.values()):
critter.brain.load(Graphics_s.brain_path + str(i) + Graphics_s.brain_ext)
print "Loaded"
if move:
old_crits = self.sim.population.keys()
old_food = self.sim.food.food.keys()
sleep(sleep_time)
self.sim.step()
render(screen, self.sim, old_crits, old_food, self.bg_rendered)
if not self.bg_rendered:
self.bg_rendered = True
pygame.display.update()
pygame.quit()