Bastien Sevajol vor 9 Jahren
Ursprung
Commit
a420b757ee

+ 10 - 6
intelligine/simulation/object/brain/AntBrain.py Datei anzeigen

@@ -2,27 +2,30 @@ from intelligine.simulation.object.brain.Brain import Brain
2 2
 from intelligine.simulation.object.brain.part.attack.AttackBrainPart import AttackBrainPart
3 3
 from intelligine.simulation.object.brain.part.move.AntMoveBrainPart import AntMoveBrainPart
4 4
 from intelligine.cst import MOVE_MODE, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, PHEROMON_DIR_EXPLO, \
5
-    BRAIN_PART_TAKE, BRAIN_PART_PUT, MOVE_MODE_NURSE, PHEROMON_DIR_NONE, BRAIN_PART_ATTACK, MOVE_MODE_HOME, SMELL_FOOD
5
+    BRAIN_PART_TAKE, BRAIN_PART_PUT, MOVE_MODE_NURSE, PHEROMON_DIR_NONE, BRAIN_PART_ATTACK, MOVE_MODE_HOME, \
6
+    SMELL_FOOD, SMELL_EGG
6 7
 from intelligine.cst import MOLECULE_SEARCHING
7 8
 from intelligine.cst import BRAIN_PART_MOVE
8 9
 from intelligine.simulation.object.brain.part.transport.AntPutBrainPart import AntPutBrainPart
9 10
 from intelligine.simulation.object.brain.part.transport.AntTakeBrainPart import AntTakeBrainPart
10 11
 from intelligine.synergy.object.Food import Food
12
+from intelligine.synergy.object.ant.Egg import Egg
11 13
 from synergine.core.exceptions import NotFound
12 14
 
13 15
 
14 16
 class AntBrain(Brain):
15 17
 
16
-    # TODO: methode __init_ pour la classe ? Pour surcharger ici.
17
-    _brain_parts = {
18
+    _brain_parts = Brain._brain_parts.copy()
19
+    _brain_parts.update({
18 20
         BRAIN_PART_MOVE: AntMoveBrainPart,
19 21
         BRAIN_PART_TAKE: AntTakeBrainPart,
20 22
         BRAIN_PART_PUT: AntPutBrainPart,
21 23
         BRAIN_PART_ATTACK: AttackBrainPart
22
-    }
24
+    })
23 25
 
24 26
     _taken_smell_matches = {
25
-        Food: SMELL_FOOD
27
+        Food: SMELL_FOOD,
28
+        Egg: SMELL_EGG
26 29
     }
27 30
     """ Correspondance entre ce qui est ramassé et où ce doit être stocké """
28 31
 
@@ -65,6 +68,7 @@ class AntBrain(Brain):
65 68
         elif mode == MOVE_MODE_NURSE:
66 69
             molecule_searching = PHEROMON_DIR_NONE
67 70
         elif mode == MOVE_MODE_HOME:
71
+            # TODO: Ca depend de ce que fait la fourmis, si s'occupe des oeufs, etc
68 72
             molecule_searching = self.get_part(BRAIN_PART_TAKE).get_smell_target()
69 73
         else:
70 74
             raise NotImplementedError()
@@ -76,7 +80,7 @@ class AntBrain(Brain):
76 80
         return self._movement_mode
77 81
 
78 82
     def host_moved(self, distance=1):
79
-        self._distance_from_objective += 1
83
+        self._distance_from_objective += distance
80 84
 
81 85
     def set_distance_from_objective(self, distance):
82 86
         self._distance_from_objective = distance

+ 13 - 9
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py Datei anzeigen

@@ -6,7 +6,7 @@ from intelligine.synergy.event.move.direction import directions_modifiers, get_p
6 6
 from synergine_xyz.cst import POSITION
7 7
 from intelligine.core.exceptions import NoMolecule
8 8
 from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, \
9
-    EXPLORATION_VECTOR, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG, BRAIN_SCHEMA, BRAIN
9
+    EXPLORATION_VECTOR, MOLECULES_DIRECTION
10 10
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
11 11
 
12 12
 
@@ -103,22 +103,16 @@ class AntMoveBrainPart(MoveBrainPart):
103 103
         movement_mode = self._host_brain.get_movement_mode()
104 104
 
105 105
         if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(self._context, self._host.get_id()):
106
-            self._host_brain.switch_to_mode(MOVE_MODE_HOME)
107
-            ant_star = self._get_by_pass_brain(self._context, self._host.get_id())
108
-            ant_star.erase()
109
-            # TODO: on change les molecule recherché (Food => SmellFood, definis dans Take, en fct de ce qui est take)
106
+            self._arrived_at_home()
110 107
 
111 108
         elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
112
-            self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
113 109
             self._start_new_exploration()
114 110
 
115 111
         elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
116
-            self._start_new_exploration()  # TODO: rename en reinit_explo
112
+            self._init_exploration_vector()
117 113
 
118 114
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
119 115
 
120
-        # TODO: Poser sur StockedFood
121
-
122 116
     @classmethod
123 117
     def _on_home_smell(cls, context, object_id):
124 118
         current_position = context.metas.value.get(POSITION, object_id)
@@ -146,7 +140,17 @@ class AntMoveBrainPart(MoveBrainPart):
146 140
             self._update_exploration_vector()
147 141
 
148 142
     def _start_new_exploration(self):
143
+        self._reinit_exploration_vector()
144
+        self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
145
+
146
+    def _init_exploration_vector(self):
149 147
         # On vient de rentrer dans le monde exterieur, le vecteur de départ pointe vers la case précedente
150 148
         # qui est une case dans la forteresse.
151 149
         init_exploration_vector = get_position_with_direction_decal(self.get_host().get_previous_direction())
152 150
         self._set_exploration_vector(init_exploration_vector)
151
+
152
+
153
+    def _arrived_at_home(self):
154
+        self._host_brain.switch_to_mode(MOVE_MODE_HOME)
155
+        ant_star = self._get_by_pass_brain(self._context, self._host.get_id())
156
+        ant_star.erase()