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,6 +1,6 @@
1 1
 from intelligine.simulation.object.brain.part.MoveBrainPart import MoveBrainPart
2 2
 from xyzworld.cst import POSITION
3
-from intelligine.core.exceptions import NoPheromone, BestPheromoneHere
3
+from intelligine.core.exceptions import NoPheromone
4 4
 from intelligine.cst import PHEROMONE_SEARCHING, MOVE_MODE_EXPLO, COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
5 5
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
6 6
 
@@ -45,7 +45,7 @@ class AntMoveBrainPart(MoveBrainPart):
45 45
 
46 46
     def done(self, obj, context):
47 47
         super().done(obj, context)
48
-        self._appose_pheromone(obj, context)
48
+        self._appose_pheromone(obj)
49 49
 
50 50
         # TEST: le temps de tout tester
51 51
         if obj.get_position() == obj.get_colony().get_start_position() and obj.is_carrying():
@@ -58,12 +58,6 @@ class AntMoveBrainPart(MoveBrainPart):
58 58
                                                  COL_TRANSPORTER_CARRYING)
59 59
 
60 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,8 +1,12 @@
1
+from intelligine.core.exceptions import BestPheromoneHere
2
+from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
3
+
1 4
 class PheromoneGland():
2 5
 
3
-    def __init__(self, host):
6
+    def __init__(self, host, context):
4 7
         self._pheromone_type = None
5 8
         self._host = host
9
+        self._context = context
6 10
 
7 11
     def set_pheromone_type(self, pheromone_type):
8 12
         self._pheromone_type = pheromone_type
@@ -10,4 +14,12 @@ class PheromoneGland():
10 14
     def get_pheromone_type(self):
11 15
         if self._pheromone_type is None:
12 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,7 +20,7 @@ class Ant(Bug):
20 20
                                                            COL_FIGHTER])
21 21
         self._carried = []
22 22
         self._last_pheromones_points = {}
23
-        self._movement_pheromone_gland = MovementPheromoneGland(self)
23
+        self._movement_pheromone_gland = MovementPheromoneGland(self, self._context)
24 24
         self._brain.switch_to_mode(MOVE_MODE_EXPLO)
25 25
 
26 26
     def _get_brain_instance(self):