Browse Source

Put object only if free space around

Bastien Sevajol 8 years ago
parent
commit
d86c315af5

+ 22 - 2
intelligine/simulation/object/brain/part/transport/AntPutBrainPart.py View File

54
                     return pos_around_target
54
                     return pos_around_target
55
         raise CantFindWhereToPut()
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
         if not context.position_is_penetrable(position):
59
         if not context.position_is_penetrable(position):
60
             return False
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
         count_obj_here = len(context.metas.list.get(POSITIONS, position, allow_empty=True))
72
         count_obj_here = len(context.metas.list.get(POSITIONS, position, allow_empty=True))
63
         if count_obj_here <= Core.get_configuration_manager().get('ant.put.max_objects_at_same_position', 5):
73
         if count_obj_here <= Core.get_configuration_manager().get('ant.put.max_objects_at_same_position', 5):
64
             return True
74
             return True
65
         return False
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
     def done(self, puted_object):
87
     def done(self, puted_object):
68
         # TODO: lancer le choix d'un nouveau mode dans le brain.
88
         # TODO: lancer le choix d'un nouveau mode dans le brain.
69
         if isinstance(puted_object, Food):
89
         if isinstance(puted_object, Food):