Exemplo n.º 1
0
	def Sniff(self):
		" Looks for the next place to go "
		DirectionToTarget = cmath.phase(t2c(self.Target) - t2c(self.location))   # argument 
		DirectionToTarget = ET.noise_add(DirectionToTarget, 0.02*cmath.pi * Gbl.Parameter('Noise'))
		# Distance0 = abs(DirectionToTarget)
		Neighbourhood = Land.neighbours(self.location, Gbl.Parameter('SniffingDistance'))
		random.shuffle(Neighbourhood) # to avoid anisotropy
		acceptable = None
		best = -Gbl.Parameter('Saturation')	# best == pheromone balance found so far
		for NewPos in Neighbourhood:
			if NewPos == self.location: continue
			# Target attractiveness
			Direction = cmath.phase(t2c(NewPos) - t2c(self.location))
			Value = Gbl.Parameter('TargetAttractiveness') * abs(cmath.pi - abs(DirectionToTarget - Direction))
			# looking for position with pheromone
			# attractiveness of pheromone
			Value += Gbl.Parameter('PheromoneAttractiveness') * float(Land.pheromone(NewPos)) / Gbl.Parameter('Saturation')
			# Value += Gbl.Parameter('PheromoneAttractiveness') * (Land.pheromone(NewPos))
			# aversion to climbing
			Value -= Gbl.Parameter('SlopeAversion') * abs(Land.Altitude(NewPos) - Land.Altitude(self.location))
			if Value > best:			  
				acceptable = NewPos
				best = Value
		return acceptable
Exemplo n.º 2
0
	def Sniff(self):
		" Looks for the next place to go "
		DirectionToTarget = cmath.phase(t2c(self.Target) - t2c(self.location))   # argument 
		DirectionToTarget = ET.noise_add(DirectionToTarget, 0.02*cmath.pi * Gbl.Parameter('Noise'))
		# Distance0 = abs(DirectionToTarget)
		Neighbourhood = list(Land.neighbours(self.location, Gbl.Parameter('SniffingDistance')))
		random.shuffle(Neighbourhood) # to avoid anisotropy
		acceptable = None
		best = -Gbl.Parameter('Saturation')	# best == pheromone balance found so far
		for NewPos in Neighbourhood:
			if NewPos == self.location: continue
			# Target attractiveness
			Direction = cmath.phase(t2c(NewPos) - t2c(self.location))
			Value = Gbl.Parameter('TargetAttractiveness') * abs(cmath.pi - abs(DirectionToTarget - Direction))
			# looking for position with pheromone
			# attractiveness of pheromone
			Value += Gbl.Parameter('PheromoneAttractiveness') * float(Land.pheromone(NewPos)) / Gbl.Parameter('Saturation')
			# Value += Gbl.Parameter('PheromoneAttractiveness') * (Land.pheromone(NewPos))
			# aversion to climbing
			Value -= Gbl.Parameter('SlopeAversion') * abs(Land.Altitude(NewPos) - Land.Altitude(self.location))
			if Value > best:			  
				acceptable = NewPos
				best = Value
		return acceptable