|  | @@ -1,3 +1,4 @@
 | 
	
		
			
			|  | 1 | +from intelligine.core.exceptions import DirectionException
 | 
	
		
			
			| 1 | 2 |  from intelligine.simulation.object.brain.part.BrainPart import BrainPart
 | 
	
		
			
			| 2 | 3 |  from intelligine.synergy.event.move.direction import directions_same_level, directions_slighty
 | 
	
		
			
			| 3 | 4 |  from random import randint, choice, randrange
 | 
	
	
		
			
			|  | @@ -8,15 +9,15 @@ class MoveBrainPart(BrainPart):
 | 
	
		
			
			| 8 | 9 |  
 | 
	
		
			
			| 9 | 10 |      @classmethod
 | 
	
		
			
			| 10 | 11 |      def get_direction(cls, context, object_id):
 | 
	
		
			
			| 11 |  | -        return cls._get_random_direction(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)
 | 
	
		
			
			| 12 | 16 |  
 | 
	
		
			
			| 13 | 17 |      @classmethod
 | 
	
		
			
			| 14 |  | -    def _get_random_direction(cls, context, object_id):
 | 
	
		
			
			| 15 |  | -        try:
 | 
	
		
			
			| 16 |  | -            blocked_since = context.metas.value.get(BLOCKED_SINCE, object_id)
 | 
	
		
			
			| 17 |  | -        except KeyError:
 | 
	
		
			
			| 18 |  | -            blocked_since = 0
 | 
	
		
			
			| 19 |  | -        direction_name = None
 | 
	
		
			
			|  | 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)
 | 
	
		
			
			| 20 | 21 |          if blocked_since <= 3:  #TODO: config
 | 
	
		
			
			| 21 | 22 |              try:
 | 
	
		
			
			| 22 | 23 |                  previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, object_id)
 | 
	
	
		
			
			|  | @@ -28,11 +29,12 @@ class MoveBrainPart(BrainPart):
 | 
	
		
			
			| 28 | 29 |                  directions_list = directions_slighty[previous_direction]
 | 
	
		
			
			| 29 | 30 |                  # TODO: TMP tant que 1 niveau (z)
 | 
	
		
			
			| 30 | 31 |                  directions_list = [direction for direction in directions_list if 9 < direction < 19]
 | 
	
		
			
			| 31 |  | -                direction_name = choice(directions_list)
 | 
	
		
			
			|  | 32 | +                return choice(directions_list)
 | 
	
		
			
			| 32 | 33 |              except KeyError:
 | 
	
		
			
			| 33 | 34 |                  pass
 | 
	
		
			
			| 34 | 35 |  
 | 
	
		
			
			| 35 |  | -        if not direction_name:
 | 
	
		
			
			| 36 |  | -            direction_name = randint(directions_same_level)
 | 
	
		
			
			|  | 36 | +        raise DirectionException()
 | 
	
		
			
			| 37 | 37 |  
 | 
	
		
			
			| 38 |  | -        return direction_name
 | 
	
		
			
			|  | 38 | +    @classmethod
 | 
	
		
			
			|  | 39 | +    def _get_random_direction(cls, context, object_id):
 | 
	
		
			
			|  | 40 | +        return randint(directions_same_level)
 |