def evaluate(self, action, zones, graph): scenario = Scenario_Generator( self.width, self.height, self.immobile_objs, self.mobile_objs, self.manipulatable_obj, self.target_obj, showRender=False, ) game_objects = scenario.getGameObjects() end_position, shape = scenario.evaluate(action) radius = shape.radius end_position = Point(end_position) circular_region_ball = end_position.buffer(radius) occupied_zones = [] for i in xrange(len(zones)): if zones[i].intersects(circular_region_ball): occupied_zones.append(i) if len(occupied_zones) == 0: return len(zones) # set to the maximum length min_d = 9999 for occupied_zone in occupied_zones: length = nx.shortest_path_length(graph, source=occupied_zone, target=self.target_zone) if length < min_d: min_d = length return min_d
def test_old_evaluate(self, action): scenario = Scenario_Generator(self.width, self.height, self.immobile_objs, self.mobile_objs, self.manipulatable_obj, self.target_obj, showRender=False) game_objects = scenario.getGameObjects() graph, zones = triangulate(game_objects, self.width, self.height) end_position, shape = scenario.evaluate(action) end_position = Point(end_position) last_zone = -1 for i in xrange(len(zones)): if zones[i].contains(end_position): last_zone = i break if last_zone == -1: return len(zones) # set to the maximum length score = nx.shortest_path_length(graph, source=i, target=self.target_zone) return score