AppsusUK / NFT-Art-Generator

Easy to use NFT art generator app for windows/linux/mac
MIT License
434 stars 165 forks source link

Innaccurate Max Combinations #4

Closed AbdulDridi closed 2 years ago

AbdulDridi commented 3 years ago

https://github.com/AppsusUK/NFT-Art-Generator/blob/f786d9db53cc9fe35901b6dd9ad6ba79e38c431f/src/app/home/home.component.ts#L240-L250

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);
  } 
AbdulDridi commented 2 years ago

Closed in b0ed7a33a3ba1fd5cc64edebd431d9f881ae4b88