Browse Source

dev: molecule to follow and to find smell origin

Bastien Sevajol 9 years ago
parent
commit
3f0867951b

+ 6 - 5
intelligine/cst.py View File

13
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
13
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
14
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
14
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
15
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
15
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
16
-PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.molecule_searching')
16
+MOLECULE_SEARCHING = IncrementedNamedInt.get('intelligine.molecule_searching')
17
+MOLECULES = IncrementedNamedInt.get('intelligine.molecules')
17
 
18
 
18
-# TODO: Renommer "move_mode" en "mode"
19
+# TODO: Renommer "move_mode" en "mode" ?
19
 MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
20
 MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
20
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
21
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
21
 MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
22
 MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
28
 TYPE_ANT = IncrementedNamedInt.get('intelligine.object.type.ant')
29
 TYPE_ANT = IncrementedNamedInt.get('intelligine.object.type.ant')
29
 
30
 
30
 PHEROMON_POSITIONS = IncrementedNamedInt.get('intelligine.phero.positions')
31
 PHEROMON_POSITIONS = IncrementedNamedInt.get('intelligine.phero.positions')
31
-PHEROMON_INFOS = IncrementedNamedInt.get('intelligine.phero.infos')
32
-PHEROMON_DIRECTION = IncrementedNamedInt.get('intelligine.phero.direction')
32
+MOLECULES_INFOS = IncrementedNamedInt.get('intelligine.phero.infos')
33
+MOLECULES_DIRECTION = IncrementedNamedInt.get('intelligine.phero.direction')
33
 PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
34
 PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
34
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
35
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
35
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
36
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
36
 EXPLORATION_VECTOR = IncrementedNamedInt.get('intelligine.exploration_vector')
37
 EXPLORATION_VECTOR = IncrementedNamedInt.get('intelligine.exploration_vector')
37
 
38
 
38
-SMELL = IncrementedNamedInt.get('intelligine.smell')
39
+#SMELL = IncrementedNamedInt.get('intelligine.smell')
39
 OBJ_SMELL = IncrementedNamedInt.get('intelligine.obj_smell')
40
 OBJ_SMELL = IncrementedNamedInt.get('intelligine.obj_smell')
40
 SMELL_FOOD = IncrementedNamedInt.get('intelligine.smell.food')
41
 SMELL_FOOD = IncrementedNamedInt.get('intelligine.smell.food')
41
 SMELL_EGG = IncrementedNamedInt.get('intelligine.smell.egg')
42
 SMELL_EGG = IncrementedNamedInt.get('intelligine.smell.egg')

+ 25 - 28
intelligine/display/Pygame.py View File

1
 from intelligine.core.exceptions import NoMolecule
1
 from intelligine.core.exceptions import NoMolecule
2
 from synergine_xyz.display.Pygame import Pygame as XyzPygame
2
 from synergine_xyz.display.Pygame import Pygame as XyzPygame
3
 import pygame
3
 import pygame
4
-from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, PHEROMON_POSITIONS, POINTS_SMELL, \
5
-    POINT_SMELL, SMELL_EGG, SMELL_FOOD
4
+from intelligine.cst import PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, MOLECULES, \
5
+    SMELL_EGG, SMELL_FOOD, MOLECULES_DIRECTION
6
 from intelligine.display.pygame.visualisation import SURFACE_PHEROMONE_EXPLORATION, SURFACE_PHEROMONE_HOME, \
6
 from intelligine.display.pygame.visualisation import SURFACE_PHEROMONE_EXPLORATION, SURFACE_PHEROMONE_HOME, \
7
     SURFACE_SMELL_EGG, SURFACE_SMELL_FOOD
7
     SURFACE_SMELL_EGG, SURFACE_SMELL_FOOD
8
 
8
 
18
         super().receive(actions_done)
18
         super().receive(actions_done)
19
 
19
 
20
         if self._is_display_molecules:
20
         if self._is_display_molecules:
21
-            molecules_positions = self._context.metas.list.get(PHEROMON_POSITIONS,
22
-                                                                PHEROMON_POSITIONS,
23
-                                                                allow_empty=True)
21
+            molecules_positions = self._context.metas.list.get(MOLECULES,
22
+                                                               MOLECULES,
23
+                                                               allow_empty=True)
24
             self._display_molecules(molecules_positions, self._context)
