Browse Source

update code of egg missions

Bastien Sevajol 9 years ago
parent
commit
f50c04d9ac

+ 1 - 0
TODO View File

@@ -8,6 +8,7 @@ TODO:
8 8
 
9 9
  * Mechanisme qui donne les pheromones around ?
10 10
  * Appliquer la disparition des pheromones
11
+ * Les move mode sont arbitraire. On sais (cf. livre Ameisen) qu'elles se spécialisent avec l'expérience de reussite/echec. Voir coment implémenter ça !
11 12
 
12 13
 Future:
13 14
  * Chambres

+ 2 - 2
config.py View File

@@ -2,9 +2,9 @@ from intelligine.core.Context import Context
2 2
 from intelligine.synergy.Simulation import Simulation
3 3
 from intelligine.display.Pygame import Pygame
4 4
 from intelligine.display.pygame.visualisation import visualisation as pygame_visualisation
5
-#from intelligine.sandbox.colored.colors_colonys import collections
5
+from intelligine.sandbox.colored.colors_colonys import collections
6 6
 # TODO: influencer avec argument python
7
-from intelligine.sandbox.exploration.collections import collections
7
+#from intelligine.sandbox.exploration.collections import collections
8 8
 
9 9
 """
10 10
  TODO:

+ 3 - 0
intelligine/core/exceptions.py View File

@@ -42,6 +42,9 @@ class BestPheromoneHere(PheromoneException):
42 42
     def get_best_distance(self):
43 43
         return self._best_distance
44 44
 
45
+class PheromoneGlandDisabled(PheromoneException):
46
+    pass
47
+
45 48
 
46 49
 class BrainException(Exception):
47 50
     pass

+ 4 - 0
intelligine/cst.py View File

@@ -15,18 +15,22 @@ CANT_PUT_STILL = IncrementedNamedInt.get('intelligine.cantput.still')
15 15
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
16 16
 PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.pheromone_searching')
17 17
 
18
+# TODO: Renommer "move_mode" en "mode"
18 19
 MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
19 20
 MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
20 21
 MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
22
+MOVE_MODE_NURSE = IncrementedNamedInt.get('intelligine.basebug.move.mode.nurse')
21 23
 
22 24
 TYPE = IncrementedNamedInt.get('intelligine.object.type')
23 25
 TYPE_RESOURCE_TRANSFORMABLE = IncrementedNamedInt.get('intelligine.object.type.resource.transformable')
26
+TYPE_NURSERY = IncrementedNamedInt.get('intelligine.object.type.nursery')
24 27
 
25 28
 LAST_PHERMONES_POINTS = IncrementedNamedInt.get('intelligine.last_pheromones_points')
26 29
 
27 30
 PHEROMON_POSITIONS = IncrementedNamedInt.get('intelligine.phero.positions')
28 31
 PHEROMON_INFOS = IncrementedNamedInt.get('intelligine.phero.infos')
29 32
 PHEROMON_DIRECTION = IncrementedNamedInt.get('intelligine.phero.direction')
33
+PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
30 34
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
31 35
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
32 36
 

+ 5 - 1
intelligine/sandbox/colored/RedColonyConfiguration.py View File

@@ -1,17 +1,21 @@
1 1
 from intelligine.synergy.ColonyConfiguration import ColonyConfiguration
2 2
 from intelligine.sandbox.colored.RedAnt import RedAnt
3 3
 from intelligine.synergy.object.ant.Egg import Egg
4
-from intelligine.cst import COLONY
4
+from intelligine.cst import COLONY, MOVE_MODE_NURSE
5 5
 
6 6
 
7 7
 class RedColonyConfiguration(ColonyConfiguration):
8 8
 
9 9
     _start_position = (0, 20, 70)
10 10
     _ant_class = RedAnt
11
+    _ant_count = 50
11 12
 
12 13
     def get_start_objects(self, collection, context):
13 14
         objects = super().get_start_objects(collection, context)
14 15
 
16
+        for ant in objects:
17
+            ant._brain.switch_to_mode(MOVE_MODE_NURSE)
18
+
15 19
         for x in range(50):
16 20
           for y in range(1, 50):
17 21
             if x % 3 == 0 and y % 3 == 0:

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

@@ -1,7 +1,7 @@
1 1
 from intelligine.simulation.object.brain.Brain import Brain
2 2
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
3 3
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, \
4
-    BRAIN_PART_TAKE, BRAIN_PART_PUT
4
+    BRAIN_PART_TAKE, BRAIN_PART_PUT, MOVE_MODE_NURSE, PHEROMON_DIR_NONE
5 5
 from intelligine.cst import PHEROMONE_SEARCHING
6 6
 from intelligine.cst import BRAIN_PART_MOVE
7 7
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
@@ -45,15 +45,24 @@ class AntBrain(Brain):
45 45
             pheromone_direction_type = PHEROMON_DIR_HOME
46 46
         elif mode == MOVE_MODE_GOHOME:
47 47
             pheromone_direction_type = PHEROMON_DIR_EXPLO
48
+        elif mode == MOVE_MODE_NURSE:
49
+            pheromone_direction_type = None
48 50
         else:
49 51
             raise NotImplementedError()
50
-        self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
52
+
53
+        if pheromone_direction_type:
54
+            self._host.get_movement_pheromone_gland().set_pheromone_type(pheromone_direction_type)
55
+            self._host.get_movement_pheromone_gland().enable()
56
+        else:
57
+            self._host.get_movement_pheromone_gland().disable()
51 58
 
52 59
     def _update_pheromone_searching(self, mode):
53 60
         if mode == MOVE_MODE_EXPLO:
54 61
             pheromone_searching = PHEROMON_DIR_EXPLO
55 62
         elif mode == MOVE_MODE_GOHOME:
56 63
             pheromone_searching = PHEROMON_DIR_HOME
64
+        elif mode == MOVE_MODE_NURSE:
65
+            pheromone_searching = PHEROMON_DIR_NONE
57 66
         else:
58 67
             raise NotImplementedError()
59 68
         self._pheromone_searching = pheromone_searching

+ 2 - 1
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py View File

@@ -49,5 +49,6 @@ class AntMoveBrainPart(MoveBrainPart):
49 49
 
50 50
     @staticmethod
51 51
     def _appose_pheromone(obj):
52
-        obj.get_movement_pheromone_gland().appose()
52
+        if obj.get_movement_pheromone_gland().is_enabled():
53
+            obj.get_movement_pheromone_gland().appose()
53 54
 

+ 10 - 7
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py View File

@@ -1,11 +1,11 @@
1 1
 from intelligine.core.exceptions import CantFindWhereToPut
2
-from intelligine.simulation.object.brain.part.transport.TakeBrainPart import TakeBrainPart
3
-from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE, TYPE_RESOURCE_TRANSFORMABLE, TYPE, CARRIED, \
4
-    COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
2
+from intelligine.cst import MOVE_MODE_EXPLO, TYPE_RESOURCE_TRANSFORMABLE, CARRIED
3
+from intelligine.simulation.object.brain.part.transport.TransportBrainPart import TransportBrainPart
4
+from intelligine.synergy.object.Food import Food
5 5
 from xyzworld.cst import POSITION, POSITIONS
6 6
 
7 7
 
8
-class AntPutBrainPart(TakeBrainPart):
8
+class AntPutBrainPart(TransportBrainPart):
9 9
 
10 10
     # TODO: methode __nit_ pour la classe ?
11 11
     _mode_matches = {
@@ -52,6 +52,9 @@ class AntPutBrainPart(TakeBrainPart):
52 52
         return False
53 53
 
54 54
     def done(self, obj, puted_object, context):
55
-        # TODO: Depose au -1 pour des raisons de test. Plus tard ce sera des tas comme un autre !
56
-        puted_object.set_position((-1, 0, 0))
57
-        obj.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
55
+        # TODO: Il faut refact/logique qqpart pour ca !! Genre Brain.done(PUT, ??)
56
+        if isinstance(puted_object, Food):
57
+            obj.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
58
+            # TODO: TEST Depose au -1 pour des raisons de test. Plus tard ce sera des tas comme un autre !
59
+            puted_object.set_position((-1, 0, 0))
60
+

+ 2 - 1
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py View File

@@ -1,7 +1,7 @@
1 1
 from intelligine.simulation.object.brain.part.transport.TakeBrainPart import TakeBrainPart
2 2
 from intelligine.synergy.object.ressource.Ressource import Resource
3 3
 from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE, TYPE_RESOURCE_TRANSFORMABLE, \
4
-    TYPE, MOVE_MODE_GOHOME, PHEROMON_DIR_EXPLO
4
+    TYPE, MOVE_MODE_GOHOME, PHEROMON_DIR_EXPLO, MOVE_MODE_NURSE, TYPE_NURSERY
5 5
 
6 6
 
7 7
 class AntTakeBrainPart(TakeBrainPart):
@@ -9,6 +9,7 @@ class AntTakeBrainPart(TakeBrainPart):
9 9
     # TODO: methode __nit_ pour la classe ? vt mieux surcharger !
10 10
     _mode_matches = {
11 11
         MOVE_MODE_EXPLO: [TYPE_RESOURCE_TRANSFORMABLE],
12
+        MOVE_MODE_NURSE: [TYPE_NURSERY]
12 13
     }
13 14
 
14 15
     @classmethod

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

@@ -1,4 +1,4 @@
1
-from intelligine.core.exceptions import BestPheromoneHere
1
+from intelligine.core.exceptions import BestPheromoneHere, PheromoneGlandDisabled
2 2
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
3 3
 
4 4
 class PheromoneGland():
@@ -7,6 +7,7 @@ class PheromoneGland():
7 7
         self._pheromone_type = None
8 8
         self._host = host
9 9
         self._context = context
10
+        self._enabled = False
10 11
 
11 12
     def set_pheromone_type(self, pheromone_type):
12 13
         self._pheromone_type = pheromone_type
@@ -20,9 +21,21 @@ class PheromoneGland():
20 21
         raise NotImplementedError()
21 22
 
22 23
     def appose(self):
24
+        if not self._enabled:
25
+            raise PheromoneGlandDisabled()
26
+
23 27
         try:
24 28
             DirectionPheromone.appose(self._context,
25 29
                                       self._host.get_position(),
26 30
                                       self.get_pheromone())
27 31
         except BestPheromoneHere as best_pheromone_here:
28
-            self._host.get_brain().set_distance_from_objective(best_pheromone_here.get_best_distance())
32
+            self._host.get_brain().set_distance_from_objective(best_pheromone_here.get_best_distance())
33
+
34
+    def disable(self):
35
+        self._enabled = False
36
+
37
+    def enable(self):
38
+        self._enabled = True
39
+
40
+    def is_enabled(self):
41
+        return self._enabled

+ 3 - 1
intelligine/synergy/object/Egg.py View File

@@ -1,10 +1,12 @@
1 1
 from intelligine.synergy.object.BaseBug import BaseBug
2
-from intelligine.cst import TRANSPORTABLE
2
+from intelligine.cst import TRANSPORTABLE, TYPE_NURSERY, TYPE
3 3
 
4 4
 
5 5
 class Egg(BaseBug):
6 6
 
7 7
     def __init__(self, collection, context):
8 8
         super().__init__(collection, context)
9
+        context.metas.list.add(TYPE, self.get_id(), TYPE_NURSERY)
10
+        # TODO: ?? TRANSPORTABLE ne devrait pas ette du cote de Transportable ?
9 11
         context.metas.states.add(self.get_id(), TRANSPORTABLE)
10 12
         self._life_points = 1

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

@@ -1,5 +1,4 @@
1
-from intelligine.core.exceptions import BestPheromoneHere
2
-from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
1
+from intelligine.core.exceptions import PheromoneException
3 2
 from intelligine.synergy.object.Bug import Bug
4 3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
5 4
                             COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
@@ -78,10 +77,11 @@ class Ant(Bug):
78 77
 
79 78
     def initialize(self):
80 79
         super().initialize()
81
-        try:
82
-            self.get_movement_pheromone_gland().appose()
83
-        except BestPheromoneHere as best_pheromone_here:
84
-            pass
80
+        if self.get_movement_pheromone_gland().is_enabled():
81
+            try:
82
+                self.get_movement_pheromone_gland().appose()
83
+            except PheromoneException:
84
+                pass
85 85
 
86 86
     def get_colony(self):
87 87
         return self.get_collection()