Bläddra i källkod

Put object only if free space around

Bastien Sevajol 9 år sedan
förälder
incheckning
d86c315af5
1 ändrade filer med 22 tillägg och 2 borttagningar
  1. 22 2
      intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py

+ 22 - 2
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py Visa fil

@@ -54,16 +54,36 @@ class AntPutBrainPart(TransportBrainPart):
54 54
                     return pos_around_target
55 55
         raise CantFindWhereToPut()
56 56
 
57
-    @staticmethod
58
-    def _is_available_position(context, position):
57
+    @classmethod
58
+    def _is_available_position(cls, context, position):
59 59
         if not context.position_is_penetrable(position):
60 60
             return False
61 61
 
62
+        if not cls._position_is_enought_place(context, position):
63
+            return False
64
+
65
+        if not cls._position_have_free_space_around(context, position):
66
+            return False
67
+
68
+        return True
69
+
70
+    @classmethod
71
+    def _position_is_enought_place(cls, context, position):
62 72
         count_obj_here = len(context.metas.list.get(POSITIONS, position, allow_empty=True))
63 73
         if count_obj_here <= Core.get_configuration_manager().get('ant.put.max_objects_at_same_position', 5):
64 74
             return True
65 75
         return False
66 76
 
77
+    @classmethod
78
+    def _position_have_free_space_around(cls, context, position):
79
+        # TODO: On regarde ces cases qui ne sont pas forcement visible par l'individu. On presupose ici qu'elle peut les
80
+        # voir. Pour etre au top il faudrait une logie propre a l'individu qui definis ce qu'il voie.
81
+        around_positions = context.get_around_points_of_point(position)
82
+        for around_position in around_positions:
83
+            if not context.position_is_penetrable(around_position):
84
+                return False
85
+        return True
86
+
67 87
     def done(self, puted_object):
68 88
         # TODO: lancer le choix d'un nouveau mode dans le brain.
69 89
         if isinstance(puted_object, Food):