Browse Source

body parts

Bastien Sevajol 9 years ago
parent
commit
7d04ad816a

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

54
     pass
54
     pass
55
 
55
 
56
 
56
 
57
+class BodyException(Exception):
58
+    pass
59
+
60
+
61
+class BodyPartAlreadyExist(BodyException):
62
+    pass
63
+
64
+
57
 class DirectionException(Exception):
65
 class DirectionException(Exception):
58
     pass
66
     pass
59
 
67
 

+ 4 - 1
intelligine/cst.py View File

43
 BRAIN_PART_MOVE = IncrementedNamedInt.get('intelligine.brain.part.move')
43
 BRAIN_PART_MOVE = IncrementedNamedInt.get('intelligine.brain.part.move')
44
 BRAIN_PART_TAKE = IncrementedNamedInt.get('intelligine.brain.part.take')
44
 BRAIN_PART_TAKE = IncrementedNamedInt.get('intelligine.brain.part.take')
45
 BRAIN_PART_PUT = IncrementedNamedInt.get('intelligine.brain.part.put')
45
 BRAIN_PART_PUT = IncrementedNamedInt.get('intelligine.brain.part.put')
46
-BRAIN_PART_ATTACK = IncrementedNamedInt.get('intelligine.brain.part.attack')
46
+BRAIN_PART_ATTACK = IncrementedNamedInt.get('intelligine.brain.part.attack')
47
+
48
+BODY_SCHEMA = IncrementedNamedInt.get('intelligine.body_schema')
49
+BODY_PART_PHEROMONE_GLAND = IncrementedNamedInt.get('intelligine.body.part.pheromone_gland')

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

30
         self._schema = {}
30
         self._schema = {}
31
         for part_name in self._parts:
31
         for part_name in self._parts:
32
             self._schema[part_name] = self._parts[part_name].__class__
32
             self._schema[part_name] = self._parts[part_name].__class__
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 ?
33
         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)

+ 17 - 0
intelligine/synergy/object/BaseBug.py View File

1
+from intelligine.core.exceptions import BodyPartAlreadyExist
1
 from intelligine.synergy.object.Transportable import Transportable
2
 from intelligine.synergy.object.Transportable import Transportable
2
 from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE
3
 from intelligine.cst import ALIVE, ATTACKABLE, COL_ALIVE
3
 from intelligine.simulation.object.brain.Brain import Brain
4
 from intelligine.simulation.object.brain.Brain import Brain
5
 
6
 
6
 class BaseBug(Transportable):
7
 class BaseBug(Transportable):
7
 
8
 
9
+    _body_parts = {}
10
+
8
     def __init__(self, collection, context):
11
     def __init__(self, collection, context):
9
         super().__init__(collection, context)
12
         super().__init__(collection, context)
10
         context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
13
         context.metas.states.add_list(self.get_id(), [ALIVE, ATTACKABLE])
12
         self._life_points = 10
15
         self._life_points = 10
13
         self._movements_count = -1
16
         self._movements_count = -1
14
         self._brain = self._get_brain_instance()
17
         self._brain = self._get_brain_instance()
18
+        self._parts = {}
19
+        self._init_parts()
20
+
21
+    def _init_parts(self):
22
+        for body_part_name in self._body_parts:
23
+            self._set_body_part(body_part_name, self._body_parts[body_part_name](self, self._context))
24
+
25
+    def _set_body_part(self, name, body_part, replace=False):
26
+        if name in self._parts and not replace:
27
+            raise BodyPartAlreadyExist()
28
+        self._parts[name] = body_part
29
+
30
+    def get_body_part(self, name):
31
+        return self._parts[name]
15
 
32
 
16
     def hurted(self, points):
33
     def hurted(self, points):
17
         self._life_points -= points
34
         self._life_points -= points

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

1
 from intelligine.core.exceptions import PheromoneException
1
 from intelligine.core.exceptions import PheromoneException
2
 from intelligine.synergy.object.Bug import Bug
2
 from intelligine.synergy.object.Bug import Bug
3
-from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, \
4
-                            COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
5
-                            COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, \
6
-                            PHEROMON_DIR_EXPLO, CARRIED
3
+from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4
+    COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, CARRIED, BODY_PART_PHEROMONE_GLAND
7
 from intelligine.synergy.object.Food import Food
5
 from intelligine.synergy.object.Food import Food
8
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
6
 from intelligine.simulation.object.pheromone.MovementPheromoneGland import MovementPheromoneGland
9
 from intelligine.simulation.object.brain.AntBrain import AntBrain
7
 from intelligine.simulation.object.brain.AntBrain import AntBrain
11
 
9
 
12
 class Ant(Bug):
10
 class Ant(Bug):
13
 
11
 
12
+    _body_parts = {
13
+        BODY_PART_PHEROMONE_GLAND: MovementPheromoneGland
14
+    }
15
+
14
     def __init__(self, collection, context):
16
     def __init__(self, collection, context):
15
         super().__init__(collection, context)
17
         super().__init__(collection, context)
16
         context.metas.states.add_list(self.get_id(), [TRANSPORTER, ATTACKER])
18
         context.metas.states.add_list(self.get_id(), [TRANSPORTER, ATTACKER])
18
                                                            COL_TRANSPORTER_NOT_CARRYING,
20
                                                            COL_TRANSPORTER_NOT_CARRYING,
19
                                                            COL_FIGHTER])
21
                                                            COL_FIGHTER])
20
         self._carried = None
22
         self._carried = None
21
-        # TODO: Faire un body_part schema pour ces trucs la
22
-        self._movement_pheromone_gland = MovementPheromoneGland(self, self._context)
23
         self._brain.switch_to_mode(MOVE_MODE_EXPLO)
23
         self._brain.switch_to_mode(MOVE_MODE_EXPLO)
24
 
24
 
25
     def _get_brain_instance(self):
25
     def _get_brain_instance(self):
26
         return AntBrain(self._context, self)
26
         return AntBrain(self._context, self)
27
 
27
 
28
     def get_movement_pheromone_gland(self):
28
     def get_movement_pheromone_gland(self):
29
-        return self._movement_pheromone_gland
29
+        return self.get_body_part(BODY_PART_PHEROMONE_GLAND)
30
 
30
 
31
     def put_carry(self, obj, position=None):
31
     def put_carry(self, obj, position=None):
32
         if position is None:
32
         if position is None: