示例#1
0
    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())
示例#2
0
    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())
示例#3
0
    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
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
 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
示例#7
0
    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)
示例#8
0
    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)
示例#9
0
 def _get_molecule_direction_for_point(context, point, molecule_type, molecule_way):
     return DirectionMolecule.get_direction_for_point(context, point, molecule_type, molecule_way)