24
             self._display_molecules(molecules_positions, self._context)
25
 
25
 
26
-        if self._is_display_smells:
27
-            smell_positions = self._context.metas.list.get(POINTS_SMELL,
28
-                                                           POINTS_SMELL,
29
-                                                           allow_empty=True)
30
-            self._display_smells(smell_positions, self._context)
31
-
32
     def _display_molecules(self, molecules_positions, context):
26
     def _display_molecules(self, molecules_positions, context):
33
         molecule_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
27
         molecule_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
34
         molecule_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
28
         molecule_home_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_HOME)
29
+        smell_egg_surface = self._object_visualizer.get_surface(SURFACE_SMELL_EGG)
30
+        smell_food_surface = self._object_visualizer.get_surface(SURFACE_SMELL_FOOD)
35
 
31
 
36
         for point in molecules_positions:
32
         for point in molecules_positions:
37
             point_flavour = context.molecules().get_flavour(point)
33
             point_flavour = context.molecules().get_flavour(point)
38
             try:
34
             try:
39
-                point_flavour.get_molecule(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_HOME)
35
+                point_flavour.get_molecule(category=MOLECULES_DIRECTION, type=PHEROMON_DIR_HOME)
40
                 self.draw_surface(point, molecule_home_surface)
36
                 self.draw_surface(point, molecule_home_surface)
41
             except NoMolecule:
37
             except NoMolecule:
42
                 pass # No molecule here
38
                 pass # No molecule here
43
 
39
 
44
             try:
40
             try:
45
-                point_flavour.get_molecule(category=PHEROMON_DIRECTION, type=PHEROMON_DIR_EXPLO)
41
+                point_flavour.get_molecule(category=MOLECULES_DIRECTION, type=PHEROMON_DIR_EXPLO)
46
                 self.draw_surface(point, molecule_exploration_surface)
42
                 self.draw_surface(point, molecule_exploration_surface)
47
             except NoMolecule:
43
             except NoMolecule:
48
                 pass # No molecule here
44
                 pass # No molecule here
49
 
45
 
50
-    def _display_smells(self, smell_positions, context):
51
-        smell_egg_surface = self._object_visualizer.get_surface(SURFACE_SMELL_EGG)
52
-        smell_food_surface = self._object_visualizer.get_surface(SURFACE_SMELL_FOOD)
46
+            try:
47
+                molecule = point_flavour.get_molecule(category=MOLECULES_DIRECTION, type=SMELL_FOOD)
48
+                self.draw_surface(point, smell_food_surface)
53
 
49
 
54
-        for point in smell_positions:
55
-            point_flavour = context.metas.value.get(POINT_SMELL, point, allow_empty=True, empty_value={})
56
-            if SMELL_EGG in point_flavour:
50
+                adapted_point = self._get_real_pixel_position_of_position(point)
51
+                myfont = pygame.font.SysFont("monospace", 15)
52
+                label = myfont.render(str(molecule.get_distance()), 1, (255,255,0))
53
+                self._screen.blit(label, adapted_point)
54
+
55
+            except NoMolecule:
56
+                pass # No molecule here
57
+
58
+            try:
59
+                point_flavour.get_molecule(category=MOLECULES_DIRECTION, type=SMELL_EGG)
57
                 self.draw_surface(point, smell_egg_surface)
60
                 self.draw_surface(point, smell_egg_surface)
58
-            if SMELL_FOOD in point_flavour:
59
-                self.draw_surface(point, smell_food_surface)
61
+            except NoMolecule:
62
+                pass # No molecule here
60
 
63
 
61
     def _key_pressed(self, key):
64
     def _key_pressed(self, key):
62
 
65
 
63
-        if key == pygame.K_p:
66
+        if key == pygame.K_m:
64
             if self._is_display_molecules:
67
             if self._is_display_molecules:
65
                 self._is_display_molecules = False
68
                 self._is_display_molecules = False
66
             else:
69
             else:
67
                 self._is_display_molecules = True
70
                 self._is_display_molecules = True
68
-
69
-        if key == pygame.K_s:
70
-            if self._is_display_smells:
71
-                self._is_display_smells = False
72
-            else:
73
-                self._is_display_smells = True

