Browse Source

dev: molecule to follow and to find smell origin

Bastien Sevajol 8 years ago
parent
commit
3f0867951b

+ 6 - 5
intelligine/cst.py View File

@@ -13,9 +13,10 @@ CARRIED = IncrementedNamedInt.get('intelligine.carried')
13 13
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
14 14
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
15 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 20
 MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
20 21
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
21 22
 MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
@@ -28,14 +29,14 @@ TYPE_NURSERY = IncrementedNamedInt.get('intelligine.object.type.nursery')
28 29
 TYPE_ANT = IncrementedNamedInt.get('intelligine.object.type.ant')
29 30
 
30 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 34
 PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
34 35
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
35 36
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
36 37
 EXPLORATION_VECTOR = IncrementedNamedInt.get('intelligine.exploration_vector')
37 38
 
38
-SMELL = IncrementedNamedInt.get('intelligine.smell')
39
+#SMELL = IncrementedNamedInt.get('intelligine.smell')
39 40
 OBJ_SMELL = IncrementedNamedInt.get('intelligine.obj_smell')
40 41
 SMELL_FOOD = IncrementedNamedInt.get('intelligine.smell.food')
41 42
 SMELL_EGG = IncrementedNamedInt.get('intelligine.smell.egg')

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

@@ -1,8 +1,8 @@
1 1
 from intelligine.core.exceptions import NoMolecule
2 2
 from synergine_xyz.display.Pygame import Pygame as XyzPygame
3 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 6
 from intelligine.display.pygame.visualisation import SURFACE_PHEROMONE_EXPLORATION, SURFACE_PHEROMONE_HOME, \
7 7
     SURFACE_SMELL_EGG, SURFACE_SMELL_FOOD
8 8
 
@@ -18,56 +18,53 @@ class Pygame(XyzPygame):
18 18
         super().receive(actions_done)
19 19
 
20 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 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 26
     def _display_molecules(self, molecules_positions, context):
33 27
         molecule_exploration_surface = self._object_visualizer.get_surface(SURFACE_PHEROMONE_EXPLORATION)
34 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 32
         for point in molecules_positions:
37 33
             point_flavour = context.molecules().get_flavour(point)
38 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 36
                 self.draw_surface(point, molecule_home_surface)
41 37
             except NoMolecule:
42 38
                 pass # No molecule here
43 39
 
44 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 42
                 self.draw_surface(point, molecule_exploration_surface)
47 43
             except NoMolecule:
48 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 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 64
     def _key_pressed(self, key):
62 65
 
63
-        if key == pygame.K_p:
66
+        if key == pygame.K_m:
64 67
             if self._is_display_molecules:
65 68
                 self._is_display_molecules = False
66 69
             else:
67 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,4 +1,4 @@
1
-from intelligine.cst import PHEROMON_DIRECTION, PHEROMON_POSITIONS
1
+from intelligine.cst import POINTS_SMELL, MOLECULES, MOLECULES_DIRECTION
2 2
 from intelligine.core.exceptions import NoMolecule
3 3
 from random import shuffle
4 4
 from synergine_xyz.geometry import get_degree_from_north
@@ -7,20 +7,22 @@ from intelligine.synergy.event.move.direction import get_direction_for_degrees
7 7
 
8 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 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 17
     @classmethod
16 18
     def get_direction_for_point(cls, context, point, molecule_type):
17 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 22
         distance = molecule.get_distance()
21 23
         around_molecule_filter = lambda around_molecule: around_molecule.get_distance() < distance
22 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 27
         if not around_molecules_points:
26 28
             raise NoMolecule()
@@ -45,15 +47,15 @@ class DirectionMolecule():
45 47
 
46 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 53
         around_points = context.get_around_points_of_point(reference_point)
52 54
         around_molecules_points = []
53 55
         for around_point in around_points:
54 56
             flavour = context.molecules().get_flavour(around_point)
55 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 59
                 if molecule_filter(around_molecule):
