AntBrain.py 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. from intelligine.cst import PHEROMONE_SEARCHING
  4. class AntBrain(Brain):
  5. def __init__(self, context, host):
  6. super().__init__(context, host)
  7. self._movement_mode = MOVE_MODE_EXPLO
  8. self._distance_from_objective = 0 # TODO rename: distance_since_objective
  9. self._pheromone_searching = PHEROMON_DIR_EXPLO
  10. def switch_to_mode(self, mode):
  11. self._movement_mode = mode
  12. self._update_pheromone_gland(mode)
  13. self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
  14. self._distance_from_objective = 0
  15. self._update_pheromone_searching(mode)
  16. def _update_pheromone_gland(self, mode):
  17. if mode == MOVE_MODE_EXPLO:
  18. pheromone_direction_type = PHEROMON_DIR_HOME
  19. elif mode == MOVE_MODE_GOHOME:
  20. pheromone_direction_type = PHEROMON_DIR_EXPLO
  21. else:
  22. raise NotImplementedError()
  23. self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
  24. def _update_pheromone_searching(self, mode):
  25. if mode == MOVE_MODE_EXPLO:
  26. pheromone_searching = PHEROMON_DIR_EXPLO
  27. elif mode == MOVE_MODE_GOHOME:
  28. pheromone_searching = PHEROMON_DIR_HOME
  29. else:
  30. raise NotImplementedError()
  31. self._pheromone_searching = pheromone_searching
  32. self._context.metas.value.set(PHEROMONE_SEARCHING, self._host.get_id(), pheromone_searching)
  33. def get_movement_mode(self):
  34. return self._movement_mode
  35. def host_moved(self, distance=1):
  36. self._distance_from_objective += 1
  37. def set_distance_from_objective(self, distance):
  38. self._distance_from_objective = distance
  39. def get_distance_from_objective(self):
  40. return self._distance_from_objective