+ 15 - 13
intelligine/simulation/molecule/DirectionMolecule.py View File

1
-from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_POSITIONS
1
+from intelligine.cst import POINTS_SMELL, MOLECULES, MOLECULES_DIRECTION
2
 from intelligine.core.exceptions import NoMolecule
2
 from intelligine.core.exceptions import NoMolecule
3
 from random import shuffle
3
 from random import shuffle
4
 from synergine_xyz.geometry import get_degree_from_north
4
 from synergine_xyz.geometry import get_degree_from_north
7
 
7
 
8
 class DirectionMolecule():
8
 class DirectionMolecule():
9
 
9
 
10
-    @staticmethod
11
-    def appose(context, point, molecule):
10
+    _positions_key = None
11
+
12
+    @classmethod
13
+    def appose(cls, context, point, molecule):
12
         context.molecules().increment_with_molecule(point, molecule)
14
         context.molecules().increment_with_molecule(point, molecule)
13
-        context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, point, assert_not_in=False)
15
+        context.metas.list.add(MOLECULES, MOLECULES, point, assert_not_in=False)
14
 
16
 
15
     @classmethod
17
     @classmethod
16
     def get_direction_for_point(cls, context, point, molecule_type):
18
     def get_direction_for_point(cls, context, point, molecule_type):
17
         flavour = context.molecules().get_flavour(point)
19
         flavour = context.molecules().get_flavour(point)
18
-        molecule = flavour.get_molecule(category=PHEROMON_DIRECTION, type=molecule_type)
20
+        molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
19
 
21
 
20
         distance = molecule.get_distance()
22
         distance = molecule.get_distance()
21
         around_molecule_filter = lambda around_molecule: around_molecule.get_distance() < distance
23
         around_molecule_filter = lambda around_molecule: around_molecule.get_distance() < distance
22
         around_molecules_points = cls._get_around_molecules(context, point, molecule_type,
24
         around_molecules_points = cls._get_around_molecules(context, point, molecule_type,
23
-                                                              molecule_filter=around_molecule_filter)
25
+                                                            molecule_filter=around_molecule_filter)
24
 
26
 
25
         if not around_molecules_points:
27
         if not around_molecules_points:
26
             raise NoMolecule()
28
             raise NoMolecule()
45
 
47
 
46
         return direction
48
         return direction
47
 
49
 
48
-    @staticmethod
49
-    def _get_around_molecules(context, reference_point, molecule_type,
50
-                               molecule_filter=lambda around_molecule: True):
50
+    @classmethod
51
+    def _get_around_molecules(cls, context, reference_point, molecule_type,
52
+                              molecule_filter=lambda around_molecule: True):
51
         around_points = context.get_around_points_of_point(reference_point)
53
         around_points = context.get_around_points_of_point(reference_point)
52
         around_molecules_points = []
54
         around_molecules_points = []
53
         for around_point in around_points:
55
         for around_point in around_points:
54
             flavour = context.molecules().get_flavour(around_point)
56
             flavour = context.molecules().get_flavour(around_point)
55
             try:
57
             try:
56
-                around_molecule = flavour.get_molecule(category=PHEROMON_DIRECTION, type=molecule_type)
58
+                around_molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
57
                 if molecule_filter(around_molecule):
59
                 if molecule_filter(around_molecule):
58
                     around_molecules_points.append((around_point, around_molecule))
60
                     around_molecules_points.append((around_point, around_molecule))
59
             except NoMolecule:
61
             except NoMolecule:
61
 
63
 
62
         return around_molecules_points
64
         return around_molecules_points
63
 
65
 
64
-    @staticmethod
65
-    def get_best_molecule_direction_in(context, reference_point, points, molecule_type):
66
+    @classmethod
67
+    def get_best_molecule_direction_in(cls, context, reference_point, points, molecule_type):
66
         around_molecules_points = []
68
         around_molecules_points = []
67
         for around_point in points:
69
         for around_point in points:
68
             flavour = context.molecules().get_flavour(around_point)
70
             flavour = context.molecules().get_flavour(around_point)
69
             try:
71
             try:
70
-                around_molecule = flavour.get_molecule(category=PHEROMON_DIRECTION, type=molecule_type)
72
+                around_molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=molecule_type)
71
                 around_molecules_points.append((around_point, around_molecule))
73
                 around_molecules_points.append((around_point, around_molecule))
72
             except NoMolecule:
74
             except NoMolecule:
73
                 pass  # Ok, no molecule, continue to sniff around
75
                 pass  # Ok, no molecule, continue to sniff around

+ 20 - 5
intelligine/simulation/object/brain/AntBrain.py View File

2
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
2
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
3
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
3
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
4
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, \
4
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, \
5
-    BRAIN_PART_TAKE, BRAIN_PART_PUT, MOVE_MODE_NURSE, PHEROMON_DIR_NONE, BRAIN_PART_ATTACK, MOVE_MODE_HOME
6
-from intelligine.cst import PHEROMONE_SEARCHING
5
+    BRAIN_PART_TAKE, BRAIN_PART_PUT, MOVE_MODE_NURSE, PHEROMON_DIR_NONE, BRAIN_PART_ATTACK, MOVE_MODE_HOME, SMELL_FOOD
6
+from intelligine.cst import MOLECULE_SEARCHING
7
 from intelligine.cst import BRAIN_PART_MOVE
7
 from intelligine.cst import BRAIN_PART_MOVE
8
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
8
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
9
 from intelligine.simulation.object.brain.part.transport.AntTakeBrainPart import AntTakeBrainPart
9
 from intelligine.simulation.object.brain.part.transport.AntTakeBrainPart import AntTakeBrainPart
10
+from intelligine.synergy.object.Food import Food
11
+from synergine.core.exceptions import NotFound
10
 
12
 
11
 
13
 
12
 class AntBrain(Brain):
14
 class AntBrain(Brain):
19
         BRAIN_PART_ATTACK: AttackBrainPart
21
         BRAIN_PART_ATTACK: AttackBrainPart
20
     }
22
     }
21
 
23
 
24
+    _taken_smell_matches = {
25
+        Food: SMELL_FOOD
26
+    }
27
+    """ Correspondance entre ce qui est ramassé et où ce doit être stocké """
28
+
22
     def __init__(self, context, host):
29
     def __init__(self, context, host):
23
         super().__init__(context, host)
30
         super().__init__(context, host)
24
         self._movement_mode = MOVE_MODE_HOME
31
         self._movement_mode = MOVE_MODE_HOME
55
         if mode == MOVE_MODE_EXPLO:
62
         if mode == MOVE_MODE_EXPLO:
56
             molecule_searching = PHEROMON_DIR_EXPLO
63
             molecule_searching = PHEROMON_DIR_EXPLO
57
         elif mode == MOVE_MODE_GOHOME:
64
         elif mode == MOVE_MODE_GOHOME:
65
+            # TODO: Plus rien ici (path integration)
58
             molecule_searching = PHEROMON_DIR_HOME
66
             molecule_searching = PHEROMON_DIR_HOME
59
         elif mode == MOVE_MODE_NURSE:
67
         elif mode == MOVE_MODE_NURSE:
60
             molecule_searching = PHEROMON_DIR_NONE
68
             molecule_searching = PHEROMON_DIR_NONE
61
         elif mode == MOVE_MODE_HOME:
69
         elif mode == MOVE_MODE_HOME:
62
-            return
70
+            molecule_searching = self.get_part(BRAIN_PART_TAKE).get_smell_target()
63
         else:
71
         else:
64
             raise NotImplementedError()
72
             raise NotImplementedError()
73
+
65
         self._molecule_searching = molecule_searching
74
         self._molecule_searching = molecule_searching
66
-        self._context.metas.value.set(PHEROMONE_SEARCHING, self._host.get_id(), molecule_searching)
75
+        self._context.metas.value.set(MOLECULE_SEARCHING, self._host.get_id(), molecule_searching)
67
 
76
 
68
     def get_movement_mode(self):
77
     def get_movement_mode(self):
69
         return self._movement_mode
78
         return self._movement_mode
75
         self._distance_from_objective = distance
84
         self._distance_from_objective = distance
76
 
85
 
77
     def get_distance_from_objective(self):
86
     def get_distance_from_objective(self):
78
-        return self._distance_from_objective
87
+        return self._distance_from_objective
88
+
89
+    def get_smell_for_object_taken(self, obj):
90
+        for take_class in self._taken_smell_matches:
91
+            if isinstance(obj, take_class):
92
+                return self._taken_smell_matches[take_class]
93
+        raise NotFound()

+ 27 - 14
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py View File

1
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
1
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
2
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
2
 from intelligine.synergy.event.move.direction import directions_modifiers, get_direction_for_degrees
3
 from intelligine.synergy.event.move.direction import directions_modifiers, get_direction_for_degrees
3
 from synergine_xyz.cst import POSITION
4
 from synergine_xyz.cst import POSITION
4
-from intelligine.core.exceptions import NoMolecule
5
-from intelligine.cst import PHEROMONE_SEARCHING, MOVE_MODE_EXPLO, \
6
-    MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, EXPLORATION_VECTOR, POINTS_SMELL
5
+from intelligine.core.exceptions import NoMolecule, NoTypeInMolecule
6
+from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, \
7
+    MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, EXPLORATION_VECTOR, POINTS_SMELL, MOLECULES, MOLECULES_DIRECTION, \
8
+    SMELL_FOOD, SMELL_EGG
7
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
9
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
8
 from synergine_xyz.geometry import get_degree_from_north
10
 from synergine_xyz.geometry import get_degree_from_north
9
 
11
 
24
     @classmethod
26
     @classmethod
25
     def get_direction(cls, context, object_id):
27
     def get_direction(cls, context, object_id):
26
         move_mode = context.metas.value.get(MOVE_MODE, object_id)
28
         move_mode = context.metas.value.get(MOVE_MODE, object_id)
27
-        if move_mode == MOVE_MODE_EXPLO:
29
+        if move_mode == MOVE_MODE_GOHOME:
30
+            return cls._get_direction_with_exploration_vector(context, object_id)
31
+        else:
28
             try:
32
             try:
29
                 return cls._get_direction_with_molecules(context, object_id)
33
                 return cls._get_direction_with_molecules(context, object_id)
30
             except NoMolecule:
34
             except NoMolecule:
31
                 return super().get_direction(context, object_id)
35
                 return super().get_direction(context, object_id)
32
-        elif move_mode == MOVE_MODE_GOHOME:
33
-            return cls._get_direction_with_exploration_vector(context, object_id)
34
 
36
 
35
         return super().get_direction(context, object_id)
37
         return super().get_direction(context, object_id)
36
 
38
 
37
     @classmethod
39
     @classmethod
38
     def _get_direction_with_molecules(cls, context, object_id):
40
     def _get_direction_with_molecules(cls, context, object_id):
39
         object_point = context.metas.value.get(POSITION, object_id)
41
         object_point = context.metas.value.get(POSITION, object_id)
40
-        molecule_type = context.metas.value.get(PHEROMONE_SEARCHING, object_id)
42
+        molecule_type = context.metas.value.get(MOLECULE_SEARCHING, object_id)
41
         try:
43
         try:
42
             direction = cls._get_molecule_direction_for_point(context, object_point, molecule_type)
44
             direction = cls._get_molecule_direction_for_point(context, object_point, molecule_type)
43
         except NoMolecule:
45
         except NoMolecule:
67
     def _get_direction_with_exploration_vector(context, object_id):
69
     def _get_direction_with_exploration_vector(context, object_id):
68
         current_position = context.metas.value.get(POSITION, object_id)
70
         current_position = context.metas.value.get(POSITION, object_id)
69
         exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
71
         exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
70
-        # TODO: inverser
72
+        # TODO: inverser (math)
71
         home_vector = (exploration_vector[0] - (exploration_vector[0]*2),
73
         home_vector = (exploration_vector[0] - (exploration_vector[0]*2),
72
                        exploration_vector[1] - (exploration_vector[1]*2))
74
                        exploration_vector[1] - (exploration_vector[1]*2))
73
         home_position = (0, current_position[1]+home_vector[0], current_position[2]+home_vector[1])
75
         home_position = (0, current_position[1]+home_vector[0], current_position[2]+home_vector[1])
100
         :param context:
102
         :param context:
101
         :return:
103
         :return:
102
         """
104
         """
103
-        if self._host_brain.get_movement_mode() == MOVE_MODE_EXPLO and self._on_home_smell(context, obj.get_id()):
105
+        movement_mode = self._host_brain.get_movement_mode()
106
+
107
+        if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(context, obj.get_id()):
104
             self._host_brain.switch_to_mode(MOVE_MODE_HOME)
