Example #1
0
	def moveRandomly(self, individual, step_length):
		ind = population.Individual()
	
		ind.loadIndividual(individual)
	
		while 1:
			random = nbmath.randomDouble()*0.25
			x_change = math.log(random)/math.log(0.25)*step_length
	
			random = nbmath.randomDouble()*0.25
			y_change = math.log(random)/math.log(0.25)*step_length
	
			if nbmath.randomNumber(100) < 50:
				x_change = 0-x_change
	
			if nbmath.randomNumber(100) < 50:
				y_change = 0-y_change
				
			if self.pixelColourAt(ind.X+x_change,ind.Y+y_change) != (255, 255, 255):
				break;
		
		ind.X += x_change
		ind.Y += y_change
	
		return ind.getIndividual()
	
	registered = 0;
	
	for x in range(0,100):  #simulate the population for 100 years.
		print('simulation: ' + str(y) + '   year: ' + str(x));
  
		if BEARS.getPopulationSize() > 0:
			while BEARS.feedToEnd() != 'done':
				alive = 1;

				IND.loadIndividual(BEARS.selectedIndividual);
				
				if IND.gender == 'f':
					if IND.age >= 5:
						if IND.misc == 'pregnant':
							if nbmath.randomDouble() <= 0.82:
								if nbmath.randomDouble() > 0.90:
									BEARS.generateIndividual(IND.ID,0,0,'r','','',0,0,0,'')
									BEARS.generateIndividual(IND.ID,0,0,'r','','',0,0,0,'')
									BEARS.generateIndividual(IND.ID,0,0,'r','','',0,0,0,'')
								elif nbmath.randomDouble() > 0.67:
									BEARS.generateIndividual(IND.ID,0,0,'r','','',0,0,0,'')
									BEARS.generateIndividual(IND.ID,0,0,'r','','',0,0,0,'')
								else:
									BEARS.generateIndividual(IND.ID,0,0,'r','','',0,0,0,'')
								
								IND.misc = 'parent0';
						elif IND.misc == 'parent0':
								IND.misc = 'parent1';
						elif IND.misc == 'parent1':
								IND.misc = 'parent2';