AntBrain.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637
  1. from intelligine.simulation.object.brain.Brain import Brain
  2. from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO
  3. class AntBrain(Brain):
  4. def __init__(self, context, host):
  5. super().__init__(context, host)
  6. self._movement_mode = MOVE_MODE_EXPLO
  7. self._distance_from_objective = 0 # TODO rename: distance_since_objective
  8. def switch_to_mode(self, mode):
  9. self._movement_mode = mode
  10. self._update_pheromone_gland(mode)
  11. self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
  12. self._distance_from_objective = 0
  13. def _update_pheromone_gland(self, mode):
  14. if mode == MOVE_MODE_EXPLO:
  15. pheromone_direction_type = PHEROMON_DIR_HOME
  16. elif mode == MOVE_MODE_GOHOME:
  17. pheromone_direction_type = PHEROMON_DIR_EXPLO
  18. else:
  19. raise NotImplementedError()
  20. self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
  21. def get_movement_mode(self):
  22. return self._movement_mode
  23. def host_moved(self, distance=1):
  24. self._distance_from_objective += 1
  25. def set_distance_from_objective(self, distance):
  26. self._distance_from_objective = distance
  27. def get_distance_from_objective(self):
  28. return self._distance_from_objective