108
             self._host_brain.switch_to_mode(MOVE_MODE_HOME)
109
+            # TODO: on change les molecule recherché (Food => SmellFood, definis dans Take, en fct de ce qui est take)
105
 
110
 
106
-        if self._host_brain.get_movement_mode() == MOVE_MODE_HOME and not self._on_home_smell(context, obj.get_id()):
107
-            # TODO: sitwh explo que si rien a faire (rien a poser par exemple)
111
+        elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(context, obj.get_id()):
108
             self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
112
             self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
109
             self._start_new_exploration()
113
             self._start_new_exploration()
110
 
114
 
115
+        # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
116
+
117
+        # TODO: Poser sur StockedFood
118
+
111
     @classmethod
119
     @classmethod
112
     def _on_home_smell(cls, context, object_id):
120
     def _on_home_smell(cls, context, object_id):
113
         current_position = context.metas.value.get(POSITION, object_id)
121
         current_position = context.metas.value.get(POSITION, object_id)
114
-        smell_points = context.metas.value.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True, empty_value={})
115
-        if current_position in smell_points:
116
-            return True
122
+        flavour = context.molecules().get_flavour(current_position)
123
+        # TODO: Idem, liste de smell_type ...
124
+        for smell_type in (SMELL_FOOD, SMELL_EGG):
125
+            try:
126
+                molecule = flavour.get_molecule(category=MOLECULES_DIRECTION, type=smell_type)
127
+                return True
128
+            except NoTypeInMolecule:
129
+                pass  # C'est qu'elle y est pas ^^
117
         return False
130
         return False
118
 
131
 
119
     def _update_exploration_vector(self):
132
     def _update_exploration_vector(self):

+ 11 - 0
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py View File

13
         MOVE_MODE_GOHOME: []
13
         MOVE_MODE_GOHOME: []
14
     }
14
     }
15
 
15
 
16
+    def __init__(self, host_brain):
17
+        super().__init__(host_brain)
18
+        self._smell_target = None
19
+
20
+    def get_smell_target(self):
21
+        if not self._smell_target:
22
+            raise Exception('No _smell_target')
23
+        return self._smell_target
24
+
16
     @classmethod
25
     @classmethod
17
     def can_take(cls, context, object_id, object_to_take_id):
26
     def can_take(cls, context, object_id, object_to_take_id):
18
         # Pour le moment si le type de l'objet fait partie des types admis pour le mode courant du porteur, c'est bon.
27
         # Pour le moment si le type de l'objet fait partie des types admis pour le mode courant du porteur, c'est bon.
20
 
29
 
21
     def done(self, obj, take_object, context):
30
     def done(self, obj, take_object, context):
22
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
31
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
32
+        # TODO: qqch plus generique ... (attention aux eggs)
23
         if isinstance(take_object, Resource):
33
         if isinstance(take_object, Resource):
34
+            self._smell_target = self._host_brain.get_smell_for_object_taken(take_object)
24
             obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
35
             obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
25
             obj.get_movement_molecule_gland().appose()
36
             obj.get_movement_molecule_gland().appose()

+ 3 - 2
intelligine/simulation/object/molecule/MoleculeGland.py View File

1
 from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled
1
 from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled
2
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
2
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
3
 
3
 
4
+
4
 class MoleculeGland():
5
 class MoleculeGland():
5
 
6
 
6
     def __init__(self, host, context):
7
     def __init__(self, host, context):
26
 
27
 
27
         try:
28
         try:
28
             DirectionMolecule.appose(self._context,
29
             DirectionMolecule.appose(self._context,
29
-                                      self._host.get_position(),
30
-                                      self.get_molecule())
30
+                                     self._host.get_position(),
31
+                                     self.get_molecule())
31
         except BestMoleculeHere as best_molecule_here:
32
         except BestMoleculeHere as best_molecule_here:
32
             self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance())
33
             self._host.get_brain().set_distance_from_objective(best_molecule_here.get_best_distance())
33
 
34
 

+ 5 - 2
intelligine/simulation/object/molecule/MovementMoleculeGland.py View File

