Selaa lähdekoodia

remove move mode constants

Bastien Sevajol 9 vuotta sitten
vanhempi
commit
4cf3365a10

+ 5 - 5
intelligine/cst.py Näytä tiedosto

@@ -17,11 +17,11 @@ MOLECULE_SEARCHING = IncrementedNamedInt.get('intelligine.molecule_searching')
17 17
 MOLECULES = IncrementedNamedInt.get('intelligine.molecules')
18 18
 
19 19
 # TODO: Renommer "move_mode" en "mode" ?
20
-MOVE_MODE = IncrementedNamedInt.get('intelligine.basebug.move.mode')
21
-MOVE_MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.mode.explo')
22
-MOVE_MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.gohome')
23
-MOVE_MODE_NURSE = IncrementedNamedInt.get('intelligine.basebug.move.mode.nurse')
24
-MOVE_MODE_HOME = IncrementedNamedInt.get('intelligine.basebug.move.mode.home')
20
+MODE = IncrementedNamedInt.get('intelligine.basebug.move')
21
+MODE_EXPLO = IncrementedNamedInt.get('intelligine.basebug.move.explo')
22
+MODE_GOHOME = IncrementedNamedInt.get('intelligine.basebug.move.gohome')
23
+MODE_NURSE = IncrementedNamedInt.get('intelligine.basebug.move.nurse')
24
+MODE_HOME = IncrementedNamedInt.get('intelligine.basebug.move.home')
25 25
 
26 26
 MOVE_BYBASS = IncrementedNamedInt.get('intelligine.basebug.move.bypass')
27 27
 MOVE_BYBASS_DISTANCE = IncrementedNamedInt.get('intelligine.basebug.move.bypass.distance')

+ 12 - 12
intelligine/simulation/object/brain/AntBrain.py Näytä tiedosto

@@ -1,8 +1,8 @@
1 1
 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
-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, \
4
+from intelligine.cst import MODE, MODE_EXPLO, MODE_GOHOME, PHEROMON_DIR_EXPLO, \
5
+    BRAIN_PART_TAKE, BRAIN_PART_PUT, MODE_NURSE, PHEROMON_DIR_NONE, BRAIN_PART_ATTACK, MODE_HOME, \
6 6
     SMELL_FOOD, SMELL_EGG
7 7
 from intelligine.cst import MOLECULE_SEARCHING
8 8
 from intelligine.cst import BRAIN_PART_MOVE
@@ -31,25 +31,25 @@ class AntBrain(Brain):
31 31
 
32 32
     def __init__(self, context, host):
33 33
         super().__init__(context, host)
34
-        self._movement_mode = MOVE_MODE_HOME
34
+        self._movement_mode = MODE_HOME
35 35
         self._distance_from_objective = 0  # TODO rename: distance_since_objective
36 36
         self._molecule_searching = PHEROMON_DIR_EXPLO
37 37
 
38 38
     def switch_to_mode(self, mode):
39 39
         self._movement_mode = mode
40 40
         self._update_molecule_gland(mode)
41
-        self._context.metas.value.set(MOVE_MODE, self._host.get_id(), mode)
41
+        self._context.metas.value.set(MODE, self._host.get_id(), mode)
42 42
         self._update_molecule_searching(mode)
43 43
 
44 44
     def _update_molecule_gland(self, mode):
45
-        if mode == MOVE_MODE_EXPLO:
45
+        if mode == MODE_EXPLO:
46 46
             molecule_direction_type = None
47
-        elif mode == MOVE_MODE_GOHOME:
47
+        elif mode == MODE_GOHOME:
48 48
             molecule_direction_type = PHEROMON_DIR_EXPLO
49 49
             self._distance_from_objective = 0
50
-        elif mode == MOVE_MODE_NURSE:
50
+        elif mode == MODE_NURSE:
51 51
             molecule_direction_type = None
52
-        elif mode == MOVE_MODE_HOME:
52
+        elif mode == MODE_HOME:
53 53
             molecule_direction_type = PHEROMON_DIR_EXPLO
54 54
         else:
