I think your matrix idea is viable. Although I would suggest a bit of improvements to make it easier to work with:
# step 0: define your ingredients in a list
known_ingredients = ["butterfly" , "frog" , "stone"]
# Step 1: reorganize your list; make it visually an actual grid.
grid[0] = ["" , "frog" , "butterfly" , "stone"]
grid[1] = ["frog" , "superfrog" , "froggerfly" , "frog marmelade"]
grid[2] = ["butterfly", "froggerfly" , "super butterfly", "butterfly jam"]
grid[3] = ["stone" , "frog marmelade", "butterfly jam" , "super stone"]
# Step 2: remove noise and some potential errors: sort the list alphabetically and
# remove the duplicates, that will be less maintenance for you:
grid[0] = ["" , "butterfly" , "frog" , "stone"]
grid[1] = ["butterfly", "super butterfly", "froggerfly" , "butterfly jam"]
grid[2] = ["frog" , "" , "superfrog" , "frog marmelade"]
grid[3] = ["stone" , "" , "" , "super stone"]
def mix_ingredients(ingredient_1, ingredient_2):
# the `index` index function assumes the object is there, you might want to
# add a bit of error handling here.
coordinates_ingredient_1 = known_ingredients.index(ingredient_1) + 1
coordinates_ingredient_2 = known_ingredients.index(ingredient_2) + 1
if coordinates_ingredient_1 > coordinates_ingredient_2:
# swap the indices, we sort them in alphabetical order
tmp = coordinates_ingredient_2
coordinates_ingredient_2 = coordinates_ingredient_1
coordinates_ingredient_1 = tmp
return grid[coordinates_ingredient_1][coordinates_ingredient_2]
Now this will work fine if you have a few ingredients, but at some point, you'll likely want to move this to something like a CSV and load it from file at game initialization.