PheromoneGland.py 1009B

12345678910111213141516171819202122232425262728
  1. from intelligine.core.exceptions import BestPheromoneHere
  2. from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
  3. class PheromoneGland():
  4. def __init__(self, host, context):
  5. self._pheromone_type = None
  6. self._host = host
  7. self._context = context
  8. def set_pheromone_type(self, pheromone_type):
  9. self._pheromone_type = pheromone_type
  10. def get_pheromone_type(self):
  11. if self._pheromone_type is None:
  12. raise Exception("pheromone_type not specified")
  13. return self._pheromone_type
  14. def get_pheromone(self):
  15. raise NotImplementedError()
  16. def appose(self):
  17. try:
  18. DirectionPheromone.appose(self._context,
  19. self._host.get_position(),
  20. self.get_pheromone())
  21. except BestPheromoneHere as best_pheromone_here:
  22. self._host.get_brain().set_distance_from_objective(best_pheromone_here.get_best_distance())