55 55
             raise NotImplementedError()
@@ -61,13 +61,13 @@ class AntBrain(Brain):
61 61
             self._host.get_movement_molecule_gland().disable()
62 62
 
63 63
     def _update_molecule_searching(self, mode):
64
-        if mode == MOVE_MODE_EXPLO:
64
+        if mode == MODE_EXPLO:
65 65
             molecule_searching = PHEROMON_DIR_EXPLO
66
-        elif mode == MOVE_MODE_GOHOME:
66
+        elif mode == MODE_GOHOME:
67 67
             molecule_searching = PHEROMON_DIR_NONE
68
-        elif mode == MOVE_MODE_NURSE:
68
+        elif mode == MODE_NURSE:
69 69
             molecule_searching = PHEROMON_DIR_NONE
70
-        elif mode == MOVE_MODE_HOME:
70
+        elif mode == MODE_HOME:
71 71
             # TODO: Ca depend de ce que fait la fourmis, si s'occupe des oeufs, etc
72 72
             molecule_searching = self.get_part(BRAIN_PART_TAKE).get_smell_target()
73 73
         else:

+ 9 - 9
intelligine/simulation/object/brain/part/move/AntMoveBrainPart.py Näytä tiedosto

@@ -5,7 +5,7 @@ from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrai
5 5
 from intelligine.synergy.event.move.direction import directions_modifiers, get_position_with_direction_decal
6 6
 from synergine_xyz.cst import POSITION
7 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, MODE_EXPLO, MODE_HOME, MODE, MODE_GOHOME, \
9 9
     EXPLORATION_VECTOR, MOLECULES_DIRECTION
10 10
 from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
11 11
 
@@ -24,8 +24,8 @@ class AntMoveBrainPart(MoveBrainPart):
24 24
 
25 25
     @classmethod
26 26
     def get_direction(cls, context, object_id):
27
-        move_mode = context.metas.value.get(MOVE_MODE, object_id)
28
-        if move_mode == MOVE_MODE_GOHOME:
27
+        move_mode = context.metas.value.get(MODE, object_id)
28
+        if move_mode == MODE_GOHOME:
29 29
             return cls._get_direction_with_exploration_vector(context, object_id)
30 30
         else:
31 31
             try:
