Browse Source

Use meta information for pheromone searching

Bastien Sevajol 9 years ago
parent
commit
9e6b89ca7c

+ 1 - 0
intelligine/cst.py View File

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

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

1
 from intelligine.simulation.object.brain.Brain import Brain
1
 from intelligine.simulation.object.brain.Brain import Brain
2
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO
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
 class AntBrain(Brain):
6
 class AntBrain(Brain):
8
         super().__init__(context, host)
9
         super().__init__(context, host)
9
         self._movement_mode = MOVE_MODE_EXPLO
10
         self._movement_mode = MOVE_MODE_EXPLO
10
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
11
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
12
+        self._pheromone_searching = PHEROMON_DIR_EXPLO
11
 
13
 
12
     def switch_to_mode(self, mode):
14
     def switch_to_mode(self, mode):
13
         self._movement_mode = mode
15
         self._movement_mode = mode
14
         self._update_pheromone_gland(mode)
16
         self._update_pheromone_gland(mode)
15
         self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
17
         self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
16
         self._distance_from_objective = 0
18
         self._distance_from_objective = 0
19
+        self._update_pheromone_searching(mode)
17
 
20
 
18
     def _update_pheromone_gland(self, mode):
21
     def _update_pheromone_gland(self, mode):
19
         if mode == MOVE_MODE_EXPLO:
22
         if mode == MOVE_MODE_EXPLO:
24
             raise NotImplementedError()
27
             raise NotImplementedError()
25
         self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
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
     def get_movement_mode(self):
40
     def get_movement_mode(self):
28
         return self._movement_mode
41
         return self._movement_mode
29
 
42
 

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

10
 class DirectionPheromone():
10
 class DirectionPheromone():
11
 
11
 
12
     @staticmethod
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
     def appose(context, point, movement_molecules):
13
     def appose(context, point, movement_molecules):
22
         pheromone_type, distance_from = movement_molecules
14
         pheromone_type, distance_from = movement_molecules
23
         # TODO: Ajouter l'age de la pheromone !
15
         # TODO: Ajouter l'age de la pheromone !

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

2
 from intelligine.synergy.event.move.MoveEvent import MoveEvent
2
 from intelligine.synergy.event.move.MoveEvent import MoveEvent
3
 from random import randint, choice, randrange
3
 from random import randint, choice, randrange
4
 from xyzworld.cst import POSITION
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
 from intelligine.cst import COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
6
 from intelligine.cst import COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
7
 from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
7
 from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
8
 from intelligine.synergy.event.move.direction import get_position_with_direction_decal
8
 from intelligine.synergy.event.move.direction import get_position_with_direction_decal
36
             pass
36
             pass
37
 
37
 
38
     def _get_direction_with_pheromones(self, context, object_point):
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
         try:
40
         try:
42
             direction = self._get_pheromone_direction_for_point(context, object_point, pheromone_type)
41
             direction = self._get_pheromone_direction_for_point(context, object_point, pheromone_type)
43
         except NoPheromone:
42
         except NoPheromone:
119
     @staticmethod
118
     @staticmethod
120
     def _appose_pheromone(obj, context):
119
     def _appose_pheromone(obj, context):
121
         # TODO: Cette action de pheromone doit etre une surcharge de Move afin d'avoir une Action Move generique.
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
         try:
122
         try:
124
             DirectionPheromone.appose(context,
123
             DirectionPheromone.appose(context,
125
                                       obj.get_position(),
124
                                       obj.get_position(),