Browse Source

Move pheromone appose in pheromone gland

Bastien Sevajol 9 years ago
parent
commit
ce1346d378

+ 4 - 10
intelligine/simulation/object/brain/part/AntMoveBrainPart.py View File

1
 from intelligine.simulation.object.brain.part.MoveBrainPart import MoveBrainPart
1
 from intelligine.simulation.object.brain.part.MoveBrainPart import MoveBrainPart
2
 from xyzworld.cst import POSITION
2
 from xyzworld.cst import POSITION
3
-from intelligine.core.exceptions import NoPheromone, BestPheromoneHere
3
+from intelligine.core.exceptions import NoPheromone
4
 from intelligine.cst import PHEROMONE_SEARCHING, MOVE_MODE_EXPLO, COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
4
 from intelligine.cst import PHEROMONE_SEARCHING, MOVE_MODE_EXPLO, COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
5
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
5
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
6
 
6
 
45
 
45
 
46
     def done(self, obj, context):
46
     def done(self, obj, context):
47
         super().done(obj, context)
47
         super().done(obj, context)
48
-        self._appose_pheromone(obj, context)
48
+        self._appose_pheromone(obj)
49
 
49
 
50
         # TEST: le temps de tout tester
50
         # TEST: le temps de tout tester
51
         if obj.get_position() == obj.get_colony().get_start_position() and obj.is_carrying():
51
         if obj.get_position() == obj.get_colony().get_start_position() and obj.is_carrying():
58
                                                  COL_TRANSPORTER_CARRYING)
58
                                                  COL_TRANSPORTER_CARRYING)
59
 
59
 
60
     @staticmethod
60
     @staticmethod
61
-    def _appose_pheromone(obj, context):
62
-        # TODO: Cette action de pheromone doit etre une surcharge de Move afin d'avoir une Action Move generique.
63
-        try:
64
-            DirectionPheromone.appose(context,
65
-                                      obj.get_position(),
66
-                                      obj.get_movement_pheromone_gland().get_movement_molecules())
67
-        except BestPheromoneHere as best_pheromone_here:
68
-            obj.get_brain().set_distance_from_objective(best_pheromone_here.get_best_distance())
61
+    def _appose_pheromone(obj):
62
+        obj.get_movement_pheromone_gland().appose()
69
 
63
 

+ 14 - 2
intelligine/simulation/object/pheromone/PheromoneGland.py View File

1
+from intelligine.core.exceptions import BestPheromoneHere
2
+from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
3
+
1
 class PheromoneGland():
4
 class PheromoneGland():
2
 
5
 
3
-    def __init__(self, host):
6
+    def __init__(self, host, context):
4
         self._pheromone_type = None
7
         self._pheromone_type = None
5
         self._host = host
8
         self._host = host
9
+        self._context = context
6
 
10
 
7
     def set_pheromone_type(self, pheromone_type):
11
     def set_pheromone_type(self, pheromone_type):
8
         self._pheromone_type = pheromone_type
12
         self._pheromone_type = pheromone_type
10
     def get_pheromone_type(self):
14
     def get_pheromone_type(self):
11
         if self._pheromone_type is None:
15
         if self._pheromone_type is None:
12
             raise Exception("pheromone_type not specified")
16
             raise Exception("pheromone_type not specified")
13
-        return self._pheromone_type
17
+        return self._pheromone_type
18
+
19
+    def appose(self):
20
+        try:
21
+            DirectionPheromone.appose(self._context,
22
+                                      self._host.get_position(),
23
+                                      self._host.get_movement_pheromone_gland().get_movement_molecules())
24
+        except BestPheromoneHere as best_pheromone_here:
25
+            self._host.get_brain().set_distance_from_objective(best_pheromone_here.get_best_distance())

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

20
                                                            COL_FIGHTER])
20
                                                            COL_FIGHTER])
21
         self._carried = []
21
         self._carried = []
22
         self._last_pheromones_points = {}
22
         self._last_pheromones_points = {}
23
-        self._movement_pheromone_gland = MovementPheromoneGland(self)
23
+        self._movement_pheromone_gland = MovementPheromoneGland(self, self._context)
24
         self._brain.switch_to_mode(MOVE_MODE_EXPLO)
24
         self._brain.switch_to_mode(MOVE_MODE_EXPLO)
25
 
25
 
26
     def _get_brain_instance(self):
26
     def _get_brain_instance(self):