1
-from intelligine.cst import PHEROMON_DIRECTION
1
+from intelligine.cst import MOLECULES_DIRECTION
2
 from intelligine.simulation.object.molecule.MoleculeGland import MoleculeGland
2
 from intelligine.simulation.object.molecule.MoleculeGland import MoleculeGland
3
 from intelligine.simulation.molecule.Molecule import Molecule
3
 from intelligine.simulation.molecule.Molecule import Molecule
4
 
4
 
9
         """
9
         """
10
         :return: Molecule
10
         :return: Molecule
11
         """
11
         """
12
-        return Molecule(PHEROMON_DIRECTION, self._molecule_type, self._host.get_brain().get_distance_from_objective(), 1)
12
+        return Molecule(MOLECULES_DIRECTION,
13
+                        self._molecule_type,
14
+                        self._host.get_brain().get_distance_from_objective(),
15
+                        1)

+ 29 - 16
intelligine/synergy/event/smell/SmellAction.py View File

1
-from intelligine.cst import POINT_SMELL, POINTS_SMELL
1
+from intelligine.cst import POINT_SMELL, POINTS_SMELL, MOLECULES_INFOS, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
2
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
3
+from intelligine.simulation.molecule.Molecule import Molecule
2
 from intelligine.synergy.event.smell.SmellEvent import SmellEvent
4
 from intelligine.synergy.event.smell.SmellEvent import SmellEvent
3
 from synergine.synergy.event.Action import Action
5
 from synergine.synergy.event.Action import Action
4
 
6
 
11
     def cycle_pre_run(cls, context, synergy_manager):
13
     def cycle_pre_run(cls, context, synergy_manager):
12
         smell_positions = context.metas.list.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
14
         smell_positions = context.metas.list.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
13
         for smell_position in smell_positions:
15
         for smell_position in smell_positions:
14
-            context.metas.value.unset(POINT_SMELL, smell_position)
16
+            # TODO: Remonter ca dans MoleculeManager ?
17
+            flavour_raw_data = context.metas.value.get(MOLECULES_INFOS, smell_position)
18
+            # TODO: Calculer ou definir qqpart la liste des smells
19
+            for smell_type in (SMELL_FOOD, SMELL_EGG):
20
+                if smell_type in flavour_raw_data:
21
+                    del(flavour_raw_data[smell_type])
22
+                context.metas.value.set(MOLECULES_INFOS, smell_position, flavour_raw_data)
15
         context.metas.list.unset(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
23
         context.metas.list.unset(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
16
 
24
 
17
     def run(self, obj, context, synergy_manager):
25
     def run(self, obj, context, synergy_manager):
18
-
26
+        # TODO: Utiliser molecule
19
         points_distances = self._parameters['points_distances']
27
         points_distances = self._parameters['points_distances']
20
         smell_type = obj.get_smell()
28
         smell_type = obj.get_smell()
21
 
29
 
22
         for smell_point in points_distances:
30
         for smell_point in points_distances:
23
-
24
-            where_to_put_smells = context.metas.value.get(POINT_SMELL, smell_point, allow_empty=True, empty_value={})
25
-            current_point_smell = points_distances[smell_point]
26
-
27
-            if smell_type not in where_to_put_smells:
28
-                where_to_put_smells[smell_type] = current_point_smell
29
-            else:
30
-                where_to_put_smell = where_to_put_smells[smell_type]
31
-                if current_point_smell < where_to_put_smell:
32
-                    where_to_put_smells[smell_type] = where_to_put_smell
33
-
34
-            context.metas.value.set(POINT_SMELL, smell_point, where_to_put_smells)
35
-            context.metas.list.add(POINTS_SMELL, POINTS_SMELL, smell_point, assert_not_in=False)
31
+            distance = points_distances[smell_point]
32
+            molecule = Molecule(MOLECULES_DIRECTION, smell_type, distance)
33
+            DirectionMolecule.appose(context, smell_point, molecule)
34
+
35
+            #
36
+            # current_point_smell = points_distances[smell_point]
37
+            # where_to_put_smells = context.metas.value.get(POINT_SMELL, smell_point, allow_empty=True, empty_value={})
38
+            #
39
+            #
40
+            # if smell_type not in where_to_put_smells:
41
+            #     where_to_put_smells[smell_type] = current_point_smell
42
+            # else:
43
+            #     where_to_put_smell = where_to_put_smells[smell_type]
44
+            #     if current_point_smell < where_to_put_smell:
45
+            #         where_to_put_smells[smell_type] = where_to_put_smell
46
+            #
47
+            # context.metas.value.set(POINT_SMELL, smell_point, where_to_put_smells)
48
+            # context.metas.list.add(POINTS_SMELL, POINTS_SMELL, smell_point, assert_not_in=False)

+ 1 - 1
intelligine/synergy/object/ant/Ant.py View File

21
                                                            COL_TRANSPORTER_NOT_CARRYING,
21
                                                            COL_TRANSPORTER_NOT_CARRYING,
22
                                                            COL_FIGHTER])
