Browse Source

update code of egg missions

Bastien Sevajol 9 years ago
parent
commit
f50c04d9ac

+ 1 - 0
TODO View File

8
 
8
 
9
  * Mechanisme qui donne les pheromones around ?
9
  * Mechanisme qui donne les pheromones around ?
10
  * Appliquer la disparition des pheromones
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
 Future:
13
 Future:
13
  * Chambres
14
  * Chambres

+ 2 - 2
config.py View File

2
 from intelligine.synergy.Simulation import Simulation
2
 from intelligine.synergy.Simulation import Simulation
3
 from intelligine.display.Pygame import Pygame
3
 from intelligine.display.Pygame import Pygame
4
 from intelligine.display.pygame.visualisation import visualisation as pygame_visualisation
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
 # TODO: influencer avec argument python
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
  TODO:
10
  TODO:

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

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

+ 4 - 0
intelligine/cst.py View File

15
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
15
 ACTION_DIE = IncrementedNamedInt.get('intelligine.basebug.action.die')
16
 PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.pheromone_searching')
16
 PHEROMONE_SEARCHING = IncrementedNamedInt.get('intelligine.pheromone_searching')
17
 
17
 
18
+# TODO: Renommer "move_mode" en "mode"
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')
20
 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')
21
 
23
 
22
 TYPE = IncrementedNamedInt.get('intelligine.object.type')
24
 TYPE = IncrementedNamedInt.get('intelligine.object.type')
23
 TYPE_RESOURCE_TRANSFORMABLE = IncrementedNamedInt.get('intelligine.object.type.resource.transformable')
25
 TYPE_RESOURCE_TRANSFORMABLE = IncrementedNamedInt.get('intelligine.object.type.resource.transformable')
26
+TYPE_NURSERY = IncrementedNamedInt.get('intelligine.object.type.nursery')
24
 
27
 
25
 LAST_PHERMONES_POINTS = IncrementedNamedInt.get('intelligine.last_pheromones_points')
28
 LAST_PHERMONES_POINTS = IncrementedNamedInt.get('intelligine.last_pheromones_points')
26
 
29
 
27
 PHEROMON_POSITIONS = IncrementedNamedInt.get('intelligine.phero.positions')
30
 PHEROMON_POSITIONS = IncrementedNamedInt.get('intelligine.phero.positions')
28
 PHEROMON_INFOS = IncrementedNamedInt.get('intelligine.phero.infos')
31
 PHEROMON_INFOS = IncrementedNamedInt.get('intelligine.phero.infos')
29
 PHEROMON_DIRECTION = IncrementedNamedInt.get('intelligine.phero.direction')
32
 PHEROMON_DIRECTION = IncrementedNamedInt.get('intelligine.phero.direction')
33
+PHEROMON_DIR_NONE = IncrementedNamedInt.get('intelligine.phero.direction.none')
30
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
34
 PHEROMON_DIR_EXPLO = IncrementedNamedInt.get('intelligine.phero.direction.explo')
31
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
35
 PHEROMON_DIR_HOME = IncrementedNamedInt.get('intelligine.phero.direction.home')
32
 
36
 

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

1
 from intelligine.synergy.ColonyConfiguration import ColonyConfiguration
1
 from intelligine.synergy.ColonyConfiguration import ColonyConfiguration
2
 from intelligine.sandbox.colored.RedAnt import RedAnt
2
 from intelligine.sandbox.colored.RedAnt import RedAnt
3
 from intelligine.synergy.object.ant.Egg import Egg
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
 class RedColonyConfiguration(ColonyConfiguration):
7
 class RedColonyConfiguration(ColonyConfiguration):
8
 
8
 
9
     _start_position = (0, 20, 70)
9
     _start_position = (0, 20, 70)
10
     _ant_class = RedAnt
10
     _ant_class = RedAnt
11
+    _ant_count = 50
11
 
12
 
12
     def get_start_objects(self, collection, context):
13
     def get_start_objects(self, collection, context):
13
         objects = super().get_start_objects(collection, context)
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
         for x in range(50):
19
         for x in range(50):
16
           for y in range(1, 50):
20
           for y in range(1, 50):
17
             if x % 3 == 0 and y % 3 == 0:
21
             if x % 3 == 0 and y % 3 == 0:

+ 11 - 2
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.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
2
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
3
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_HOME, PHEROMON_DIR_EXPLO, \
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
 from intelligine.cst import PHEROMONE_SEARCHING
5
 from intelligine.cst import PHEROMONE_SEARCHING
6
 from intelligine.cst import BRAIN_PART_MOVE
6
 from intelligine.cst import BRAIN_PART_MOVE
7
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
7
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
45
             pheromone_direction_type = PHEROMON_DIR_HOME
45
             pheromone_direction_type = PHEROMON_DIR_HOME
46
         elif mode == MOVE_MODE_GOHOME:
46
         elif mode == MOVE_MODE_GOHOME:
47
             pheromone_direction_type = PHEROMON_DIR_EXPLO
47
             pheromone_direction_type = PHEROMON_DIR_EXPLO
48
+        elif mode == MOVE_MODE_NURSE:
49
+            pheromone_direction_type = None
48
         else:
50
         else:
