|
@@ -1,13 +1,12 @@
|
1
|
|
-from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
|
|
1
|
+from intelligine.simulation.object.brain.part.move.AntStar.ByPass import ByPass
|
|
2
|
+from intelligine.simulation.object.brain.part.move.AntStar.Host import Host
|
2
|
3
|
from intelligine.simulation.object.brain.part.move.MoveBrainPart import MoveBrainPart
|
3
|
|
-from intelligine.synergy.event.move.direction import directions_modifiers, get_direction_for_degrees
|
|
4
|
+from intelligine.synergy.event.move.direction import directions_modifiers
|
4
|
5
|
from synergine_xyz.cst import POSITION
|
5
|
6
|
from intelligine.core.exceptions import NoMolecule, NoTypeInMolecule
|
6
|
|
-from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, \
|
7
|
|
- MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, EXPLORATION_VECTOR, POINTS_SMELL, MOLECULES, MOLECULES_DIRECTION, \
|
8
|
|
- SMELL_FOOD, SMELL_EGG
|
|
7
|
+from intelligine.cst import MOLECULE_SEARCHING, MOVE_MODE_EXPLO, MOVE_MODE_HOME, MOVE_MODE, MOVE_MODE_GOHOME, \
|
|
8
|
+ EXPLORATION_VECTOR, MOLECULES_DIRECTION, SMELL_FOOD, SMELL_EGG
|
9
|
9
|
from intelligine.simulation.molecule.DirectionMolecule import DirectionMolecule
|
10
|
|
-from synergine_xyz.geometry import get_degree_from_north
|
11
|
10
|
|
12
|
11
|
|
13
|
12
|
class AntMoveBrainPart(MoveBrainPart):
|
|
@@ -58,25 +57,27 @@ class AntMoveBrainPart(MoveBrainPart):
|
58
|
57
|
search_molecule_in_points = context.get_around_points_of_point(point)
|
59
|
58
|
try:
|
60
|
59
|
best_molecule_direction = DirectionMolecule.get_best_molecule_direction_in(context,
|
61
|
|
- point,
|
62
|
|
- search_molecule_in_points,
|
63
|
|
- molecule_type)
|
|
60
|
+ point,
|
|
61
|
+ search_molecule_in_points,
|
|
62
|
+ molecule_type)
|
64
|
63
|
return best_molecule_direction
|
65
|
64
|
except NoMolecule as err:
|
66
|
65
|
raise err
|
67
|
66
|
|
68
|
|
- @staticmethod
|
69
|
|
- def _get_direction_with_exploration_vector(context, object_id):
|
70
|
|
- current_position = context.metas.value.get(POSITION, object_id)
|
71
|
|
- exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
|
72
|
|
- # TODO: inverser (math)
|
73
|
|
- home_vector = (exploration_vector[0] - (exploration_vector[0]*2),
|
74
|
|
- exploration_vector[1] - (exploration_vector[1]*2))
|
75
|
|
- home_position = (0, current_position[1]+home_vector[0], current_position[2]+home_vector[1])
|
76
|
|
- degree_from_north = get_degree_from_north(current_position, home_position)
|
77
|
|
- direction_for_home_vector = get_direction_for_degrees(degree_from_north)
|
|
67
|
+ @classmethod
|
|
68
|
+ def _get_direction_with_exploration_vector(cls, context, object_id):
|
|
69
|
+ ant_star = cls._get_by_pass_brain(context, object_id)
|
|
70
|
+ ant_star.advance()
|
|
71
|
+ ant_star.has_moved()
|
|
72
|
+ return ant_star.get_host().get_moved_to_direction()
|
78
|
73
|
|
79
|
|
- return direction_for_home_vector
|
|
74
|
+ @classmethod
|
|
75
|
+ def _get_by_pass_brain(cls, context, object_id):
|
|
76
|
+ # We use an adaptation of AntStar
|
|
77
|
+ exploration_vector = context.metas.value.get(EXPLORATION_VECTOR, object_id)
|
|
78
|
+ home_vector = (-exploration_vector[0], -exploration_vector[1])
|
|
79
|
+ ant_host = Host(context, object_id)
|
|
80
|
+ return ByPass(ant_host, home_vector, context, object_id)
|
80
|
81
|
|
81
|
82
|
# TODO: obj pas necessaire, il est dans _host
|
82
|
83
|
def done(self, obj, context):
|
|
@@ -106,12 +107,17 @@ class AntMoveBrainPart(MoveBrainPart):
|
106
|
107
|
|
107
|
108
|
if movement_mode == MOVE_MODE_GOHOME and self._on_home_smell(context, obj.get_id()):
|
108
|
109
|
self._host_brain.switch_to_mode(MOVE_MODE_HOME)
|
|
110
|
+ ant_star = self._get_by_pass_brain(context, obj.get_id())
|
|
111
|
+ ant_star.erase()
|
109
|
112
|
# TODO: on change les molecule recherché (Food => SmellFood, definis dans Take, en fct de ce qui est take)
|
110
|
113
|
|
111
|
114
|
elif movement_mode == MOVE_MODE_HOME and not self._on_home_smell(context, obj.get_id()):
|
112
|
115
|
self._host_brain.switch_to_mode(MOVE_MODE_EXPLO)
|
113
|
116
|
self._start_new_exploration()
|
114
|
117
|
|
|
118
|
+ elif movement_mode == MOVE_MODE_EXPLO and self._on_home_smell(context, obj.get_id()):
|
|
119
|
+ self._start_new_exploration() # TODO: rename en reinit_explo
|
|
120
|
+
|
115
|
121
|
# TODO: sitch explo si rien a faire (rien a poser par exemple) et HOME
|
116
|
122
|
|
117
|
123
|
# TODO: Poser sur StockedFood
|
|
@@ -135,7 +141,6 @@ class AntMoveBrainPart(MoveBrainPart):
|
135
|
141
|
self._set_exploration_vector((self._exploration_vector[0] + just_move_vector[1],
|
136
|
142
|
self._exploration_vector[1] + just_move_vector[2]))
|
137
|
143
|
|
138
|
|
-
|
139
|
144
|
def _apply_context(self, obj, context):
|
140
|
145
|
movement_mode = self._host_brain.get_movement_mode()
|
141
|
146
|
if movement_mode == MOVE_MODE_EXPLO or movement_mode == MOVE_MODE_GOHOME:
|