def create_recipe(end_product, material_names, quantity_types, tool_types, tool_type_default, ending_tools): """if not tools.has_word_type(end_product, [tools.WORD_TYPE_NOUN]): end_product_nounified = tools.nounify_first_result(end_product, "") if len(end_product_nounified) > 0 and end_product_nounified != end_product and end_product_nounified not in material_names: print("Nounified end product " + end_product + " => " + end_product_nounified) end_product = end_product_nounified """ r = Recipe(end_product, ending_tools) for material_name in random.sample(material_names, min(4, len(material_names))): material_word_type = tools.find_most_common_word_type(material_name) # Unknown and length 12? Probably truncated, let's skip it. if material_word_type == tools.WORD_TYPE_UNKNOWN and len(material_name) == 12: continue if not tools.DEBUG_SKIP_WORD_ANALYSIS and material_word_type != tools.WORD_TYPE_NOUN and not tools.has_word_type(material_name, [tools.WORD_TYPE_NOUN]): material_name_nounified = tools.nounify_first_result(material_name, "") if len(material_name_nounified) > 0 and material_name_nounified != end_product and material_name_nounified not in material_names: print("Nounified material " + material_name + " => " + material_name_nounified) material_name = material_name_nounified material_word_type = tools.find_most_common_word_type(material_name) if material_word_type == tools.WORD_TYPE_ADJECTIVE: material_name = "being " + material_name if material_word_type in quantity_types: quantity_type = random.choice(quantity_types[material_word_type]) amount = quantity_type.random_amount() r.add_material(Material(material_name, amount, quantity_type)) tool_types = tool_types.copy() tool_count = random.randint(2, len(tool_types)) # for tool_type in random.sample(tool_types, min(2, len(tool_types))): while len(r.tools) < tool_count: tool_type = tools.random_weighted_choice(tool_types, lambda t: t.chance_value) tool_types.remove(tool_type) tool = Tool(tool_type) # if not any(tool.equals(other_tool) for other_tool in r.tools): r.add_tool(tool) r.add_tool(Tool(tool_type_default)) r.finish() print("=======================") print() r.print() return r
def __init__(self, end_product, ending_tools): super(Recipe, self).__init__() self.end_product = end_product self.end_product_indefinite_article = tools.get_indefinite_article(self.end_product) + " " if tools.is_uncountable_noun(self.end_product): self.end_product_indefinite_article = "" elif not tools.DEBUG_SKIP_WORD_ANALYSIS and not tools.has_word_type(self.end_product, [tools.WORD_TYPE_NOUN]): word_type = tools.find_most_common_word_type(self.end_product) if word_type == tools.WORD_TYPE_VERB: self.end_product = "something that can " + self.end_product self.end_product_indefinite_article = "" elif word_type == tools.WORD_TYPE_ADJECTIVE: self.end_product = "something " + self.end_product self.end_product_indefinite_article = "" self.ending_tools = ending_tools self.materials = [] self.tools = [] self.instructions = [] self.available_materials = [] self.ending_tool_tools = []