Browse Source

Working on smell

Bastien Sevajol 9 years ago
parent
commit
02f0a85e93

+ 2 - 0
TODO View File

1
 * Fourmis (map.tmx) pas en mode nurse (-> algo de choix d'activité plus tard)
1
 * Fourmis (map.tmx) pas en mode nurse (-> algo de choix d'activité plus tard)
2
 * Pygame: smell, pheromons: rendre + generique
2
 * Pygame: smell, pheromons: rendre + generique
3
 * Smell: Calcul de la distance max
3
 * Smell: Calcul de la distance max
4
+* Ant: MOVE_MODE_HOME && rien à faire (pas de truc à stocker, switch to mode EXPLO)
5
+* Plus de pheromone deposer a l'explo !

+ 3 - 0
intelligine/cst.py View File

20
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
20
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
21
 MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
21
 MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
22
 MOVE_MODE_NURSE = IncrementedNamedInt.get('intelligine.basebug.move.mode.nurse')
22
 MOVE_MODE_NURSE = IncrementedNamedInt.get('intelligine.basebug.move.mode.nurse')
23
+MOVE_MODE_HOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.home')
23
 
24
 
24
 TYPE = IncrementedNamedInt.get('intelligine.object.type')
25
 TYPE = IncrementedNamedInt.get('intelligine.object.type')
25
 TYPE_RESOURCE_EXPLOITABLE = IncrementedNamedInt.get('intelligine.object.type.resource.transformable')
26
 TYPE_RESOURCE_EXPLOITABLE = IncrementedNamedInt.get('intelligine.object.type.resource.transformable')
32
 PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
33
 PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
33
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
34
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
34
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
35
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
36
+EXPLORATION_VECTOR = IncrementedNamedInt.get('intelligine.exploration_vector')
35
 
37
 
38
+SMELL = IncrementedNamedInt.get('intelligine.smell')
36
 OBJ_SMELL = IncrementedNamedInt.get('intelligine.obj_smell')
39
 OBJ_SMELL = IncrementedNamedInt.get('intelligine.obj_smell')
37
 SMELL_FOOD = IncrementedNamedInt.get('intelligine.smell.food')
40
 SMELL_FOOD = IncrementedNamedInt.get('intelligine.smell.food')
38
 SMELL_EGG = IncrementedNamedInt.get('intelligine.smell.egg')
41
 SMELL_EGG = IncrementedNamedInt.get('intelligine.smell.egg')

+ 46 - 46
intelligine/sandbox/exploration/map.tmx View File

311
    <tile gid="241"/>
311
    <tile gid="241"/>
312
    <tile gid="241"/>
312
    <tile gid="241"/>
313
    <tile gid="241"/>
313
    <tile gid="241"/>
314
+   <tile gid="243"/>
314
    <tile gid="0"/>
315
    <tile gid="0"/>
315
    <tile gid="0"/>
316
    <tile gid="0"/>
316
    <tile gid="0"/>
317
    <tile gid="0"/>
329
    <tile gid="0"/>
330
    <tile gid="0"/>
330
    <tile gid="0"/>
331
    <tile gid="0"/>
331
    <tile gid="0"/>
332
    <tile gid="0"/>
332
-   <tile gid="0"/>
333
-   <tile gid="0"/>
333
+   <tile gid="242"/>
334
    <tile gid="0"/>
334
    <tile gid="0"/>
335
    <tile gid="0"/>
335
    <tile gid="0"/>
336
    <tile gid="0"/>
336
    <tile gid="0"/>
513
    <tile gid="241"/>
513
    <tile gid="241"/>
514
    <tile gid="0"/>
514
    <tile gid="0"/>
515
    <tile gid="0"/>
515
    <tile gid="0"/>
516
+   <tile gid="1"/>
516
    <tile gid="0"/>
517
    <tile gid="0"/>
517
    <tile gid="0"/>
518
    <tile gid="0"/>
518
    <tile gid="0"/>
519
    <tile gid="0"/>
529
    <tile gid="0"/>
530
    <tile gid="0"/>
530
    <tile gid="0"/>
531
    <tile gid="0"/>
531
    <tile gid="0"/>
532
    <tile gid="0"/>
532
-   <tile gid="0"/>
533
-   <tile gid="0"/>
533
+   <tile gid="242"/>
534
    <tile gid="0"/>
534
    <tile gid="0"/>
535
    <tile gid="0"/>
535
    <tile gid="0"/>
536
    <tile gid="0"/>
536
    <tile gid="0"/>
730
    <tile gid="0"/>
730
    <tile gid="0"/>
731
    <tile gid="0"/>
731
    <tile gid="0"/>
732
    <tile gid="0"/>
732
    <tile gid="0"/>
733
-   <tile gid="0"/>
733
+   <tile gid="242"/>
734
    <tile gid="0"/>
734
    <tile gid="0"/>
735
    <tile gid="0"/>
735
    <tile gid="0"/>
736
    <tile gid="0"/>
736
    <tile gid="0"/>
930
    <tile gid="0"/>
930
    <tile gid="0"/>
931
    <tile gid="0"/>
931
    <tile gid="0"/>
932
    <tile gid="0"/>
932
    <tile gid="0"/>
933
-   <tile gid="0"/>
933
+   <tile gid="242"/>
934
    <tile gid="0"/>
934
    <tile gid="0"/>
935
    <tile gid="0"/>
935
    <tile gid="0"/>
936
    <tile gid="0"/>
936
    <tile gid="0"/>
1126
    <tile gid="0"/>
1126
    <tile gid="0"/>
1127
    <tile gid="0"/>
1127
    <tile gid="0"/>
1128
    <tile gid="0"/>
1128
    <tile gid="0"/>
1129
-   <tile gid="0"/>
1129
+   <tile gid="242"/>
1130
    <tile gid="0"/>
1130
    <tile gid="0"/>
1131
    <tile gid="0"/>
1131
    <tile gid="0"/>
1132
    <tile gid="242"/>
1132
    <tile gid="242"/>
1327
    <tile gid="0"/>
1327
    <tile gid="0"/>
1328
    <tile gid="0"/>
1328
    <tile gid="0"/>
1329
    <tile gid="0"/>
1329
    <tile gid="0"/>
1330
-   <tile gid="0"/>
1330
+   <tile gid="242"/>
1331
    <tile gid="0"/>
1331
    <tile gid="0"/>
1332
    <tile gid="0"/>
1332
    <tile gid="0"/>
1333
    <tile gid="0"/>
1333
    <tile gid="0"/>
1528
    <tile gid="0"/>
1528
    <tile gid="0"/>
1529
    <tile gid="0"/>
1529
    <tile gid="0"/>
1530
    <tile gid="0"/>
1530
    <tile gid="0"/>
1531
-   <tile gid="0"/>
1531
+   <tile gid="242"/>
1532
    <tile gid="0"/>
1532
    <tile gid="0"/>
1533
    <tile gid="0"/>
1533
    <tile gid="0"/>
1534
    <tile gid="0"/>
1534
    <tile gid="0"/>
2123
    <tile gid="0"/>
2123
    <tile gid="0"/>
2124
    <tile gid="0"/>
2124
    <tile gid="0"/>
2125
    <tile gid="0"/>
2125
    <tile gid="0"/>
2126
-   <tile gid="0"/>
2126
+   <tile gid="242"/>
2127
    <tile gid="0"/>
2127
    <tile gid="0"/>
2128
    <tile gid="0"/>
2128
    <tile gid="0"/>
2129
    <tile gid="0"/>
2129
    <tile gid="0"/>
2312
    <tile gid="241"/>
2312
    <tile gid="241"/>
2313
    <tile gid="241"/>
2313
    <tile gid="241"/>
2314
    <tile gid="0"/>
2314
    <tile gid="0"/>
2315
+   <tile gid="242"/>
2315
    <tile gid="0"/>
2316
    <tile gid="0"/>
2317
+   <tile gid="242"/>
2316
    <tile gid="0"/>
2318
    <tile gid="0"/>
2319
+   <tile gid="242"/>
2317
    <tile gid="0"/>
2320
    <tile gid="0"/>
2321
+   <tile gid="242"/>
2318
    <tile gid="0"/>
2322
    <tile gid="0"/>
2319
-   <tile gid="0"/>
2320
-   <tile gid="0"/>
2321
-   <tile gid="0"/>
2322
-   <tile gid="0"/>
2323
-   <tile gid="0"/>
2323
+   <tile gid="242"/>
2324
    <tile gid="0"/>
2324
    <tile gid="0"/>
2325
    <tile gid="242"/>
2325
    <tile gid="242"/>
2326
    <tile gid="0"/>
2326
    <tile gid="0"/>
2425
    <tile gid="0"/>
2425
    <tile gid="0"/>
2426
    <tile gid="242"/>
2426
    <tile gid="242"/>
2427
    <tile gid="0"/>
2427
    <tile gid="0"/>
2428
-   <tile gid="241"/>
2429
-   <tile gid="241"/>
2430
-   <tile gid="241"/>
2431
-   <tile gid="241"/>
2432
-   <tile gid="241"/>
2433
-   <tile gid="241"/>
2434
    <tile gid="0"/>
2428
    <tile gid="0"/>
2435
-   <tile gid="241"/>
2429
+   <tile gid="0"/>
2430
+   <tile gid="0"/>
2431
+   <tile gid="0"/>
2432
+   <tile gid="0"/>
2433
+   <tile gid="0"/>
2434
+   <tile gid="0"/>
2435
+   <tile gid="0"/>
2436
    <tile gid="0"/>
2436
    <tile gid="0"/>
2437
    <tile gid="0"/>
2437
    <tile gid="0"/>
2438
    <tile gid="0"/>
2438
    <tile gid="0"/>
2525
    <tile gid="0"/>
2525
    <tile gid="0"/>
2526
    <tile gid="0"/>
2526
    <tile gid="0"/>
2527
    <tile gid="0"/>
2527
    <tile gid="0"/>
2528
-   <tile gid="241"/>
2529
-   <tile gid="243"/>
2530
    <tile gid="0"/>
2528
    <tile gid="0"/>
2531
    <tile gid="0"/>
2529
    <tile gid="0"/>
2532
    <tile gid="0"/>
2530
    <tile gid="0"/>
2533
-   <tile gid="241"/>
2534
    <tile gid="0"/>
2531
    <tile gid="0"/>
2535
-   <tile gid="241"/>
2532
+   <tile gid="0"/>
2533
+   <tile gid="0"/>
2534
+   <tile gid="0"/>
2535
+   <tile gid="0"/>
2536
    <tile gid="0"/>
2536
    <tile gid="0"/>
2537
    <tile gid="0"/>
2537
    <tile gid="0"/>
2538
    <tile gid="0"/>
2538
    <tile gid="0"/>
2625
    <tile gid="0"/>
2625
    <tile gid="0"/>
2626
    <tile gid="0"/>
2626
    <tile gid="0"/>
2627
    <tile gid="0"/>
2627
    <tile gid="0"/>
2628
-   <tile gid="241"/>
2629
    <tile gid="0"/>
2628
    <tile gid="0"/>
2630
    <tile gid="0"/>
2629
    <tile gid="0"/>
2631
    <tile gid="0"/>
2630
    <tile gid="0"/>
2632
    <tile gid="0"/>
2631
    <tile gid="0"/>
2633
-   <tile gid="241"/>
2634
    <tile gid="0"/>
2632
    <tile gid="0"/>
2635
-   <tile gid="241"/>
2633
+   <tile gid="0"/>
2634
+   <tile gid="0"/>
2635
+   <tile gid="0"/>
2636
    <tile gid="0"/>
2636
    <tile gid="0"/>
2637
    <tile gid="0"/>
2637
    <tile gid="0"/>
2638
    <tile gid="0"/>
2638
    <tile gid="0"/>
2725
    <tile gid="0"/>
2725
    <tile gid="0"/>
2726
    <tile gid="0"/>
2726
    <tile gid="0"/>
2727
    <tile gid="0"/>
2727
    <tile gid="0"/>
2728
-   <tile gid="241"/>
2729
    <tile gid="0"/>
2728
    <tile gid="0"/>
2730
    <tile gid="0"/>
2729
    <tile gid="0"/>
2731
-   <tile gid="1"/>
2732
    <tile gid="0"/>
2730
    <tile gid="0"/>
2733
-   <tile gid="241"/>
2734
    <tile gid="0"/>
2731
    <tile gid="0"/>
2735
-   <tile gid="241"/>
2732
+   <tile gid="0"/>
2733
+   <tile gid="0"/>
2734
+   <tile gid="0"/>
2735
+   <tile gid="0"/>
2736
    <tile gid="0"/>
2736
    <tile gid="0"/>
2737
    <tile gid="0"/>
2737
    <tile gid="0"/>
2738
    <tile gid="0"/>
2738
    <tile gid="0"/>
2825
    <tile gid="0"/>
2825
    <tile gid="0"/>
2826
    <tile gid="0"/>
2826
    <tile gid="0"/>
2827
    <tile gid="0"/>
2827
    <tile gid="0"/>
2828
-   <tile gid="241"/>
2829
    <tile gid="0"/>
2828
    <tile gid="0"/>
2830
    <tile gid="0"/>
2829
    <tile gid="0"/>
2831
    <tile gid="0"/>
2830
    <tile gid="0"/>
2832
    <tile gid="0"/>
2831
    <tile gid="0"/>
2833
-   <tile gid="241"/>
2834
    <tile gid="0"/>
2832
    <tile gid="0"/>
2835
-   <tile gid="241"/>
2833
+   <tile gid="0"/>
2834
+   <tile gid="0"/>
2835
+   <tile gid="0"/>
2836
    <tile gid="0"/>
2836
    <tile gid="0"/>
2837
    <tile gid="0"/>
2837
    <tile gid="0"/>
2838
    <tile gid="0"/>
2838
    <tile gid="0"/>
2925
    <tile gid="0"/>
2925
    <tile gid="0"/>
2926
    <tile gid="0"/>
2926
    <tile gid="0"/>
2927
    <tile gid="0"/>
2927
    <tile gid="0"/>
2928
-   <tile gid="241"/>
2929
    <tile gid="0"/>
2928
    <tile gid="0"/>
2930
    <tile gid="0"/>
2929
    <tile gid="0"/>
2931
    <tile gid="0"/>
2930
    <tile gid="0"/>
2932
    <tile gid="0"/>
2931
    <tile gid="0"/>
2933
    <tile gid="0"/>
2932
    <tile gid="0"/>
2934
    <tile gid="0"/>
2933
    <tile gid="0"/>
2935
-   <tile gid="241"/>
2934
+   <tile gid="0"/>
2935
+   <tile gid="0"/>
2936
    <tile gid="0"/>
2936
    <tile gid="0"/>
2937
    <tile gid="0"/>
2937
    <tile gid="0"/>
2938
    <tile gid="0"/>
2938
    <tile gid="0"/>
3025
    <tile gid="0"/>
3025
    <tile gid="0"/>
3026
    <tile gid="0"/>
3026
    <tile gid="0"/>
3027
    <tile gid="0"/>
3027
    <tile gid="0"/>
3028
-   <tile gid="241"/>
3029
-   <tile gid="241"/>
3030
-   <tile gid="241"/>
3031
-   <tile gid="241"/>
3032
-   <tile gid="241"/>
3033
-   <tile gid="241"/>
3034
-   <tile gid="241"/>
3035
-   <tile gid="241"/>
3028
+   <tile gid="0"/>
3029
+   <tile gid="0"/>
3030
+   <tile gid="0"/>
3031
+   <tile gid="0"/>
3032
+   <tile gid="0"/>
3033
+   <tile gid="0"/>
3034
+   <tile gid="0"/>
3035
+   <tile gid="0"/>
3036
    <tile gid="0"/>
3036
    <tile gid="0"/>
3037
    <tile gid="0"/>
3037
    <tile gid="0"/>
3038
    <tile gid="0"/>
3038
    <tile gid="0"/>

+ 7 - 2
intelligine/simulation/object/brain/AntBrain.py View File

2
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
2
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
3
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
3
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
4
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, \
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
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
6
 from intelligine.cst import PHEROMONE_SEARCHING
7
 from intelligine.cst import BRAIN_PART_MOVE
7
 from intelligine.cst import BRAIN_PART_MOVE
8
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
8
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
21
 
21
 
22
     def __init__(self, context, host):
22
     def __init__(self, context, host):
23
         super().__init__(context, host)
23
         super().__init__(context, host)
24
-        self._movement_mode = MOVE_MODE_EXPLO
24
+        self._movement_mode = MOVE_MODE_HOME
25
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
25
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
26
         self._pheromone_searching = PHEROMON_DIR_EXPLO
26
         self._pheromone_searching = PHEROMON_DIR_EXPLO
27
 
27
 
28
     def switch_to_mode(self, mode):
28
     def switch_to_mode(self, mode):
29
+        # TODO: Mode explo: reinit exploration vector
29
         self._movement_mode = mode
30
         self._movement_mode = mode
30
         self._update_pheromone_gland(mode)
31
         self._update_pheromone_gland(mode)
31
         self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
32
         self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
39
             pheromone_direction_type = PHEROMON_DIR_EXPLO
40
             pheromone_direction_type = PHEROMON_DIR_EXPLO
40
         elif mode == MOVE_MODE_NURSE:
41
         elif mode == MOVE_MODE_NURSE:
41
             pheromone_direction_type = None
42
             pheromone_direction_type = None
43
+        elif mode == MOVE_MODE_HOME:
44
+            pheromone_direction_type = None
42
         else:
45
         else:
43
             raise NotImplementedError()
46
             raise NotImplementedError()
44
 
47
 
55
             pheromone_searching = PHEROMON_DIR_HOME
58
             pheromone_searching = PHEROMON_DIR_HOME
56
         elif mode == MOVE_MODE_NURSE:
59
         elif mode == MOVE_MODE_NURSE:
57
             pheromone_searching = PHEROMON_DIR_NONE
60
             pheromone_searching = PHEROMON_DIR_NONE
61
+        elif mode == MOVE_MODE_HOME:
62
+            return
58
         else:
63
         else:
59
             raise NotImplementedError()
64
             raise NotImplementedError()
60
         self._pheromone_searching = pheromone_searching
65
         self._pheromone_searching = pheromone_searching

+ 6 - 0
intelligine/simulation/object/brain/Brain.py View File

33
         # TODO: N'est-ce pas un schema appartenant a la classe ? Ne suffirai t-il pas de stocker ce schema par classe
33
         # TODO: N'est-ce pas un schema appartenant a la classe ? Ne suffirai t-il pas de stocker ce schema par classe
34
         # plutôt que par objet ?
34
         # plutôt que par objet ?
35
         self._context.metas.value.set(BRAIN_SCHEMA, self._host.get_id(), self._schema)
35
         self._context.metas.value.set(BRAIN_SCHEMA, self._host.get_id(), self._schema)
36
+
37
+    def get_context(self):
38
+        return self._context
39
+
40
+    def get_host(self):
41
+        return self._host

+ 83 - 5
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py View File

1
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
1
 from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
2
+from intelligine.synergy.event.move.direction import directions_modifiers, get_direction_for_degrees
2
 from synergine_xyz.cst import POSITION
3
 from synergine_xyz.cst import POSITION
3
 from intelligine.core.exceptions import NoPheromone
4
 from intelligine.core.exceptions import NoPheromone
4
-from intelligine.cst import PHEROMONE_SEARCHING, MOVE_MODE_EXPLO, COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
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.simulation.pheromone.DirectionPheromone import DirectionPheromone
7
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
8
+from synergine_xyz.geometry import get_degree_from_north
6
 
9
 
7
 
10
 
8
 class AntMoveBrainPart(MoveBrainPart):
11
 class AntMoveBrainPart(MoveBrainPart):
9
 
12
 
13
+    def __init__(self, host_brain):
14
+        super().__init__(host_brain)
15
+        self._exploration_vector = (0, 0)
16
+
17
+    def _set_exploration_vector(self, new_vector):
18
+        self._exploration_vector = new_vector
19
+        # TODO: On devrais donner le context aux brain parts
20
+        self._host_brain.get_context().metas.value.set(EXPLORATION_VECTOR,
21
+                                                       self._host_brain.get_host().get_id(),
22
+                                                       new_vector)
23
+
10
     @classmethod
24
     @classmethod
11
     def get_direction(cls, context, object_id):
25
     def get_direction(cls, context, object_id):
12
-        try:
13
-            return cls._get_direction_with_pheromones(context, object_id)
14
-        except NoPheromone:
15
-            return super().get_direction(context, object_id)
26
+        move_mode = context.metas.value.get(MOVE_MODE, object_id)
27
+        if move_mode == MOVE_MODE_EXPLO:
28
+            try:
29
+                return cls._get_direction_with_pheromones(context, object_id)
30
+            except NoPheromone:
31
+                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
+
35
+        return super().get_direction(context, object_id)
16
 
36
 
17
     @classmethod
37
     @classmethod
18
     def _get_direction_with_pheromones(cls, context, object_id):
38
     def _get_direction_with_pheromones(cls, context, object_id):
43
         except NoPheromone as err:
63
         except NoPheromone as err:
44
             raise err
64
             raise err
45
 
65
 
66
+    @staticmethod
67
+    def _get_direction_with_exploration_vector(context, object_id):
68
+        current_position = context.metas.value.get(POSITION, object_id)
69
+        exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
70
+        # TODO: inverser
71
+        home_vector = (exploration_vector[0] - (exploration_vector[0]*2),
72
+                       exploration_vector[1] - (exploration_vector[1]*2))
73
+        home_position = (0, current_position[1]+home_vector[0], current_position[2]+home_vector[1])
74
+        degree_from_north = get_degree_from_north(current_position, home_position)
75
+        direction_for_home_vector = get_direction_for_degrees(degree_from_north)
76
+
77
+        return direction_for_home_vector
78
+
79
+    # TODO: obj pas necessaire, il est dans _host
46
     def done(self, obj, context):
80
     def done(self, obj, context):
47
         super().done(obj, context)
81
         super().done(obj, context)
48
         self._appose_pheromone(obj)
82
         self._appose_pheromone(obj)
83
+        self._check_context(obj, context)
84
+        self._apply_context(obj, context)
49
 
85
 
50
     @staticmethod
86
     @staticmethod
51
     def _appose_pheromone(obj):
87
     def _appose_pheromone(obj):
52
         if obj.get_movement_pheromone_gland().is_enabled():
88
         if obj.get_movement_pheromone_gland().is_enabled():
53
             obj.get_movement_pheromone_gland().appose()
89
             obj.get_movement_pheromone_gland().appose()
54
 
90
 
91
+    def _check_context(self, obj, context):
92
+        """
93
+
94
+        If was in exploration, and just found home smell;
95
+            -> home mode (then, in this mode: no update vector, put food if food, etc)
96
+        If was in home, and just loose home smell:
97
+            -> exploration mode
98
+
99
+        :param obj:
100
+        :param context:
101
+        :return:
102
+        """
103
+        if self._host_brain.get_movement_mode() == MOVE_MODE_EXPLO and self._on_home_smell(context, obj.get_id()):
104
+            self._host_brain.switch_to_mode(MOVE_MODE_HOME)
105
+
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)
108
+            self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
109
+            self._start_new_exploration()
110
+
111
+    @classmethod
112
+    def _on_home_smell(cls, context, object_id):
113
+        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
117
+        return False
118
+
119
+    def _update_exploration_vector(self):
120
+        # TODO: add tuple as vectors ?
121
+        just_move_vector = directions_modifiers[self._host_brain.get_host().get_previous_direction()]
122
+        self._set_exploration_vector((self._exploration_vector[0] + just_move_vector[1],
123
+                                      self._exploration_vector[1] + just_move_vector[2]))
124
+
125
+
126
+    def _apply_context(self, obj, context):
127
+        movement_mode = self._host_brain.get_movement_mode()
128
+        if movement_mode == MOVE_MODE_EXPLO or movement_mode == MOVE_MODE_GOHOME:
129
+            self._update_exploration_vector()
130
+
131
+    def _start_new_exploration(self):
132
+        self._exploration_vector = (0, 0)

+ 1 - 1
intelligine/simulation/object/pheromone/MovementPheromoneGland.py View File

7
 
7
 
8
     def get_pheromone(self):
8
     def get_pheromone(self):
9
         """
9
         """
10
-        :return: pheromone_type, distance_from_objective
10
+        :return: Pheromone
11
         """
11
         """
12
         return Pheromone(PHEROMON_DIRECTION, self._pheromone_type, self._host.get_brain().get_distance_from_objective(), 1)
12
         return Pheromone(PHEROMON_DIRECTION, self._pheromone_type, self._host.get_brain().get_distance_from_objective(), 1)

+ 2 - 1
intelligine/synergy/event/move/direction.py View File

117
     (202.5, 247.5): 16,
117
     (202.5, 247.5): 16,
118
     (247.5, 292.5): 13,
118
     (247.5, 292.5): 13,
119
     (292.5, 337.5): 10,
119
     (292.5, 337.5): 10,
120
+    (337.5, 360): 11,
120
     (337.5, 0): 11
121
     (337.5, 0): 11
121
 }
