def _object_features_to_values(features): featurized_objects = phyre.simulation.FeaturizedObjects( phyre.simulation.finalize_featurized_objects( features[None, None, ...], phyre.simulation.PositionShift.FROM_CENTER_OF_MASS)) x = featurized_objects.xs.item() y = featurized_objects.ys.item() angle = featurized_objects.angles.item() v_x = featurized_objects.v_xs.item() v_y = featurized_objects.v_ys.item() v_angle = featurized_objects.v_angles.item() diameter = featurized_objects.diameters.item() x *= constants.SCENE_WIDTH y *= constants.SCENE_HEIGHT angle *= 360. v_x *= constants.SCENE_WIDTH v_y *= constants.SCENE_HEIGHT v_angle *= 360. diameter *= constants.SCENE_WIDTH shape_type = featurized_objects.shapes[0].lower() color = featurized_objects.colors[0].lower() dynamic = constants.color_to_id(color) in constants.DYNAMIC_COLOR_IDS user_input = featurized_objects.num_user_inputs == 1 return dict(x=x, y=y, angle=angle, v_x=v_x, v_y=v_y, v_angle=v_angle, diameter=diameter, dynamic=dynamic, user_input=user_input, color=color, shape_type=shape_type)
def set_color(self, color): color_id = constants.color_to_id(color) if self.dynamic: assert color_id in constants.DYNAMIC_COLOR_IDS, ( f'Color {color} is not allowed for dynamic bodies.') else: assert color_id in constants.STATIC_COLOR_IDS, ( f'Color {color} is not allowed for static bodies.') self.color = color self._thrift_body.color = color_id return self