58 60
                     around_molecules_points.append((around_point, around_molecule))
59 61
             except NoMolecule:
@@ -61,13 +63,13 @@ class DirectionMolecule():
61 63
 
62 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 68
         around_molecules_points = []
67 69
         for around_point in points:
68 70
             flavour = context.molecules().get_flavour(around_point)
69 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 73
                 around_molecules_points.append((around_point, around_molecule))
72 74
             except NoMolecule:
73 75
                 pass  # Ok, no molecule, continue to sniff around

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

@@ -2,11 +2,13 @@ from intelligine.simulation.object.brain.Brain import Brain
2 2
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
3 3
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
4 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 7
 from intelligine.cst import BRAIN_PART_MOVE
8 8
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
9 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 14
 class AntBrain(Brain):
@@ -19,6 +21,11 @@ class AntBrain(Brain):
19 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 29
     def __init__(self, context, host):
23 30
         super().__init__(context, host)
24 31
         self._movement_mode = MOVE_MODE_HOME
@@ -55,15 +62,17 @@ class AntBrain(Brain):
55 62
         if mode == MOVE_MODE_EXPLO:
56 63
             molecule_searching = PHEROMON_DIR_EXPLO
57 64
         elif mode == MOVE_MODE_GOHOME:
65
+            # TODO: Plus rien ici (path integration)
58 66
             molecule_searching = PHEROMON_DIR_HOME
59 67
         elif mode == MOVE_MODE_NURSE:
60 68
             molecule_searching = PHEROMON_DIR_NONE
61 69
         elif mode == MOVE_MODE_HOME:
62
-            return
70
+            molecule_searching = self.get_part(BRAIN_PART_TAKE).get_smell_target()
63 71
         else:
64 72
             raise NotImplementedError()
73
+
65 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 77
     def get_movement_mode(self):
69 78
         return self._movement_mode
@@ -75,4 +84,10 @@ class AntBrain(Brain):
75 84
         self._distance_from_objective = distance
76 85
 
77 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,9 +1,11 @@
1
+from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
1 2
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
2 3
 from intelligine.synergy.event.move.direction import directions_modifiers, get_direction_for_degrees
3 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 9
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
8 10
 from synergine_xyz.geometry import get_degree_from_north
9 11
 
@@ -24,20 +26,20 @@ class AntMoveBrainPart(MoveBrainPart):
24 26
     @classmethod
25 27
     def get_direction(cls, context, object_id):
26 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 32
             try:
29 33
                 return cls._get_direction_with_molecules(context, object_id)
30 34
             except NoMolecule:
31 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 37
         return super().get_direction(context, object_id)
36 38
 
37 39
     @classmethod
38 40
     def _get_direction_with_molecules(cls, context, object_id):
39 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 43
         try:
42 44
             direction = cls._get_molecule_direction_for_point(context, object_point, molecule_type)
43 45
         except NoMolecule:
@@ -67,7 +69,7 @@ class AntMoveBrainPart(MoveBrainPart):
67 69
     def _get_direction_with_exploration_vector(context, object_id):
68 70
         current_position = context.metas.value.get(POSITION, object_id)
69 71
         exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
70
-        # TODO: inverser
72
+        # TODO: inverser (math)
71 73
         home_vector = (exploration_vector[0] - (exploration_vector[0]*2),
72 74
                        exploration_vector[1] - (exploration_vector[1]*2))
73 75
         home_position = (0, current_position[1]+home_vector[0], current_position[2]+home_vector[1])
@@ -100,20 +102,31 @@ class AntMoveBrainPart(MoveBrainPart):
100 102
         :param context:
101 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 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 112
             self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
109 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 119
     @classmethod
112 120
     def _on_home_smell(cls, context, object_id):
113 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 130
         return False
118 131
 
119 132
     def _update_exploration_vector(self):

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

@@ -13,6 +13,15 @@ class AntTakeBrainPart(TakeBrainPart):
13 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 25
     @classmethod
17 26
     def can_take(cls, context, object_id, object_to_take_id):