122
 }
122
 
123
 
127
     for plage in directions_degrees:
128
     for plage in directions_degrees:
128
         if plage[0] <= degrees <= plage[1]:
129
         if plage[0] <= degrees <= plage[1]:
129
             return directions_degrees[plage]
130
             return directions_degrees[plage]
130
-    raise Exception("Unknow plage for degree \"" + degrees + '"')
131
+    raise Exception("Unknow plage for degree \"" + str(degrees) + '"')
131
 
132
 
132
 
133
 
133
 """
134
 """

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

2
 from intelligine.synergy.object.Bug import Bug
2
 from intelligine.synergy.object.Bug import Bug
3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4
     COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
4
     COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5
-    COL_TRANSPORTER_CARRYING, MOVE_MODE_NURSE
5
+    COL_TRANSPORTER_CARRYING, MOVE_MODE_NURSE, MOVE_MODE_HOME
6
 from intelligine.synergy.object.Food import Food
6
 from intelligine.synergy.object.Food import Food
7
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
7
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
21
                                                            COL_TRANSPORTER_NOT_CARRYING,
21
                                                            COL_TRANSPORTER_NOT_CARRYING,
22
                                                            COL_FIGHTER])
22
                                                            COL_FIGHTER])
23
         self._carried = None
23
         self._carried = None
24
-        self._brain.switch_to_mode(MOVE_MODE_EXPLO)
24
+        self._brain.switch_to_mode(MOVE_MODE_HOME)
25
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
25
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
26
 
26
 
27
     def die(self):
27
     def die(self):