AppsusUK / NFT-Art-Generator

Easy to use NFT art generator app for windows/linux/mac

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Innaccurate Max Combinations

AbdulDridi opened this issue · comments

getMaxImageCombinations() {
let itemsInLayers = [];
this.nftDirectory.layers.forEach((layer) => {
let itemsInLayer = 0;
layer.itemRarityFolders.forEach((rarityFolder) => {
itemsInLayer += rarityFolder.items.size;
})
itemsInLayers.push(itemsInLayer);
})
return itemsInLayers.reduce((total, num) => total * num);
}

This function makes 2 bad assumptions:

  1. All layers have a 100% probability of being applied
  2. Rarity Folders have a > 0% probability

This means:

  1. When a layer % is less than 100%, we're artificially limiting the max combination ceiling - since not having the layer/item is also a valid combination
  2. When a rarity folder has a 0% probability, it's not possible to select its images, so the program will be stuck in a loop trying to roll for a combination that doesn't exist (the one in which the item present in that layer exists in the 0% rarity folder)

The code should probably be (to be confirmed with unit tests):

  getMaxImageCombinations() {
    let itemsInLayers = [];
    this.nftDirectory.layers.forEach((layer) => {
      if (layer.rarity > 0) {
        let itemsInLayer = layer.rarity == 1 ? 0 : 1;
        layer.itemRarityFolders.forEach((rarityFolder) => {
          if (rarityFolder.rarity > 0) {
            itemsInLayer += rarityFolder.items.size;
          }
        })
        itemsInLayers.push(itemsInLayer);
      }
    })
    return itemsInLayers.reduce((total, num) => total * num);
  } 
  • testing to confirm