|
|
|
|
12
|
context.pheromones().increment_with_pheromone(point, pheromone)
|
12
|
context.pheromones().increment_with_pheromone(point, pheromone)
|
13
|
context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, point, assert_not_in=False)
|
13
|
context.metas.list.add(PHEROMON_POSITIONS, PHEROMON_POSITIONS, point, assert_not_in=False)
|
14
|
|
14
|
|
15
|
- @staticmethod
|
|
|
16
|
- def get_direction_for_point(context, point, pheromone_type):
|
|
|
|
|
15
|
+ @classmethod
|
|
|
16
|
+ def get_direction_for_point(cls, context, point, pheromone_type):
|
17
|
flavour = context.pheromones().get_flavour(point)
|
17
|
flavour = context.pheromones().get_flavour(point)
|
18
|
pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
|
18
|
pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
|
19
|
|
19
|
|
20
|
distance = pheromone.get_distance()
|
20
|
distance = pheromone.get_distance()
|
21
|
- around_points = context.get_around_points_of(point)
|
|
|
22
|
- # TODO: Cet algo around a mettre ailleurs
|
|
|
23
|
- around_pheromones_points = []
|
|
|
24
|
- for around_point in around_points:
|
|
|
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
|
|
|
|
|
21
|
+ around_pheromone_filter = lambda around_pheromone: around_pheromone.get_distance() < distance
|
|
|
22
|
+ around_pheromones_points = cls._get_around_pheromones(context, point, pheromone_type,
|
|
|
23
|
+ pheromone_filter=around_pheromone_filter)
|
32
|
|
24
|
|
33
|
if not around_pheromones_points:
|
25
|
if not around_pheromones_points:
|
34
|
raise NoPheromone()
|
26
|
raise NoPheromone()
|
|
|
|
|
54
|
return direction
|
46
|
return direction
|
55
|
|
47
|
|
56
|
@staticmethod
|
48
|
@staticmethod
|
|
|
49
|
+ def _get_around_pheromones(context, reference_point, pheromone_type,
|
|
|
50
|
+ pheromone_filter=lambda around_pheromone: True):
|
|
|
51
|
+ around_points = context.get_around_points_of(reference_point)
|
|
|
52
|
+ around_pheromones_points = []
|
|
|
53
|
+ for around_point in around_points:
|
|
|
54
|
+ flavour = context.pheromones().get_flavour(around_point)
|
|
|
55
|
+ try:
|
|
|
56
|
+ around_pheromone = flavour.get_pheromone(category=PHEROMON_DIRECTION, type=pheromone_type)
|
|
|
57
|
+ if pheromone_filter(around_pheromone):
|
|
|
58
|
+ around_pheromones_points.append((around_point, around_pheromone))
|
|
|
59
|
+ except NoPheromone:
|
|
|
60
|
+ pass # No pheromone, ok continue to sniff around
|
|
|
61
|
+
|
|
|
62
|
+ return around_pheromones_points
|
|
|
63
|
+
|
|
|
64
|
+ @staticmethod
|
57
|
def get_best_pheromone_direction_in(context, reference_point, points, pheromone_type):
|
65
|
def get_best_pheromone_direction_in(context, reference_point, points, pheromone_type):
|
58
|
around_pheromones_points = []
|
66
|
around_pheromones_points = []
|
59
|
for around_point in points:
|
67
|
for around_point in points:
|