|
@@ -1,9 +1,10 @@
|
1
|
1
|
from synergine.synergy.event.Action import Action
|
2
|
2
|
from intelligine.synergy.event.move.MoveEvent import MoveEvent
|
3
|
|
-from random import randint, choice
|
|
3
|
+from random import randint, choice, randrange
|
4
|
4
|
from xyzworld.cst import POSITION, POSITIONS
|
5
|
5
|
from intelligine.cst import PREVIOUS_DIRECTION, BLOCKED_SINCE
|
6
|
6
|
from intelligine.synergy.event.move.direction import directions_same_level, directions_modifiers, directions_slighty
|
|
7
|
+from intelligine.core.exceptions import NoPheromoneMove
|
7
|
8
|
|
8
|
9
|
|
9
|
10
|
class MoveAction(Action):
|
|
@@ -17,7 +18,10 @@ class MoveAction(Action):
|
17
|
18
|
|
18
|
19
|
def prepare(self, context):
|
19
|
20
|
object_point = context.metas.value.get(POSITION, self._object_id)
|
20
|
|
- choosed_direction_name, choosed_direction_point = self._get_random_direction_point(context, object_point)
|
|
21
|
+ try:
|
|
22
|
+ choosed_direction_name, choosed_direction_point = self._get_pheromone_direction_point(context, object_point)
|
|
23
|
+ except NoPheromoneMove:
|
|
24
|
+ choosed_direction_name, choosed_direction_point = self._get_random_direction_point(context, object_point)
|
21
|
25
|
if self._direction_point_is_possible(context, choosed_direction_point):
|
22
|
26
|
self._move_to_point = choosed_direction_point
|
23
|
27
|
self._move_to_direction = choosed_direction_name
|
|
@@ -38,6 +42,11 @@ class MoveAction(Action):
|
38
|
42
|
if blocked_since <= 3: #TODO: config
|
39
|
43
|
try:
|
40
|
44
|
previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, self._object_id)
|
|
45
|
+ # TODO: Faut mettre ca en plus propre (proba d'aller tou droit, config, etc)
|
|
46
|
+ if randrange(100) < 75: # 75% de change d'aller tout droit
|
|
47
|
+ # Dans le futur: les fourmis vont moins tout droit quand elle se croient et se touche
|
|
48
|
+ return previous_direction
|
|
49
|
+
|
41
|
50
|
directions_list = directions_slighty[previous_direction]
|
42
|
51
|
# TODO: TMP tant que 1 niveau (z)
|
43
|
52
|
directions_list = [direction for direction in directions_list if direction > 9 and direction < 19]
|
|
@@ -64,3 +73,7 @@ class MoveAction(Action):
|
64
|
73
|
except:
|
65
|
74
|
blocked_since = 0
|
66
|
75
|
context.metas.value.set(BLOCKED_SINCE, self._object_id, blocked_since+1)
|
|
76
|
+
|
|
77
|
+ def _get_pheromone_direction_point(self, context, object_point):
|
|
78
|
+
|
|
79
|
+ raise NoPheromoneMove()
|