|
|
|
|
5
|
from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE, MOVE_MODE, MOVE_MODE_EXPLO
|
5
|
from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE, MOVE_MODE, MOVE_MODE_EXPLO
|
6
|
from intelligine.cst import COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
|
6
|
from intelligine.cst import COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING
|
7
|
from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
|
7
|
from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
|
|
|
8
|
+from intelligine.synergy.event.move.direction import get_position_with_direction_decal
|
8
|
from intelligine.core.exceptions import NoPheromone, BestPheromoneHere
|
9
|
from intelligine.core.exceptions import NoPheromone, BestPheromoneHere
|
9
|
from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
|
10
|
from intelligine.simulation.pheromone.DirectionPheromone import DirectionPheromone
|
10
|
|
11
|
|
|
|
|
|
26
|
except NoPheromone:
|
27
|
except NoPheromone:
|
27
|
direction = self._get_random_direction(context)
|
28
|
direction = self._get_random_direction(context)
|
28
|
|
29
|
|
29
|
- move_to_point = self._get_point_for_direction(object_point, direction)
|
|
|
|
|
30
|
+ move_to_point = get_position_with_direction_decal(direction, object_point)
|
30
|
if self._direction_point_is_possible(context, move_to_point):
|
31
|
if self._direction_point_is_possible(context, move_to_point):
|
31
|
self._move_to_point = move_to_point
|
32
|
self._move_to_point = move_to_point
|
32
|
self._move_to_direction = direction
|
33
|
self._move_to_direction = direction
|
|
|
|
|
35
|
pass
|
36
|
pass
|
36
|
|
37
|
|
37
|
def _get_direction_with_pheromones(self, context, object_point):
|
38
|
def _get_direction_with_pheromones(self, context, object_point):
|
38
|
- # TODO: Placer directnement pheromone type dans les metas
|
|
|
39
|
object_movement_mode = context.metas.value.get(MOVE_MODE, self._object_id)
|
39
|
object_movement_mode = context.metas.value.get(MOVE_MODE, self._object_id)
|
40
|
pheromone_type = DirectionPheromone.get_pheromone_type_for_move_mode(object_movement_mode)
|
40
|
pheromone_type = DirectionPheromone.get_pheromone_type_for_move_mode(object_movement_mode)
|
41
|
try:
|
41
|
try:
|
42
|
direction = self._get_pheromone_direction_for_point(context, object_point, pheromone_type)
|
42
|
direction = self._get_pheromone_direction_for_point(context, object_point, pheromone_type)
|
43
|
except NoPheromone:
|
43
|
except NoPheromone:
|
44
|
- direction = self._get_direction_of_pheromone(context, object_point, pheromone_type)
|
|
|
|
|
44
|
+ try:
|
|
|
45
|
+ direction = self._get_direction_of_pheromone(context, object_point, pheromone_type)
|
|
|
46
|
+ except NoPheromone:
|
|
|
47
|
+ raise
|
45
|
return direction
|
48
|
return direction
|
46
|
|
49
|
|
47
|
@staticmethod
|
50
|
@staticmethod
|
|
|
|
|
50
|
|
53
|
|
51
|
@staticmethod
|
54
|
@staticmethod
|
52
|
def _get_direction_of_pheromone(context, point, pheromone_type):
|
55
|
def _get_direction_of_pheromone(context, point, pheromone_type):
|
53
|
- search_pheromone_distance = 1 # TODO: config
|
|
|
54
|
- search_pheromone_in_points = context.get_arround_points_of(point, distance=search_pheromone_distance)
|
|
|
|
|
56
|
+ search_pheromone_in_points = context.get_arround_points_of(point, distance=1)
|
55
|
try:
|
57
|
try:
|
56
|
- # TODO: ? Avoir plutot un DirectionPheromone.get_best_pheromone_direction_in ?
|
|
|
57
|
best_pheromone_direction = DirectionPheromone.get_best_pheromone_direction_in(context,
|
58
|
best_pheromone_direction = DirectionPheromone.get_best_pheromone_direction_in(context,
|
58
|
point,
|
59
|
point,
|
59
|
search_pheromone_in_points,
|
60
|
search_pheromone_in_points,
|
|
|
|
|
62
|
except NoPheromone as err:
|
63
|
except NoPheromone as err:
|
63
|
raise err
|
64
|
raise err
|
64
|
|
65
|
|
65
|
- # def _get_random_direction_point(self, context, reference_point):
|
|
|
66
|
- # z, x, y = reference_point
|
|
|
67
|
- # direction_name = self._get_random_direction_name(context)
|
|
|
68
|
- # directions_modifier = directions_modifiers[direction_name]
|
|
|
69
|
- # new_position = (z + directions_modifier[0], x + directions_modifier[1], y + directions_modifier[2])
|
|
|
70
|
- # return (direction_name, new_position)
|
|
|
71
|
-
|
|
|
72
|
def _get_random_direction(self, context):
|
66
|
def _get_random_direction(self, context):
|
73
|
try:
|
67
|
try:
|
74
|
blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id)
|
68
|
blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id)
|
|
|
|
|
96
|
return direction_name
|
90
|
return direction_name
|
97
|
|
91
|
|
98
|
@staticmethod
|
92
|
@staticmethod
|
99
|
- def _get_point_for_direction(reference_point, direction):
|
|
|
100
|
- # TODO: mettre une fonction cote direction.py pour appliquer le modifier.
|
|
|
101
|
- z, x, y = reference_point
|
|
|
102
|
- directions_modifier = directions_modifiers[direction]
|
|
|
103
|
- return z + directions_modifier[0], x + directions_modifier[1], y + directions_modifier[2]
|
|
|
104
|
-
|
|
|
105
|
- @staticmethod
|
|
|
106
|
def _direction_point_is_possible(context, direction_point):
|
93
|
def _direction_point_is_possible(context, direction_point):
|
107
|
return context.position_is_penetrable(direction_point)
|
94
|
return context.position_is_penetrable(direction_point)
|
108
|
|
95
|
|
109
|
def run(self, obj, context, synergy_manager):
|
96
|
def run(self, obj, context, synergy_manager):
|
110
|
if self._move_to_point is not None and self._move_to_direction != 14: # TODO: il ne faut pas choisir une direction 14.
|
97
|
if self._move_to_point is not None and self._move_to_direction != 14: # TODO: il ne faut pas choisir une direction 14.
|
111
|
obj.set_position(self._move_to_point)
|
98
|
obj.set_position(self._move_to_point)
|
112
|
- #direction_from = directions_opposites[self._move_to_direction]
|
|
|
113
|
- #obj.set_direction_from(direction_from)
|
|
|
114
|
context.metas.value.set(PREVIOUS_DIRECTION, self._object_id, self._move_to_direction)
|
99
|
context.metas.value.set(PREVIOUS_DIRECTION, self._object_id, self._move_to_direction)
|
115
|
context.metas.value.set(BLOCKED_SINCE, self._object_id, 0)
|
100
|
context.metas.value.set(BLOCKED_SINCE, self._object_id, 0)
|
116
|
self._appose_pheromone(obj, context)
|
101
|
self._appose_pheromone(obj, context)
|
|
|
|
|
122
|
obj.put_carry(obj_transported, (-1, 0, 0))
|
107
|
obj.put_carry(obj_transported, (-1, 0, 0))
|
123
|
obj.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
|
108
|
obj.get_brain().switch_to_mode(MOVE_MODE_EXPLO)
|
124
|
context.metas.collections.add_remove(obj.get_id(),
|
109
|
context.metas.collections.add_remove(obj.get_id(),
|
125
|
- COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING)
|
|
|
126
|
-
|
|
|
127
|
- # TMP: Devra etre un event et une action
|
|
|
128
|
- # if self._move_to_point == (0, 5, 5): # position de depart
|
|
|
129
|
- # if len(obj._carried):
|
|
|
130
|
- # obj_transported = obj.get_carried()
|
|
|
131
|
- # obj_transported.set_carried_by(None)
|
|
|
132
|
- # obj.put_carry(obj_transported, (-1, 5, 5))
|
|
|
133
|
- # context.metas.collections.add_remove(obj.get_id(), COL_TRANSPORTER_NOT_CARRYING, COL_TRANSPORTER_CARRYING)
|
|
|
134
|
- # obj.set_movement_mode(MOVE_MODE_EXPLO)
|
|
|
135
|
-
|
|
|
136
|
-
|
|
|
|
|
110
|
+ COL_TRANSPORTER_NOT_CARRYING,
|
|
|
111
|
+ COL_TRANSPORTER_CARRYING)
|
137
|
else:
|
112
|
else:
|
138
|
try:
|
113
|
try:
|
139
|
blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id)
|
114
|
blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id)
|
|
|
|
|
141
|
blocked_since = 0
|
116
|
blocked_since = 0
|
142
|
context.metas.value.set(BLOCKED_SINCE, self._object_id, blocked_since+1)
|
117
|
context.metas.value.set(BLOCKED_SINCE, self._object_id, blocked_since+1)
|
143
|
|
118
|
|
144
|
- # def _get_pheromone_direction_point(self, context, object_point):
|
|
|
145
|
- # try:
|
|
|
146
|
- # blocked_since = context.metas.value.get(BLOCKED_SINCE, self._object_id)
|
|
|
147
|
- # except KeyError:
|
|
|
148
|
- # blocked_since = 0
|
|
|
149
|
- # if blocked_since > 3:
|
|
|
150
|
- # raise NoPheromoneMove()
|
|
|
151
|
- # # Si on explore, on cherche pheromone d'explo
|
|
|
152
|
- # # si on rentre a home, on cherche pheromone d'home...
|
|
|
153
|
- # # TODO: code arrache
|
|
|
154
|
- # object_movement_mode = context.metas.value.get(MOVE_MODE, self._object_id)
|
|
|
155
|
- # if object_movement_mode == MOVE_MODE_EXPLO:
|
|
|
156
|
- # pheromone_direction_type = PHEROMON_DIR_EXPLO
|
|
|
157
|
- # elif object_movement_mode == MOVE_MODE_GOHOME:
|
|
|
158
|
- # pheromone_direction_type = PHEROMON_DIR_HOME
|
|
|
159
|
- #
|
|
|
160
|
- # sniff_points = context.get_arround_points_of(object_point, distance=0)
|
|
|
161
|
- # # Faire un compile des infos de pheromones
|
|
|
162
|
- #
|
|
|
163
|
- # directions = {}
|
|
|
164
|
- # for sniff_point in sniff_points:
|
|
|
165
|
- # info = context.pheromones().get_info(sniff_point,
|
|
|
166
|
- # [PHEROMON_DIRECTION, pheromone_direction_type],
|
|
|
167
|
- # allow_empty=True,
|
|
|
168
|
- # empty_value={})
|
|
|
169
|
- # for direction in info:
|
|
|
170
|
- # if direction not in directions:
|
|
|
171
|
- # directions[direction] = info[direction]
|
|
|
172
|
- # else:
|
|
|
173
|
- # directions[direction] += info[direction]
|
|
|
174
|
- # if len(directions):
|
|
|
175
|
- # sorted_directions = sorted(directions.items(), key=operator.itemgetter(1))
|
|
|
176
|
- # sorted_directions.reverse()
|
|
|
177
|
- # #best_direction_name = sorted_directions[0][0]
|
|
|
178
|
- # best_direction_level = sorted_directions[0][1]
|
|
|
179
|
- # best_direction_names = [direction for direction in directions \
|
|
|
180
|
- # if directions[direction] == best_direction_level]
|
|
|
181
|
- # # Si plusieurs best directions, choisir mm direction que la precedente
|
|
|
182
|
- # # si y a pas, au hasard.
|
|
|
183
|
- # last_dir_name = context.metas.value.get(PREVIOUS_DIRECTION, self._object_id)
|
|
|
184
|
- # if last_dir_name in best_direction_names:
|
|
|
185
|
- # direction_name = last_dir_name
|
|
|
186
|
- # else:
|
|
|
187
|
- # direction_name = choice(best_direction_names)
|
|
|
188
|
- #
|
|
|
189
|
- # # DRY
|
|
|
190
|
- # z, x, y = object_point
|
|
|
191
|
- # directions_modifier = directions_modifiers[direction_name]
|
|
|
192
|
- # new_position = (z + directions_modifier[0], x + directions_modifier[1], y + directions_modifier[2])
|
|
|
193
|
- # return (direction_name, new_position)
|
|
|
194
|
- #
|
|
|
195
|
- # pass
|
|
|
196
|
- # raise NoPheromoneMove()
|
|
|
197
|
-
|
|
|
198
|
- def _appose_pheromone(self, obj, context):
|
|
|
|
|
119
|
+ @staticmethod
|
|
|
120
|
+ def _appose_pheromone(obj, context):
|
199
|
# TODO: Cette action de pheromone doit etre une surcharge de Move afin d'avoir une Action Move generique.
|
121
|
# TODO: Cette action de pheromone doit etre une surcharge de Move afin d'avoir une Action Move generique.
|
200
|
obj.get_brain().host_moved()
|
122
|
obj.get_brain().host_moved()
|
201
|
try:
|
123
|
try:
|