def appose(self): if not self._enabled: raise MoleculeGlandDisabled() try: DirectionMolecule.appose(self._context, self._host.get_position(), self.get_molecule()) except BestMoleculeHere as best_molecule_here: self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance())
def appose(self): if not self._enabled: raise MoleculeGlandDisabled() try: DirectionMolecule.appose(self._context, self._host.get_position(), self.get_molecule()) except BestMoleculeHere as best_molecule_here: self._host.get_brain().set_distance_from_objective( best_molecule_here.get_best_distance())
def run(self, obj, context, synergy_manager): points_distances = self._parameters['points_distances'] smell_type = obj.get_smell() for smell_point in points_distances: distance = points_distances[smell_point] molecule = Molecule(MOLECULES_DIRECTION, smell_type, distance) try: DirectionMolecule.appose(context, smell_point, molecule) except BestMoleculeHere: pass
def test_appose(self): self._test_point_raise_no_molecule() self._test_points_raise_no_molecule() # Une molecule au centre DirectionMolecule.appose(self._context, _p(CENTER), self._get_molecule(PHEROMON_DIR_EXPLO, 2)) # Ne permet pas de trouver une route self._test_point_raise_no_molecule(re_init=False) self._test_points_raise_no_molecule(re_init=False) # Une molecule au nord DirectionMolecule.appose(self._context, _p(NORTH), self._get_molecule(PHEROMON_DIR_EXPLO, 1)) # le permet self._test_direction_for_points({}, NORTH, re_init=False) self._test_direction_for_point({}, NORTH, re_init=False)
def _get_direction_of_molecule(context, point, molecule_type): search_molecule_in_points = context.get_around_points_of_point(point) try: best_molecule_direction = DirectionMolecule.get_best_molecule_direction_in(context, point, search_molecule_in_points, molecule_type) return best_molecule_direction except NoMolecule as err: raise err
def _test_direction_for_point(self, molecules, direction, molecule_type=PHEROMON_DIR_EXPLO, reference_point=_p(CENTER), re_init=True): """ :param molecules: :param direction: :param molecule_type: :param reference_point: :return: """ self._set_up_molecules(molecules, re_init=re_init) direction_tested = DirectionMolecule.get_direction_for_point(self._context, reference_point, molecule_type) self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
def _test_direction_for_point(self, molecules, direction, molecule_type=PHEROMON_DIR_EXPLO, reference_point=_p(CENTER), re_init=True): """ :param molecules: :param direction: :param molecule_type: :param reference_point: :return: """ self._set_up_molecules(molecules, re_init=re_init) direction_tested = DirectionMolecule.get_direction_for_point( self._context, reference_point, molecule_type) self.assertEqual(direction, direction_tested, "Direction must be %s" % direction)
def _get_molecule_direction_for_point(context, point, molecule_type, molecule_way): return DirectionMolecule.get_direction_for_point(context, point, molecule_type, molecule_way)