1
|
|
|
from intelligine.core.exceptions import DirectionException |
2
|
|
|
from intelligine.simulation.object.brain.part.BrainPart import BrainPart |
3
|
|
|
from intelligine.synergy.event.move.direction import directions_same_level, directions_slighty |
4
|
|
|
from random import randint, choice, randrange |
5
|
|
|
from synergine_xyz.cst import BLOCKED_SINCE, PREVIOUS_DIRECTION |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class MoveBrainPart(BrainPart): |
9
|
|
|
|
10
|
|
|
@classmethod |
11
|
|
|
def get_direction(cls, context, object_id): |
12
|
|
|
try: |
13
|
|
|
return cls._get_slighty_direction(context, object_id) |
14
|
|
|
except DirectionException: |
15
|
|
|
return cls._get_random_direction(context, object_id) |
16
|
|
|
|
17
|
|
|
@classmethod |
18
|
|
|
def _get_slighty_direction(cls, context, object_id): |
19
|
|
|
# TODO: A terme le calcul de la direction devra prendre en compte les directions bloques |
20
|
|
|
blocked_since = context.metas.value.get(BLOCKED_SINCE, object_id, allow_empty=True, empty_value=0) |
21
|
|
|
if blocked_since <= 3: #TODO: config |
22
|
|
|
try: |
23
|
|
|
previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, object_id) |
24
|
|
|
except KeyError: |
25
|
|
|
# No previous direction |
26
|
|
|
return cls._get_random_direction(context, object_id) |
27
|
|
|
# TODO: Faut mettre ca en plus propre (proba d'aller tou droit, config, etc) |
28
|
|
|
if randrange(100) < 75: # 75% de change d'aller tout droit |
29
|
|
|
# Dans le futur: les fourmis vont moins tout droit quand elle se croient et se touche |
30
|
|
|
return previous_direction |
31
|
|
|
|
32
|
|
|
directions_list = directions_slighty[previous_direction] |
33
|
|
|
# TODO: TMP tant que 1 niveau (z) |
34
|
|
|
directions_list = [direction for direction in directions_list if 9 < direction < 19] |
35
|
|
|
return choice(directions_list) |
36
|
|
|
|
37
|
|
|
raise DirectionException() |
38
|
|
|
|
39
|
|
|
@classmethod |
40
|
|
|
def _get_random_direction(cls, context, object_id): |
41
|
|
|
return randint(directions_same_level[0], directions_same_level[-1]) |