18 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,6 +29,8 @@ class AntTakeBrainPart(TakeBrainPart):
20 29
 
21 30
     def done(self, obj, take_object, context):
22 31
         # TODO: Ranger ca ? Truc plus dynamique/configurable ?
32
+        # TODO: qqch plus generique ... (attention aux eggs)
23 33
         if isinstance(take_object, Resource):
34
+            self._smell_target = self._host_brain.get_smell_for_object_taken(take_object)
24 35
             obj.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
25 36
             obj.get_movement_molecule_gland().appose()

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

@@ -1,6 +1,7 @@
1 1
 from intelligine.core.exceptions import BestMoleculeHere, MoleculeGlandDisabled
2 2
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
3 3
 
4
+
4 5
 class MoleculeGland():
5 6
 
6 7
     def __init__(self, host, context):
@@ -26,8 +27,8 @@ class MoleculeGland():
26 27
 
27 28
         try:
28 29
             DirectionMolecule.appose(self._context,
29
-                                      self._host.get_position(),
30
-                                      self.get_molecule())
30
+                                     self._host.get_position(),
31
+                                     self.get_molecule())
31 32
         except BestMoleculeHere as best_molecule_here:
32 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,4 +1,4 @@
1
-from intelligine.cst import PHEROMON_DIRECTION
1
+from intelligine.cst import MOLECULES_DIRECTION
2 2
 from intelligine.simulation.object.molecule.MoleculeGland import MoleculeGland
3 3
 from intelligine.simulation.molecule.Molecule import Molecule
4 4
 
@@ -9,4 +9,7 @@ class MovementMoleculeGland(MoleculeGland):
9 9
         """
10 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,4 +1,6 @@
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 4
 from intelligine.synergy.event.smell.SmellEvent import SmellEvent
3 5
 from synergine.synergy.event.Action import Action
4 6
 
@@ -11,25 +13,36 @@ class SmellAction(Action):
11 13
     def cycle_pre_run(cls, context, synergy_manager):
12 14
         smell_positions = context.metas.list.get(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
13 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 23
         context.metas.list.unset(POINTS_SMELL, POINTS_SMELL, allow_empty=True)
16 24
 
17 25
     def run(self, obj, context, synergy_manager):
18
-
26
+        # TODO: Utiliser molecule
19 27
         points_distances = self._parameters['points_distances']
20 28
         smell_type = obj.get_smell()
21 29
 
22 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,7 +21,7 @@ class Ant(Bug):
21 21
                                                            COL_TRANSPORTER_NOT_CARRYING,
22 22
                                                            COL_FIGHTER])
23 23
         self._carried = None
24
-        self._brain.switch_to_mode(MOVE_MODE_HOME)
24
+        self._brain.switch_to_mode(MOVE_MODE_EXPLO)
25 25
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
26 26
 
27 27
     def die(self):

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

@@ -1,5 +1,5 @@
1 1
 from intelligine.core.exceptions import BestMoleculeHere, NoMolecule
2
-from intelligine.cst import PHEROMON_INFOS
2
+from intelligine.cst import MOLECULES_INFOS
3 3
 from intelligine.simulation.molecule.MoleculeFlavour import MoleculeFlavour
4 4
 from intelligine.simulation.molecule.Molecule import Molecule
5 5
 
@@ -10,14 +10,14 @@ class MoleculesManager():
10 10
         self._context = context
11 11
 
12 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 17
         return MoleculeFlavour.new_from_raw_data(point_molecules)
18 18
 
19 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 22
     def get_molecule(self, position, category, type, allow_empty=False):
23 23
         flavour = self.get_flavour(position)
@@ -34,8 +34,8 @@ class MoleculesManager():
34 34
             position_molecule = flavour.get_molecule(apposed_molecule.get_category(), apposed_molecule.get_type())
35 35
         except NoMolecule:
36 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 40
         position_molecule.increment_intensity(apposed_molecule.get_intensity())
41 41
 

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

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