Skip to content

Instantly share code, notes, and snippets.

@quinnkeast
Last active April 6, 2021 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quinnkeast/494d479f824d3e1a467d330fddbf9bb9 to your computer and use it in GitHub Desktop.
Save quinnkeast/494d479f824d3e1a467d330fddbf9bb9 to your computer and use it in GitHub Desktop.
const card = { cost: [{count: 2, type: 'r'}, {count: 2, type: 'any'}, {count: 1, type: 'w/r', hybrid: true}] };
const availableMana = [{count: 4, type: 'r'}, {count: 2, type: 'w'}, {count: 1, type: 'w/r', hybrid: true}];
function hasEnoughMana(cost, availableMana) {
// If it requires more mana than is available in the first place
return cost.reduce((total, obj) => total + obj.count)) > cost.reduce((total, avail) => total + avail.count);
}
function hasRequiredMana(cost, availableMana) {
// Return if the available mana matches the required mana
let possiblePools = [];
let possibleCosts = [];
// 1. Create permutations of the manaPool that could be used to pay if hybrid lands exist.
// e.g. W/R, R, R makes [w: 1, r: 2] and [r: 3], while W/R, W/R, R makes [w: 2, r: 1], [w: 1, r: 2], [r: 3].
// 2. Create permutations of the possibleCosts that could be paid if hybrid mana exists.
// 3. Check for any possible matches between possiblePools and possibleCosts.
}
function cardIsPossible(card) {
return hasEnoughMana(card.cost, availableMana) && hasRequiredMana(card.cost, availableMana);
}
render() {
{cards.map(card => cardIsPossible(card) && <CardComponent />)}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment