MoleculeGland.py 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled
  2. from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
  3. class MoleculeGland():
  4. def __init__(self, host, context):
  5. self._molecule_type = None
  6. self._host = host
  7. self._context = context
  8. self._enabled = False
  9. def set_molecule_type(self, molecule_type):
  10. self._molecule_type = molecule_type
  11. def get_molecule_type(self):
  12. if self._molecule_type is None:
  13. raise Exception("molecule_type not specified")
  14. return self._molecule_type
  15. def get_molecule(self):
  16. raise NotImplementedError()
  17. def appose(self):
  18. if not self._enabled:
  19. raise MoleculeGlandDisabled()
  20. try:
  21. DirectionMolecule.appose(self._context,
  22. self._host.get_position(),
  23. self.get_molecule())
  24. except BestMoleculeHere as best_molecule_here:
  25. self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance())
  26. def disable(self):
  27. self._enabled = False
  28. def enable(self):
  29. self._enabled = True
  30. def is_enabled(self):
  31. return self._enabled