49
             raise NotImplementedError()
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
     def _update_pheromone_searching(self, mode):
59
     def _update_pheromone_searching(self, mode):
53
         if mode == MOVE_MODE_EXPLO:
60
         if mode == MOVE_MODE_EXPLO:
54
             pheromone_searching = PHEROMON_DIR_EXPLO
61
             pheromone_searching = PHEROMON_DIR_EXPLO
55
         elif mode == MOVE_MODE_GOHOME:
62
         elif mode == MOVE_MODE_GOHOME:
56
             pheromone_searching = PHEROMON_DIR_HOME
63
             pheromone_searching = PHEROMON_DIR_HOME
64
+        elif mode == MOVE_MODE_NURSE:
65
+            pheromone_searching = PHEROMON_DIR_NONE
57
         else:
66
         else:
58
             raise NotImplementedError()
67
             raise NotImplementedError()
59
         self._pheromone_searching = pheromone_searching
68
         self._pheromone_searching = pheromone_searching

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

49
 
49
 
50
     @staticmethod
50
     @staticmethod
51
     def _appose_pheromone(obj):
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
 from intelligine.core.exceptions import CantFindWhereToPut
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
 from xyzworld.cst import POSITION, POSITIONS
5
 from xyzworld.cst import POSITION, POSITIONS
6
 
6
 
7
 
7
 
8
-class AntPutBrainPart(TakeBrainPart):
8
+class AntPutBrainPart(TransportBrainPart):
9
 
9
 
10
     # TODO: methode __nit_ pour la classe ?
10
     # TODO: methode __nit_ pour la classe ?
11
     _mode_matches = {
11
     _mode_matches = {
52
         return False
52
         return False
53
 
53
 
54
     def done(self, obj, puted_object, context):
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
 from intelligine.simulation.object.brain.part.transport.TakeBrainPart import TakeBrainPart
1
 from intelligine.simulation.object.brain.part.transport.TakeBrainPart import TakeBrainPart
2
 from intelligine.synergy.object.ressource.Ressource import Resource
2
 from intelligine.synergy.object.ressource.Ressource import Resource
3
 from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE, TYPE_RESOURCE_TRANSFORMABLE, \
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
 class AntTakeBrainPart(TakeBrainPart):
7
 class AntTakeBrainPart(TakeBrainPart):
9
     # TODO: methode __nit_ pour la classe ? vt mieux surcharger !
9
     # TODO: methode __nit_ pour la classe ? vt mieux surcharger !
10
     _mode_matches = {
10
     _mode_matches = {
11
         MOVE_MODE_EXPLO: [TYPE_RESOURCE_TRANSFORMABLE],
11
         MOVE_MODE_EXPLO: [TYPE_RESOURCE_TRANSFORMABLE],
12
+        MOVE_MODE_NURSE: [TYPE_NURSERY]
12
     }
13
     }
13
 
14
 
14
     @classmethod
15
     @classmethod

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

1
-from intelligine.core.exceptions import BestPheromoneHere
1
+from intelligine.core.exceptions import BestPheromoneHere, PheromoneGlandDisabled
2
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
2
 from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
3
 
3
 
4
 class PheromoneGland():
4
 class PheromoneGland():
7
         self._pheromone_type = None
7
         self._pheromone_type = None
8
         self._host = host
8
         self._host = host
9
         self._context = context
9
         self._context = context
10
+        self._enabled = False
10
 
11
 
11
     def set_pheromone_type(self, pheromone_type):
12
     def set_pheromone_type(self, pheromone_type):
12
         self._pheromone_type = pheromone_type
13
         self._pheromone_type = pheromone_type
20
         raise NotImplementedError()
21
         raise NotImplementedError()
21
 
22
 
22
     def appose(self):
23
     def appose(self):
24
+        if not self._enabled:
25
+            raise PheromoneGlandDisabled()
26
+
23
         try:
27
         try:
24
             DirectionPheromone.appose(self._context,
28
             DirectionPheromone.appose(self._context,
25
                                       self._host.get_position(),
29
                                       self._host.get_position(),
26
                                       self.get_pheromone())
30
                                       self.get_pheromone())
27
         except BestPheromoneHere as best_pheromone_here:
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
 from intelligine.synergy.object.BaseBug import BaseBug
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
 class Egg(BaseBug):
5
 class Egg(BaseBug):
6
 
6
 
7
     def __init__(self, collection, context):
7
     def __init__(self, collection, context):
8
         super().__init__(collection, context)
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
         context.metas.states.add(self.get_id(), TRANSPORTABLE)
11
         context.metas.states.add(self.get_id(), TRANSPORTABLE)
10
         self._life_points = 1
12
         self._life_points = 1

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

1
-from intelligine.core.exceptions import BestPheromoneHere
2
-from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
1
+from intelligine.core.exceptions import PheromoneException
3
 from intelligine.synergy.object.Bug import Bug
2
 from intelligine.synergy.object.Bug import Bug
4
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
5
                             COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4
                             COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
78
 
77
 
79
     def initialize(self):
78
     def initialize(self):
80
         super().initialize()
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
     def get_colony(self):
86
     def get_colony(self):
87
         return self.get_collection()
87
         return self.get_collection()