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


Python Simulation.stats方法代码示例

本文整理汇总了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()
开发者ID:nglgzz,项目名称:tale,代码行数:77,代码来源:graphics.py


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