|
@@ -8,48 +8,43 @@ from intelligine.synergy.event.move.direction import get_direction_for_degrees
|
8
|
8
|
class DirectionPheromone():
|
9
|
9
|
|
10
|
10
|
@staticmethod
|
11
|
|
- def appose(context, point, movement_molecules):
|
12
|
|
- pheromone_type, distance_from = movement_molecules
|
13
|
|
- context.pheromones().increment(point, [PHEROMON_DIRECTION, pheromone_type], distance=distance_from)
|
|
11
|
+ def appose(context, point, pheromone):
|
|
12
|
+ context.pheromones().increment_with_pheromone(point, pheromone)
|
14
|
13
|
context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, point, assert_not_in=False)
|
15
|
14
|
|
16
|
15
|
@staticmethod
|
17
|
16
|
def get_direction_for_point(context, point, pheromone_type):
|
18
|
|
- try:
|
19
|
|
- pheromone_info = context.pheromones().get_info(point, [PHEROMON_DIRECTION, pheromone_type])
|
20
|
|
- except KeyError:
|
21
|
|
- raise NoPheromone()
|
22
|
|
-
|
23
|
|
- # DEBUG: On se rettrouve avec un {} ...
|
24
|
|
- if not pheromone_info:
|
25
|
|
- raise NoPheromone()
|
|
17
|
+ flavour = context.pheromones().get_flavour(point)
|
|
18
|
+ pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
|
26
|
19
|
|
27
|
|
- point_intensity = pheromone_info[1]
|
28
|
|
- point_distance = pheromone_info[0]
|
|
20
|
+ distance = pheromone.get_distance()
|
29
|
21
|
around_points = context.get_around_points_of(point)
|
30
|
|
-
|
|
22
|
+ # TODO: Cet algo around a mettre ailleurs
|
31
|
23
|
around_pheromones_points = []
|
32
|
24
|
for around_point in around_points:
|
33
|
|
- around_pheromone_info = context.pheromones().get_info(around_point,
|
34
|
|
- [PHEROMON_DIRECTION, pheromone_type],
|
35
|
|
- allow_empty=True,
|
36
|
|
- empty_value={})
|
37
|
|
- if around_pheromone_info and around_pheromone_info[0] < point_distance:
|
38
|
|
- around_pheromones_points.append((around_point, around_pheromone_info))
|
|
25
|
+ flavour = context.pheromones().get_flavour(around_point)
|
|
26
|
+ try:
|
|
27
|
+ around_pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
|
|
28
|
+ if around_pheromone.get_distance() < distance:
|
|
29
|
+ around_pheromones_points.append((around_point, around_pheromone))
|
|
30
|
+ except NoPheromone:
|
|
31
|
+ pass # No pheromone, ok continue to sniff around
|
39
|
32
|
|
40
|
33
|
if not around_pheromones_points:
|
41
|
34
|
raise NoPheromone()
|
42
|
35
|
|
43
|
36
|
shuffle(around_pheromones_points)
|
44
|
|
- around_pheromones_sorted = sorted(around_pheromones_points, key=lambda x: x[1][1], reverse=True)
|
45
|
|
- max_intensity = around_pheromones_sorted[0][1][1]
|
|
37
|
+ around_pheromones_sorted = sorted(around_pheromones_points, key=lambda x: x[1].get_intensity(), reverse=True)
|
|
38
|
+ max_intensity = around_pheromones_sorted[0][1].get_intensity()
|
46
|
39
|
|
47
|
40
|
around_pheromones_max = []
|
48
|
41
|
for around_pheromone_sorted in around_pheromones_sorted:
|
49
|
|
- if around_pheromone_sorted[1][1] == max_intensity:
|
|
42
|
+ if around_pheromone_sorted[1].get_intensity() == max_intensity:
|
50
|
43
|
around_pheromones_max.append(around_pheromone_sorted)
|
51
|
44
|
|
52
|
|
- around_pheromones_sorted_by_distance = sorted(around_pheromones_max, key=lambda x: x[1][0], reverse=False)
|
|
45
|
+ around_pheromones_sorted_by_distance = sorted(around_pheromones_max,
|
|
46
|
+ key=lambda x: x[1].get_distance(),
|
|
47
|
+ reverse=False)
|
53
|
48
|
|
54
|
49
|
go_to_point = around_pheromones_sorted_by_distance[0][0]
|
55
|
50
|
|
|
@@ -76,18 +71,18 @@ class DirectionPheromone():
|
76
|
71
|
def get_best_pheromone_direction_in(context, reference_point, points, pheromone_type):
|
77
|
72
|
around_pheromones_points = []
|
78
|
73
|
for around_point in points:
|
79
|
|
- around_pheromone_info = context.pheromones().get_info(around_point,
|
80
|
|
- [PHEROMON_DIRECTION, pheromone_type],
|
81
|
|
- allow_empty=True,
|
82
|
|
- empty_value={})
|
83
|
|
- if around_pheromone_info:
|
84
|
|
- around_pheromones_points.append((around_point, around_pheromone_info))
|
|
74
|
+ flavour = context.pheromones().get_flavour(around_point)
|
|
75
|
+ try:
|
|
76
|
+ around_pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
|
|
77
|
+ around_pheromones_points.append((around_point, around_pheromone))
|
|
78
|
+ except NoPheromone:
|
|
79
|
+ pass # Ok, no pheromone, continue to sniff around
|
85
|
80
|
|
86
|
81
|
if not around_pheromones_points:
|
87
|
82
|
raise NoPheromone()
|
88
|
83
|
|
89
|
84
|
shuffle(around_pheromones_points)
|
90
|
|
- around_pheromones_sorted = sorted(around_pheromones_points, key=lambda x: x[1][1], reverse=True)
|
|
85
|
+ around_pheromones_sorted = sorted(around_pheromones_points, key=lambda x: x[1].get_intensity(), reverse=True)
|
91
|
86
|
go_to_point = around_pheromones_sorted[0][0]
|
92
|
87
|
|
93
|
88
|
direction_degrees = get_degree_from_north(reference_point, go_to_point)
|