22
                                                            COL_FIGHTER])
23
         self._carried = None
23
         self._carried = None
24
-        self._brain.switch_to_mode(MOVE_MODE_HOME)
24
+        self._brain.switch_to_mode(MOVE_MODE_EXPLO)
25
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
25
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
26
 
26
 
27
     def die(self):
27
     def die(self):

+ 8 - 8
intelligine/synergy/stigmergy/MoleculesManager.py View File

1
 from intelligine.core.exceptions import BestMoleculeHere, NoMolecule
1
 from intelligine.core.exceptions import BestMoleculeHere, NoMolecule
2
-from intelligine.cst import PHEROMON_INFOS
2
+from intelligine.cst import MOLECULES_INFOS
3
 from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
3
 from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
4
 from intelligine.simulation.molecule.Molecule import Molecule
4
 from intelligine.simulation.molecule.Molecule import Molecule
5
 
5
 
10
         self._context = context
10
         self._context = context
11
 
11
 
12
     def get_flavour(self, position):
12
     def get_flavour(self, position):
13
-        point_molecules = self._context.metas.value.get(PHEROMON_INFOS,
14
-                                                         position,
15
-                                                         allow_empty=True,
16
-                                                         empty_value={})
13
+        point_molecules = self._context.metas.value.get(MOLECULES_INFOS,
14
+                                                        position,
15
+                                                        allow_empty=True,
16
+                                                        empty_value={})
17
         return MoleculeFlavour.new_from_raw_data(point_molecules)
17
         return MoleculeFlavour.new_from_raw_data(point_molecules)
18
 
18
 
19
     def set_flavour(self, position, flavour):
19
     def set_flavour(self, position, flavour):
20
-        self._context.metas.value.set(PHEROMON_INFOS, position, flavour.get_raw_data())
20
+        self._context.metas.value.set(MOLECULES_INFOS, position, flavour.get_raw_data())
21
 
21
 
22
     def get_molecule(self, position, category, type, allow_empty=False):
22
     def get_molecule(self, position, category, type, allow_empty=False):
23
         flavour = self.get_flavour(position)
23
         flavour = self.get_flavour(position)
34
             position_molecule = flavour.get_molecule(apposed_molecule.get_category(), apposed_molecule.get_type())
34
             position_molecule = flavour.get_molecule(apposed_molecule.get_category(), apposed_molecule.get_type())
35
         except NoMolecule:
35
         except NoMolecule:
36
             position_molecule = Molecule(apposed_molecule.get_category(),
36
             position_molecule = Molecule(apposed_molecule.get_category(),
37
-                                           apposed_molecule.get_type(),
38
-                                           distance=apposed_molecule.get_distance())
37
+                                         apposed_molecule.get_type(),
38
+                                         distance=apposed_molecule.get_distance())
39
 
39
 
40
         position_molecule.increment_intensity(apposed_molecule.get_intensity())
40
         position_molecule.increment_intensity(apposed_molecule.get_intensity())
41
 
41
 

+ 1 - 0
intelligine/tests/simulation/molecule/TestDirection.py View File

3
 from intelligine.core.exceptions import NoMolecule
3
 from intelligine.core.exceptions import NoMolecule
4
 from intelligine.simulation.molecule.Molecule import Molecule
4
 from intelligine.simulation.molecule.Molecule import Molecule
5
 from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
5
 from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
6
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
6
 
7
 
7
 ppath.insert(1,getcwd()+'/modules')
8
 ppath.insert(1,getcwd()+'/modules')
8
 
9