Browse Source

Use meta information for pheromone searching

Bastien Sevajol 9 years ago
parent
commit
9e6b89ca7c

+ 1 - 0
intelligine/cst.py View File

@@ -14,6 +14,7 @@ CARRYING = IncrementedNamedInt.get('intelligine.carrying')
14 14
 CANT_CARRY_STILL = IncrementedNamedInt.get('intelligine.cantcarry.still')
15 15
 CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
16 16
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
17
+PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.pheromone_searching')
17 18
 
18 19
 MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
19 20
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')

+ 13 - 0
intelligine/simulation/object/brain/AntBrain.py View File

@@ -1,5 +1,6 @@
1 1
 from intelligine.simulation.object.brain.Brain import Brain
2 2
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO
3
+from intelligine.cst import PHEROMONE_SEARCHING
3 4
 
4 5
 
5 6
 class AntBrain(Brain):
@@ -8,12 +9,14 @@ class AntBrain(Brain):
8 9
         super().__init__(context, host)
9 10
         self._movement_mode = MOVE_MODE_EXPLO
10 11
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
12
+        self._pheromone_searching = PHEROMON_DIR_EXPLO
11 13
 
12 14
     def switch_to_mode(self, mode):
13 15
         self._movement_mode = mode
14 16
         self._update_pheromone_gland(mode)
15 17
         self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
16 18
         self._distance_from_objective = 0
19
+        self._update_pheromone_searching(mode)
17 20
 
18 21
     def _update_pheromone_gland(self, mode):
19 22
         if mode == MOVE_MODE_EXPLO:
@@ -24,6 +27,16 @@ class AntBrain(Brain):
24 27
             raise NotImplementedError()
25 28
         self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
26 29
 
30
+    def _update_pheromone_searching(self, mode):
31
+        if mode == MOVE_MODE_EXPLO:
32
+            pheromone_searching = PHEROMON_DIR_EXPLO
33
+        elif mode == MOVE_MODE_GOHOME:
34
+            pheromone_searching = PHEROMON_DIR_HOME
35
+        else:
36
+            raise NotImplementedError()
37
+        self._pheromone_searching = pheromone_searching
38
+        self._context.metas.value.set(PHEROMONE_SEARCHING, self._host.get_id(), pheromone_searching)
39
+
27 40
     def get_movement_mode(self):
28 41
         return self._movement_mode
29 42
 

+ 0 - 8
intelligine/simulation/pheromone/DirectionPheromone.py View File

@@ -10,14 +10,6 @@ from intelligine.synergy.event.move.direction import get_direction_for_degrees
10 10
 class DirectionPheromone():
11 11
 
12 12
     @staticmethod
13
-    def get_pheromone_type_for_move_mode(move_mode):
14
-        if move_mode == MOVE_MODE_EXPLO:
15
-            return PHEROMON_DIR_EXPLO
16
-        if move_mode == MOVE_MODE_GOHOME:
17
-            return PHEROMON_DIR_HOME
18
-        raise NotImplementedError()
19
-
20
-    @staticmethod
21 13
     def appose(context, point, movement_molecules):
22 14
         pheromone_type, distance_from = movement_molecules
23 15
         # TODO: Ajouter l'age de la pheromone !

+ 3 - 4
intelligine/synergy/event/move/MoveAction.py View File

@@ -2,7 +2,7 @@ from synergine.synergy.event.Action import Action
2 2
 from intelligine.synergy.event.move.MoveEvent import MoveEvent
3 3
 from random import randint, choice, randrange
4 4
 from xyzworld.cst import POSITION
5
-from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE, MOVE_MODE, MOVE_MODE_EXPLO
5
+from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE, MOVE_MODE, MOVE_MODE_EXPLO, PHEROMONE_SEARCHING
6 6
 from intelligine.cst import COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
7 7
 from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
8 8
 from intelligine.synergy.event.move.direction import get_position_with_direction_decal
@@ -36,8 +36,7 @@ class MoveAction(Action):
36 36
             pass
37 37
 
38 38
     def _get_direction_with_pheromones(self, context, object_point):
39
-        object_movement_mode = context.metas.value.get(MOVE_MODE, self._object_id)
40
-        pheromone_type = DirectionPheromone.get_pheromone_type_for_move_mode(object_movement_mode)
39
+        pheromone_type = context.metas.value.get(PHEROMONE_SEARCHING, self._object_id)
41 40
         try:
42 41
             direction = self._get_pheromone_direction_for_point(context, object_point, pheromone_type)
43 42
         except NoPheromone:
@@ -119,7 +118,7 @@ class MoveAction(Action):
119 118
     @staticmethod
120 119
     def _appose_pheromone(obj, context):
121 120
         # TODO: Cette action de pheromone doit etre une surcharge de Move afin d'avoir une Action Move generique.
122
-        obj.get_brain().host_moved()
121
+        obj.get_brain().host_moved()  # TODO: Auto quand set_position ? (test iit)
123 122
         try:
124 123
             DirectionPheromone.appose(context,
125 124
                                       obj.get_position(),