Exemplo n.º 1
0
	def __logicLoop(self, task):
		"""
		Main logic loop, if the actual frames > max frames go to next generation,
		save statistics to file, update the pandas and the UI text
		
		Args:
		    task (task): Panda3D requires this param
		
		Returns:
		    int: Task.cont to continue looping
		"""
		if self.__terminationCriteria():
			sys.exit()

		if self.actualFrameNumber > self.maxFramesPerGeneration or Panda.livingPandas == 0:
			if self.bestGenomeScore < Panda.getBestPanda().carrotsEaten:
				self.bestGenomeScore = Panda.getBestPanda().carrotsEaten
				self.bestGenomeGenes = Panda.getBestPanda().brainWeights

			if ((self.ga.getCurrentGeneration()+1) % 10) == 0:
				self.__saveBestGenomeToFile()

			self.__saveGenomeStatsToFile()
			self.__goNextGen()

		for panda in Panda.pandaList:
			panda.update(self, Carrot.carrotList, Spike.spikeList)

		self.__updateText()
		self.actualFrameNumber += 1
		return Task.cont
Exemplo n.º 2
0
	def __goNextGen(self):
		"""
		Evolve the population one generation, clear the scene and generate it again
		in other random positions
		"""
		if self.bestGenomeScore < Panda.getBestPanda().carrotsEaten:
			self.bestGenomeScore = Panda.getBestPanda().carrotsEaten
			self.bestGenomeGenes = Panda.getBestPanda().brainWeights

		self.actualFrameNumber = 0
		self.ga.step()

		Spike.clearNormalSpikes()
		Panda.clearPandas(self)
		Carrot.clearCarrots(self)

		self.__generateSpikes()
		self.__generatePandas()
		self.__generateCarrots()