Last active
January 25, 2024 05:18
-
-
Save Hidden50/9bdc239cf69f1afa2b7180314fc4761e to your computer and use it in GitHub Desktop.
Pokemon Quest Recipe Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Recipe Generator | |
*/ | |
(function() { | |
const recipeData = { | |
ingredients: { | |
r: {name: "Tiny Mushroom", quality: 0, properties: ["red", "soft", "mushroom"]}, | |
b: {name: "Bluk Berry", quality: 0, properties: ["blue", "soft", "sweet"]}, | |
y: {name: "Apricorn", quality: 0, properties: ["yellow", "hard", "plant"]}, | |
g: {name: "Fossil", quality: 0, properties: ["gray", "hard", "mineral"]}, | |
R: {name: "Big Root", quality: 1, properties: ["red", "soft", "plant"]}, | |
B: {name: "Icy Rock", quality: 1, properties: ["blue", "hard", "mineral"]}, | |
Y: {name: "Honey", quality: 1, properties: ["yellow", "soft", "sweet"]}, | |
G: {name: "Balm Mushroom", quality: 1, properties: ["gray", "soft", "mushroom"]}, | |
M: {name: "Rainbow Matter", quality: 2, properties: []}, | |
S: {name: "Mystical Shell", quality: 1, properties: ["mythical"]}, | |
}, | |
dishes: [ | |
{shortname: "Red", properties: {red: 4}}, | |
{shortname: "Blue", properties: {blue: 4}}, | |
{shortname: "Yellow", properties: {yellow: 4}}, | |
{shortname: "Gray", properties: {gray: 4}}, | |
{shortname: "Water", properties: {blue: 3, soft: 4}}, | |
{shortname: "Normal", properties: {gray: 2, sweet: 3}}, | |
{shortname: "Poison", properties: {soft: 3, mushroom: 4}}, | |
{shortname: "Ground", properties: {soft: 3, mineral: 2}}, | |
{shortname: "Grass", properties: {soft: 2, plant: 4}}, | |
{shortname: "Bug", properties: {yellow: 3, sweet: 4}}, | |
{shortname: "Psychic", properties: {hard: 2, sweet: 3}}, | |
{shortname: "Rock", properties: {hard: 4, mineral: 2}}, | |
{shortname: "Flying", properties: {mineral: 3, plant: 2}}, | |
{shortname: "Fire", properties: {red: 1, mushroom: 3}}, | |
{shortname: "Electric", properties: {yellow: 3, soft: 4}}, | |
{shortname: "Fighting", properties: {sweet: 3, mushroom: 2}}, | |
{shortname: "Ambrosia", properties: {mythical: 1}}, | |
{shortname: "Mulligan", properties: {}}, | |
], | |
getIngredients (recipe) { | |
return [...recipe].map( letter => this.ingredients[letter] ); | |
}, | |
getSoup (ingredients) { | |
const properties = {red: 0, blue: 0, yellow: 0, gray: 0, soft: 0, hard: 0, mushroom: 0, sweet: 0, plant: 0, mineral: 0, mythical: 0}; | |
let quality = 0; | |
for (const ingredient of ingredients) { | |
quality += ingredient.quality; | |
for (const p of ingredient.properties) { | |
properties[p]++; | |
} | |
} | |
return {quality, ...properties}; | |
}, | |
getDish (soup) { | |
for (const dish of this.dishes) { | |
let isMatch = true; | |
for (const p in dish.properties) { | |
if (soup[p] < dish.properties[p]) { | |
isMatch = false; | |
break; | |
} | |
} | |
if (isMatch) { | |
return dish; | |
} | |
} | |
}, | |
getQualityDescriptor (quality) { | |
if (quality < 1) return "basic"; | |
if (quality < 3) return "good"; | |
if (quality < 5) return "very_good"; | |
return "special"; | |
}, | |
generateRecipes () { | |
const results = {}; | |
for (const dish of this.dishes) { | |
results[dish.shortname] = { | |
basic: [], | |
good: [], | |
very_good: [], | |
special: [], | |
}; | |
} | |
const ingredientList = Object.values(this.ingredients); | |
const ingredientLetters = Object.keys(this.ingredients); | |
const len = ingredientList.length; | |
// loop through all ordered ingredient combinations | |
for (let a = 0; a < len; a++) | |
for (let b = a; b < len; b++) | |
for (let c = b; c < len; c++) | |
for (let d = c; d < len; d++) | |
for (let e = d; e < len; e++) { | |
const ingredients = [a,b,c,d,e].map( i => ingredientList[i] ); | |
const recipe = [a,b,c,d,e].map( i => ingredientLetters[i] ).join(""); | |
const soup = this.getSoup(ingredients); | |
const dish = this.getDish(soup); | |
const dishName = dish.shortname; | |
const qualityDesc = this.getQualityDescriptor(soup.quality); | |
results[dishName][qualityDesc].push(recipe); | |
} | |
return results; | |
}, | |
}; | |
return recipeData.generateRecipes(); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment