Browse Source

clean code

Bastien Sevajol 9 years ago
parent
commit
a420b757ee

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

+ 13 - 9
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py View File

6
 from synergine_xyz.cst import POSITION
6
 from synergine_xyz.cst import POSITION
7
 from intelligine.core.exceptions import NoMolecule
7
 from intelligine.core.exceptions import NoMolecule
8
 from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, \
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
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
10
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
11
 
11
 
12
 
12
 
103
         movement_mode = self._host_brain.get_movement_mode()
103
         movement_mode = self._host_brain.get_movement_mode()
104
 
104
 
105
         if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(self._context, self._host.get_id()):
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
         elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
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
             self._start_new_exploration()
109
             self._start_new_exploration()
114
 
110
 
115
         elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
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
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
114
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
119
 
115
 
120
-        # TODO: Poser sur StockedFood
121
-
122
     @classmethod
116
     @classmethod
123
     def _on_home_smell(cls, context, object_id):
117
     def _on_home_smell(cls, context, object_id):
124
         current_position = context.metas.value.get(POSITION, object_id)
118
         current_position = context.metas.value.get(POSITION, object_id)
146
             self._update_exploration_vector()
140
             self._update_exploration_vector()
147
 
141
 
148
     def _start_new_exploration(self):
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
         # On vient de rentrer dans le monde exterieur, le vecteur de départ pointe vers la case précedente
147
         # On vient de rentrer dans le monde exterieur, le vecteur de départ pointe vers la case précedente
150
         # qui est une case dans la forteresse.
148
         # qui est une case dans la forteresse.
151
         init_exploration_vector = get_position_with_direction_decal(self.get_host().get_previous_direction())
149
         init_exploration_vector = get_position_with_direction_decal(self.get_host().get_previous_direction())
152
         self._set_exploration_vector(init_exploration_vector)
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()