@@ -102,13 +102,13 @@ class AntMoveBrainPart(MoveBrainPart):
102 102
         """
103 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 == MODE_GOHOME and self._on_home_smell(self._context, self._host.get_id()):
106 106
             self._arrived_at_home()
107 107
 
108
-        elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
108
+        elif movement_mode == MODE_HOME and not self._on_home_smell(self._context, self._host.get_id()):
109 109
             self._start_new_exploration()
110 110
 
111
-        elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
111
+        elif movement_mode == MODE_EXPLO and self._on_home_smell(self._context, self._host.get_id()):
112 112
             self._init_exploration_vector()
113 113
 
114 114
         # TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
@@ -136,12 +136,12 @@ class AntMoveBrainPart(MoveBrainPart):
136 136
 
137 137
     def _apply_context(self):
138 138
         movement_mode = self._host_brain.get_movement_mode()
139
-        if movement_mode == MOVE_MODE_EXPLO or movement_mode == MOVE_MODE_GOHOME:
139
+        if movement_mode == MODE_EXPLO or movement_mode == MODE_GOHOME:
140 140
             self._update_exploration_vector()
141 141
 
142 142
     def _start_new_exploration(self):
143 143
         self._reinit_exploration_vector()
144
-        self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
144
+        self._host_brain.switch_to_mode(MODE_EXPLO)
145 145
 
146 146
     def _init_exploration_vector(self):
147 147
         # On vient de rentrer dans le monde exterieur, le vecteur de départ pointe vers la case précedente
@@ -150,6 +150,6 @@ class AntMoveBrainPart(MoveBrainPart):
150 150
         self._set_exploration_vector(init_exploration_vector)
151 151
 
152 152
     def _arrived_at_home(self):
153
-        self._host_brain.switch_to_mode(MOVE_MODE_HOME)
153
+        self._host_brain.switch_to_mode(MODE_HOME)
154 154
         ant_star = self._get_by_pass_brain(self._context, self._host.get_id())
155 155
         ant_star.erase()

+ 6 - 6
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py Näytä tiedosto

@@ -1,6 +1,6 @@
1 1
 from intelligine.core.exceptions import CantFindWhereToPut
2
-from intelligine.cst import MOVE_MODE_EXPLO, TYPE_RESOURCE_EXPLOITABLE, CARRIED, MOVE_MODE_NURSE, TYPE_NURSERY, \
3
-    MOVE_MODE_HOME, TYPE_RESOURCE_EATABLE, TYPE, MOVE_MODE, MOVE_MODE_GOHOME
2
+from intelligine.cst import MODE_EXPLO, TYPE_RESOURCE_EXPLOITABLE, CARRIED, MODE_NURSE, TYPE_NURSERY, \
3
+    MODE_HOME, TYPE_RESOURCE_EATABLE, TYPE, MODE, MODE_GOHOME
4 4
 from intelligine.simulation.object.brain.part.transport.TransportBrainPart import TransportBrainPart
5 5
 from intelligine.synergy.object.Food import Food
6 6
 from synergine_xyz.cst import POSITION, POSITIONS
@@ -10,9 +10,9 @@ class AntPutBrainPart(TransportBrainPart):
10 10
 
11 11
     # TODO: methode __nit_ pour la classe ?
12 12
     _mode_matches = {
13
-        MOVE_MODE_NURSE: [TYPE_NURSERY],
14
-        MOVE_MODE_HOME: [TYPE_RESOURCE_EATABLE],
15
-        MOVE_MODE_GOHOME: []
13
+        MODE_NURSE: [TYPE_NURSERY],
14
+        MODE_HOME: [TYPE_RESOURCE_EATABLE],
15
+        MODE_GOHOME: []
16 16
     }
17 17
 
18 18
     _types_matches = {
@@ -65,7 +65,7 @@ class AntPutBrainPart(TransportBrainPart):
65 65
         # TODO: Il faut refact/logique qqpart pour ca !! Genre Brain.done(PUT, ??)
66 66
         if isinstance(puted_object, Food):
67 67
             # TODO: Quel mode ? On vient de poser (ps forcement dans la colonie) cls._mode_swicth ?
68
-            self._host.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
68
+            self._host.get_brain().switch_to_mode(MODE_EXPLO)
69 69
             # TODO: TEST Depose au -1 pour des raisons de test. Plus tard ce sera des tas comme un autre !
70 70
             puted_object.set_position((-1, 0, 0))
71 71
 

+ 6 - 6
intelligine/simulation/object/brain/part/transport/AntTakeBrainPart.py Näytä tiedosto

@@ -1,16 +1,16 @@
1 1
 from intelligine.simulation.object.brain.part.transport.TakeBrainPart import TakeBrainPart
2 2
 from intelligine.synergy.object.ressource.Ressource import Resource
3
-from intelligine.cst import MOVE_MODE_EXPLO, TYPE_RESOURCE_EXPLOITABLE, \
4
-    MOVE_MODE_GOHOME, MOVE_MODE_NURSE, TYPE_NURSERY
3
+from intelligine.cst import MODE_EXPLO, TYPE_RESOURCE_EXPLOITABLE, \
4
+    MODE_GOHOME, MODE_NURSE, TYPE_NURSERY
5 5
 
6 6
 
7 7
 class AntTakeBrainPart(TakeBrainPart):
8 8
 
9 9
     # TODO: methode __init_ pour la classe ? Pour surcharger ici.
10 10
     _mode_matches = {
11
-        MOVE_MODE_EXPLO: [TYPE_RESOURCE_EXPLOITABLE],
12
-        MOVE_MODE_NURSE: [TYPE_NURSERY],
13
-        MOVE_MODE_GOHOME: []
11
+        MODE_EXPLO: [TYPE_RESOURCE_EXPLOITABLE],
12
+        MODE_NURSE: [TYPE_NURSERY],
13
+        MODE_GOHOME: []
14 14
     }
15 15
 
16 16
     def __init__(self, host_brain):
@@ -32,5 +32,5 @@ class AntTakeBrainPart(TakeBrainPart):
32 32
         # TODO: qqch plus generique ... (attention aux eggs)
33 33
         if isinstance(take_object, Resource):
34 34
             self._smell_target = self._host_brain.get_smell_for_object_taken(take_object)
35
-            self._host.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
35
+            self._host.get_brain().switch_to_mode(MODE_GOHOME)
36 36
             self._host.get_movement_molecule_gland().appose()

+ 2 - 2
intelligine/simulation/object/brain/part/transport/TransportBrainPart.py Näytä tiedosto

@@ -1,4 +1,4 @@
1
-from intelligine.cst import MOVE_MODE, TYPE
1
+from intelligine.cst import MODE, TYPE
2 2
 from intelligine.simulation.object.brain.part.BrainPart import BrainPart
3 3
 
4 4
 
@@ -9,7 +9,7 @@ class TransportBrainPart(BrainPart):
9 9
 
10 10
     @classmethod
11 11
     def _match_with_mode(cls, context, object_id, concerned_object_id):
12
-        move_mode = context.metas.value.get(MOVE_MODE, object_id)
12
+        move_mode = context.metas.value.get(MODE, object_id)
13 13
         for takable_type in cls._mode_matches[move_mode]:
14 14
             if context.metas.list.have(TYPE, concerned_object_id, takable_type, allow_empty=True):
15 15
                 return True

+ 4 - 4
intelligine/synergy/object/ant/Ant.py Näytä tiedosto

@@ -1,8 +1,8 @@
1 1
 from intelligine.core.exceptions import MoleculeException
2 2
 from intelligine.synergy.object.Bug import Bug
3 3
 from intelligine.cst import CARRYING, TRANSPORTER, ATTACKER, COL_TRANSPORTER, COL_TRANSPORTER_NOT_CARRYING, \
4
-    COL_FIGHTER, MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5
-    COL_TRANSPORTER_CARRYING, MOVE_MODE_NURSE, MOVE_MODE_HOME
4
+    COL_FIGHTER, MODE_EXPLO, MODE_GOHOME, BODY_PART_PHEROMONE_GLAND, TYPE, TYPE_ANT, \
5
+    COL_TRANSPORTER_CARRYING, MODE_NURSE, MODE_HOME
6 6
 from intelligine.synergy.object.Food import Food
7 7
 from intelligine.simulation.object.molecule.MovementMoleculeGland import MovementMoleculeGland
8 8
 from intelligine.simulation.object.brain.AntBrain import AntBrain
@@ -22,7 +22,7 @@ class Ant(Bug):
22 22
                                                            COL_TRANSPORTER_NOT_CARRYING,
23 23
                                                            COL_FIGHTER])
24 24
         self._carried = None
25
-        self._brain.switch_to_mode(MOVE_MODE_EXPLO)
25
+        self._brain.switch_to_mode(MODE_EXPLO)
26 26
         context.metas.list.add(TYPE, self.get_id(), TYPE_ANT)
27 27
 
28 28
     def die(self):
@@ -58,7 +58,7 @@ class Ant(Bug):
58 58
         obj.set_is_carried(True, self)
59 59
         # TODO: pour le moment hardcode, a gerer dans AntTakeBrainPart (callback en fct de ce qui est depose)
60 60
         if isinstance(obj, Food):
61
-            self.get_brain().switch_to_mode(MOVE_MODE_GOHOME)
61
+            self.get_brain().switch_to_mode(MODE_GOHOME)
62 62
             self.get_movement_molecule_gland().appose()
63 63
 
64 64
     def is_carrying(self):

+ 9 - 9
intelligine/tests/simulation/mode/TestChangeMode.py Näytä tiedosto

@@ -11,7 +11,7 @@ from intelligine.tests.src.event.MoveAction import MoveAction as TestMoveAction
11 11
 from synergine.synergy.collection.SynergyCollection import SynergyCollection
12 12
 from synergine.synergy.collection.Configuration import Configuration
13 13
 from intelligine.core.Context import Context
14
-from intelligine.cst import MOVE_MODE_EXPLO, MOVE_MODE_GOHOME, MOVE_MODE, MOVE_MODE_HOME, PHEROMON_DIR_NONE
14
+from intelligine.cst import MODE_EXPLO, MODE_GOHOME, MODE, MODE_HOME, PHEROMON_DIR_NONE
15 15
 from intelligine.cst import PHEROMON_DIR_EXPLO
16 16
 
17 17
 
@@ -25,8 +25,8 @@ class TestChangeMode(Base):
25 25
 
26 26
     @staticmethod
27 27
     def _force_move(self_move_action, object_id, context):
28
-        object_movement_mode = context.metas.value.get(MOVE_MODE, object_id)
29
-        if object_movement_mode == MOVE_MODE_GOHOME or object_movement_mode == MOVE_MODE_HOME:
28
+        object_movement_mode = context.metas.value.get(MODE, object_id)
29
+        if object_movement_mode == MODE_GOHOME or object_movement_mode == MODE_HOME:
30 30
             return SOUTH
31 31
         return NORTH
32 32
 
@@ -104,12 +104,12 @@ class TestChangeMode(Base):
104 104
     def test_from_exploration_to_go_home(self):
105 105
         self._run_and_get_core(0)
106 106
         self.assertEquals((0, 0, 0), self.ant.get_position())
107
-        self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
107
+        self.assertEquals(MODE_EXPLO, self.ant.get_brain().get_movement_mode())
108 108
         self.assertFalse(self.ant.is_carrying())
109 109
 
110 110
         self._run_and_get_core(1)
111 111
         self.assertEquals((0, 0, -1), self.ant.get_position())
112
-        self.assertEquals(MOVE_MODE_EXPLO, self.ant.get_brain().get_movement_mode())
112
+        self.assertEquals(MODE_EXPLO, self.ant.get_brain().get_movement_mode())
113 113
         self.assertFalse(self.ant.is_carrying())
114 114
 
115 115
         # Ant has take Food piece
@@ -121,22 +121,22 @@ class TestChangeMode(Base):
121 121
         molecule = self.ant.get_movement_molecule_gland().get_molecule()
122 122
         # Now it appose exploration molecule
123 123
         self.assertEquals((PHEROMON_DIR_EXPLO, 0), (molecule.get_type(), molecule.get_distance()))
124
-        self.assertEquals(MOVE_MODE_GOHOME, self.ant.get_brain().get_movement_mode())
124
+        self.assertEquals(MODE_GOHOME, self.ant.get_brain().get_movement_mode())
125 125
         self.assertEquals(PHEROMON_DIR_EXPLO, self.ant.get_movement_molecule_gland().get_molecule_type())
126 126
 
127 127
         self._run_and_get_core(32)
128 128
         self.assertEquals((0, 0, -6), self.ant.get_position())
129 129
         self.assertTrue(self.ant.is_carrying())
130
-        self.assertEquals(MOVE_MODE_HOME, self.ant.get_brain().get_movement_mode())
130
+        self.assertEquals(MODE_HOME, self.ant.get_brain().get_movement_mode())
131 131
 
132 132
         self._run_and_get_core(33)
133 133
         self.assertEquals((0, 0, -5), self.ant.get_position())
134 134
         self.assertTrue(self.ant.is_carrying())
135
-        self.assertEquals(MOVE_MODE_HOME, self.ant.get_brain().get_movement_mode())
135
+        self.assertEquals(MODE_HOME, self.ant.get_brain().get_movement_mode())
136 136
 
137 137
         self._run_and_get_core(34)
138 138
         self.assertEquals((0, 0, -4), self.ant.get_position())
139
-        self.assertEquals(MOVE_MODE_HOME, self.ant.get_brain().get_movement_mode())
139
+        self.assertEquals(MODE_HOME, self.ant.get_brain().get_movement_mode())
140 140
 
141 141
         self._run_and_get_core(37)
142 142
         self.assertEquals((0, 0, -1), self.ant.get_position())