using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using NUnit.Framework; using UnityEngine; namespace Assets.Data { public class TraitsMapping : MonoBehaviour { // long for champion, int for traits public static Dictionary ChampsTraits = new Dictionary { { (long)ChampionsEnum.ASHE, TraitUtils.ToInt( new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.MULTISTRIKER } ) }, { (long)ChampionsEnum.BLITZCRANK, TraitUtils.ToInt( new HashSet { TraitsEnum.HONEYMANCY, TraitsEnum.VANGUARD } ) }, { (long)ChampionsEnum.ELISE, TraitUtils.ToInt( new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.SHAPESHIFTER } ) }, { (long)ChampionsEnum.JAX, TraitUtils.ToInt( new HashSet { TraitsEnum.CHRONO, TraitsEnum.MULTISTRIKER } ) }, { (long)ChampionsEnum.JAYCE, TraitUtils.ToInt( new HashSet { TraitsEnum.PORTAL, TraitsEnum.SHAPESHIFTER } ) }, { (long)ChampionsEnum.LILLIA, TraitUtils.ToInt(new HashSet { TraitsEnum.FAERIE, TraitsEnum.BASTION }) }, { (long)ChampionsEnum.NOMSY, TraitUtils.ToInt(new HashSet { TraitsEnum.DRAGON, TraitsEnum.HUNTER }) }, { (long)ChampionsEnum.POPPY, TraitUtils.ToInt( new HashSet { TraitsEnum.WITCHCRAFT, TraitsEnum.BASTION } ) }, { (long)ChampionsEnum.SERAPHINE, TraitUtils.ToInt(new HashSet { TraitsEnum.FAERIE, TraitsEnum.MAGE }) }, { (long)ChampionsEnum.SORAKA, TraitUtils.ToInt(new HashSet { TraitsEnum.SUGARCRAFT, TraitsEnum.MAGE }) }, { (long)ChampionsEnum.TWITCH, TraitUtils.ToInt(new HashSet { TraitsEnum.FROST, TraitsEnum.HUNTER }) }, { (long)ChampionsEnum.WARWICK, TraitUtils.ToInt(new HashSet { TraitsEnum.FROST, TraitsEnum.VANGUARD }) }, { (long)ChampionsEnum.ZIGGS, TraitUtils.ToInt( new HashSet { TraitsEnum.HONEYMANCY, TraitsEnum.INCANTATOR } ) }, { (long)ChampionsEnum.ZOE, TraitUtils.ToInt( new HashSet { TraitsEnum.WITCHCRAFT, TraitsEnum.SCHOLAR, TraitsEnum.PORTAL, } ) }, { (long)ChampionsEnum.AHRI, TraitUtils.ToInt(new HashSet { TraitsEnum.ARCANA, TraitsEnum.SCHOLAR }) }, { (long)ChampionsEnum.AKALI, TraitUtils.ToInt( new HashSet { TraitsEnum.PYRO, TraitsEnum.MULTISTRIKER, TraitsEnum.WARRIOR, } ) }, { (long)ChampionsEnum.CASSIOPEIA, TraitUtils.ToInt( new HashSet { TraitsEnum.WITCHCRAFT, TraitsEnum.INCANTATOR } ) }, { (long)ChampionsEnum.GALIO, TraitUtils.ToInt( new HashSet { TraitsEnum.PORTAL, TraitsEnum.VANGUARD, TraitsEnum.MAGE, } ) }, { (long)ChampionsEnum.KASSADIN, TraitUtils.ToInt( new HashSet { TraitsEnum.PORTAL, TraitsEnum.MULTISTRIKER } ) }, { (long)ChampionsEnum.KOGMAW, TraitUtils.ToInt( new HashSet { TraitsEnum.HONEYMANCY, TraitsEnum.HUNTER } ) }, { (long)ChampionsEnum.NILAH, TraitUtils.ToInt( new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.WARRIOR } ) }, { (long)ChampionsEnum.NUNU, TraitUtils.ToInt( new HashSet { TraitsEnum.HONEYMANCY, TraitsEnum.BASTION } ) }, { (long)ChampionsEnum.RUMBLE, TraitUtils.ToInt( new HashSet { TraitsEnum.SUGARCRAFT, TraitsEnum.BLASTER, TraitsEnum.VANGUARD, } ) }, { (long)ChampionsEnum.SHYVANA, TraitUtils.ToInt( new HashSet { TraitsEnum.DRAGON, TraitsEnum.SHAPESHIFTER } ) }, { (long)ChampionsEnum.SYNDRA, TraitUtils.ToInt( new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.INCANTATOR } ) }, { (long)ChampionsEnum.TRISTANA, TraitUtils.ToInt(new HashSet { TraitsEnum.FAERIE, TraitsEnum.BLASTER }) }, { (long)ChampionsEnum.ZILEAN, TraitUtils.ToInt( new HashSet { TraitsEnum.FROST, TraitsEnum.CHRONO, TraitsEnum.PRESERVER, } ) }, { (long)ChampionsEnum.BARD, TraitUtils.ToInt( new HashSet { TraitsEnum.SUGARCRAFT, TraitsEnum.SCHOLAR, TraitsEnum.PRESERVER, } ) }, { (long)ChampionsEnum.EZREAL, TraitUtils.ToInt(new HashSet { TraitsEnum.PORTAL, TraitsEnum.BLASTER }) }, { (long)ChampionsEnum.HECARIM, TraitUtils.ToInt( new HashSet { TraitsEnum.ARCANA, TraitsEnum.MULTISTRIKER, TraitsEnum.BASTION, } ) }, { (long)ChampionsEnum.HWEI, TraitUtils.ToInt(new HashSet { TraitsEnum.FROST, TraitsEnum.BLASTER }) }, { (long)ChampionsEnum.JINX, TraitUtils.ToInt( new HashSet { TraitsEnum.SUGARCRAFT, TraitsEnum.HUNTER } ) }, { (long)ChampionsEnum.KATARINA, TraitUtils.ToInt(new HashSet { TraitsEnum.FAERIE, TraitsEnum.WARRIOR }) }, { (long)ChampionsEnum.MORDEKAISER, TraitUtils.ToInt( new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.VANGUARD } ) }, { (long)ChampionsEnum.NEEKO, TraitUtils.ToInt( new HashSet { TraitsEnum.WITCHCRAFT, TraitsEnum.SHAPESHIFTER } ) }, { (long)ChampionsEnum.SHEN, TraitUtils.ToInt(new HashSet { TraitsEnum.PYRO, TraitsEnum.BASTION }) }, { (long)ChampionsEnum.SWAIN, TraitUtils.ToInt( new HashSet { TraitsEnum.FROST, TraitsEnum.SHAPESHIFTER } ) }, { (long)ChampionsEnum.VEIGAR, TraitUtils.ToInt(new HashSet { TraitsEnum.HONEYMANCY, TraitsEnum.MAGE }) }, { (long)ChampionsEnum.VEX, TraitUtils.ToInt(new HashSet { TraitsEnum.CHRONO, TraitsEnum.MAGE }) }, { (long)ChampionsEnum.WUKONG, TraitUtils.ToInt(new HashSet { TraitsEnum.DRUID }) }, { (long)ChampionsEnum.FIORA, TraitUtils.ToInt( new HashSet { TraitsEnum.WITCHCRAFT, TraitsEnum.WARRIOR } ) }, { (long)ChampionsEnum.GWEN, TraitUtils.ToInt( new HashSet { TraitsEnum.SUGARCRAFT, TraitsEnum.WARRIOR } ) }, { (long)ChampionsEnum.KALISTA, TraitUtils.ToInt( new HashSet { TraitsEnum.FAERIE, TraitsEnum.MULTISTRIKER } ) }, { (long)ChampionsEnum.KARMA, TraitUtils.ToInt( new HashSet { TraitsEnum.INCANTATOR, TraitsEnum.CHRONO } ) }, { (long)ChampionsEnum.NAMI, TraitUtils.ToInt(new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.MAGE }) }, { (long)ChampionsEnum.NASUS, TraitUtils.ToInt( new HashSet { TraitsEnum.SHAPESHIFTER, TraitsEnum.PYRO } ) }, { (long)ChampionsEnum.OLAF, TraitUtils.ToInt(new HashSet { TraitsEnum.FROST, TraitsEnum.HUNTER }) }, { (long)ChampionsEnum.RAKAN, TraitUtils.ToInt( new HashSet { TraitsEnum.FAERIE, TraitsEnum.PRESERVER } ) }, { (long)ChampionsEnum.RYZE, TraitUtils.ToInt(new HashSet { TraitsEnum.PORTAL, TraitsEnum.SCHOLAR }) }, { (long)ChampionsEnum.TAHMKENCH, TraitUtils.ToInt(new HashSet { TraitsEnum.ARCANA, TraitsEnum.VANGUARD }) }, { (long)ChampionsEnum.TARIC, TraitUtils.ToInt(new HashSet { TraitsEnum.PORTAL, TraitsEnum.BASTION }) }, { (long)ChampionsEnum.VARUS, TraitUtils.ToInt(new HashSet { TraitsEnum.PYRO, TraitsEnum.BLASTER }) }, { (long)ChampionsEnum.BRIAR, TraitUtils.ToInt( new HashSet { TraitsEnum.ELDRICHT, TraitsEnum.SHAPESHIFTER } ) }, { (long)ChampionsEnum.CAMILLE, TraitUtils.ToInt( new HashSet { TraitsEnum.CHRONO, TraitsEnum.MULTISTRIKER } ) }, { (long)ChampionsEnum.DIANA, TraitUtils.ToInt(new HashSet { TraitsEnum.FROST, TraitsEnum.BASTION }) }, { (long)ChampionsEnum.MILLIO, TraitUtils.ToInt(new HashSet { TraitsEnum.FAERIE, TraitsEnum.SCHOLAR }) }, { (long)ChampionsEnum.MORGANA, TraitUtils.ToInt( new HashSet { TraitsEnum.WITCHCRAFT, TraitsEnum.PRESERVER } ) }, { (long)ChampionsEnum.NORRA, TraitUtils.ToInt(new HashSet { TraitsEnum.PORTAL, TraitsEnum.MAGE }) }, { (long)ChampionsEnum.SMOLDER, TraitUtils.ToInt(new HashSet { TraitsEnum.DRAGON, TraitsEnum.BLASTER }) }, { (long)ChampionsEnum.XERATH, TraitUtils.ToInt(new HashSet { TraitsEnum.ARCANA }) }, }; // int for trait and long for list of champions public static Dictionary TraitsChamp = new Dictionary { { (int)TraitsEnum.ARCANA, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.AHRI, ChampionsEnum.HECARIM, ChampionsEnum.TAHMKENCH, ChampionsEnum.XERATH, } ) }, { (int)TraitsEnum.CHRONO, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.CAMILLE, ChampionsEnum.JAX, ChampionsEnum.KARMA, ChampionsEnum.VEX, ChampionsEnum.ZILEAN, } ) }, { (int)TraitsEnum.DRAGON, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.SMOLDER, ChampionsEnum.SHYVANA, ChampionsEnum.NOMSY, } ) }, { (int)TraitsEnum.DRUID, ChampionUtils.ToLong(new HashSet() { ChampionsEnum.WUKONG }) }, { (int)TraitsEnum.ELDRICHT, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.ASHE, ChampionsEnum.BRIAR, ChampionsEnum.ELISE, ChampionsEnum.MORDEKAISER, ChampionsEnum.NAMI, ChampionsEnum.NILAH, ChampionsEnum.SYNDRA, } ) }, { (int)TraitsEnum.FAERIE, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.KALISTA, ChampionsEnum.KATARINA, ChampionsEnum.LILLIA, ChampionsEnum.MILLIO, ChampionsEnum.RAKAN, ChampionsEnum.SERAPHINE, ChampionsEnum.TRISTANA, } ) }, { (int)TraitsEnum.FROST, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.DIANA, ChampionsEnum.HWEI, ChampionsEnum.OLAF, ChampionsEnum.SWAIN, ChampionsEnum.TWITCH, ChampionsEnum.WARWICK, ChampionsEnum.ZILEAN, } ) }, { (int)TraitsEnum.HONEYMANCY, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.BLITZCRANK, ChampionsEnum.KOGMAW, ChampionsEnum.NUNU, ChampionsEnum.VEIGAR, ChampionsEnum.ZIGGS, } ) }, { (int)TraitsEnum.PORTAL, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.EZREAL, ChampionsEnum.GALIO, ChampionsEnum.JAYCE, ChampionsEnum.KASSADIN, ChampionsEnum.NORRA, ChampionsEnum.RYZE, ChampionsEnum.TARIC, ChampionsEnum.ZOE, } ) }, { (int)TraitsEnum.PYRO, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.AKALI, ChampionsEnum.NASUS, ChampionsEnum.SHEN, ChampionsEnum.VARUS, } ) }, { (int)TraitsEnum.SUGARCRAFT, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.BARD, ChampionsEnum.GWEN, ChampionsEnum.JINX, ChampionsEnum.RUMBLE, ChampionsEnum.SORAKA, } ) }, { (int)TraitsEnum.WITCHCRAFT, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.CASSIOPEIA, ChampionsEnum.FIORA, ChampionsEnum.MORGANA, ChampionsEnum.NEEKO, ChampionsEnum.POPPY, ChampionsEnum.ZOE, } ) }, { (int)TraitsEnum.BASTION, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.DIANA, ChampionsEnum.HECARIM, ChampionsEnum.LILLIA, ChampionsEnum.NUNU, ChampionsEnum.POPPY, ChampionsEnum.SHEN, ChampionsEnum.TARIC, } ) }, { (int)TraitsEnum.BLASTER, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.EZREAL, ChampionsEnum.HWEI, ChampionsEnum.RUMBLE, ChampionsEnum.SMOLDER, ChampionsEnum.TRISTANA, ChampionsEnum.VARUS, } ) }, { (int)TraitsEnum.HUNTER, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.JINX, ChampionsEnum.KOGMAW, ChampionsEnum.NOMSY, ChampionsEnum.OLAF, ChampionsEnum.TWITCH, } ) }, { (int)TraitsEnum.INCANTATOR, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.CASSIOPEIA, ChampionsEnum.KARMA, ChampionsEnum.SYNDRA, ChampionsEnum.ZIGGS, } ) }, { (int)TraitsEnum.MAGE, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.GALIO, ChampionsEnum.NAMI, ChampionsEnum.NORRA, ChampionsEnum.SERAPHINE, ChampionsEnum.SORAKA, ChampionsEnum.VEIGAR, ChampionsEnum.VEX, } ) }, { (int)TraitsEnum.MULTISTRIKER, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.AKALI, ChampionsEnum.ASHE, ChampionsEnum.CAMILLE, ChampionsEnum.HECARIM, ChampionsEnum.JAX, ChampionsEnum.KALISTA, ChampionsEnum.KASSADIN, } ) }, { (int)TraitsEnum.PRESERVER, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.BARD, ChampionsEnum.MORGANA, ChampionsEnum.RAKAN, ChampionsEnum.ZILEAN, } ) }, { (int)TraitsEnum.SCHOLAR, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.AHRI, ChampionsEnum.BARD, ChampionsEnum.MILLIO, ChampionsEnum.RYZE, ChampionsEnum.ZOE, } ) }, { (int)TraitsEnum.SHAPESHIFTER, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.BRIAR, ChampionsEnum.ELISE, ChampionsEnum.JAYCE, ChampionsEnum.NASUS, ChampionsEnum.NEEKO, ChampionsEnum.SHYVANA, ChampionsEnum.SWAIN, } ) }, { (int)TraitsEnum.VANGUARD, ChampionUtils.ToLong( new HashSet() { ChampionsEnum.BLITZCRANK, ChampionsEnum.GALIO, ChampionsEnum.MORDEKAISER, ChampionsEnum.RUMBLE, ChampionsEnum.TAHMKENCH, ChampionsEnum.WARWICK, } ) }, { (int)TraitsEnum.WARRIOR, ChampionUtils.ToLong( new HashSet { ChampionsEnum.AKALI, ChampionsEnum.FIORA, ChampionsEnum.GWEN, ChampionsEnum.KATARINA, ChampionsEnum.NILAH, } ) }, }; public Dictionary ChampionCost = new Dictionary() { { (long)ChampionsEnum.ASHE, 1 }, { (long)ChampionsEnum.BLITZCRANK, 1 }, { (long)ChampionsEnum.ELISE, 1 }, { (long)ChampionsEnum.JAX, 1 }, { (long)ChampionsEnum.JAYCE, 1 }, { (long)ChampionsEnum.LILLIA, 1 }, { (long)ChampionsEnum.NOMSY, 1 }, { (long)ChampionsEnum.POPPY, 1 }, { (long)ChampionsEnum.SERAPHINE, 1 }, { (long)ChampionsEnum.SORAKA, 1 }, { (long)ChampionsEnum.TWITCH, 1 }, { (long)ChampionsEnum.WARWICK, 1 }, { (long)ChampionsEnum.ZIGGS, 1 }, { (long)ChampionsEnum.ZOE, 1 }, { (long)ChampionsEnum.AHRI, 2 }, { (long)ChampionsEnum.AKALI, 2 }, { (long)ChampionsEnum.CASSIOPEIA, 2 }, { (long)ChampionsEnum.GALIO, 2 }, { (long)ChampionsEnum.KASSADIN, 2 }, { (long)ChampionsEnum.KOGMAW, 2 }, { (long)ChampionsEnum.NILAH, 2 }, { (long)ChampionsEnum.NUNU, 2 }, { (long)ChampionsEnum.RUMBLE, 2 }, { (long)ChampionsEnum.SHYVANA, 2 }, { (long)ChampionsEnum.SYNDRA, 2 }, { (long)ChampionsEnum.TRISTANA, 2 }, { (long)ChampionsEnum.ZILEAN, 2 }, { (long)ChampionsEnum.BARD, 3 }, { (long)ChampionsEnum.EZREAL, 3 }, { (long)ChampionsEnum.HECARIM, 3 }, { (long)ChampionsEnum.HWEI, 3 }, { (long)ChampionsEnum.JINX, 3 }, { (long)ChampionsEnum.KATARINA, 3 }, { (long)ChampionsEnum.MORDEKAISER, 3 }, { (long)ChampionsEnum.NEEKO, 3 }, { (long)ChampionsEnum.SHEN, 3 }, { (long)ChampionsEnum.SWAIN, 3 }, { (long)ChampionsEnum.VEIGAR, 3 }, { (long)ChampionsEnum.VEX, 3 }, { (long)ChampionsEnum.WUKONG, 3 }, { (long)ChampionsEnum.FIORA, 4 }, { (long)ChampionsEnum.GWEN, 4 }, { (long)ChampionsEnum.KALISTA, 4 }, { (long)ChampionsEnum.KARMA, 4 }, { (long)ChampionsEnum.NAMI, 4 }, { (long)ChampionsEnum.NASUS, 4 }, { (long)ChampionsEnum.OLAF, 4 }, { (long)ChampionsEnum.RAKAN, 4 }, { (long)ChampionsEnum.RYZE, 4 }, { (long)ChampionsEnum.TAHMKENCH, 4 }, { (long)ChampionsEnum.TARIC, 4 }, { (long)ChampionsEnum.VARUS, 4 }, { (long)ChampionsEnum.BRIAR, 5 }, { (long)ChampionsEnum.CAMILLE, 5 }, { (long)ChampionsEnum.DIANA, 5 }, { (long)ChampionsEnum.MILLIO, 5 }, { (long)ChampionsEnum.MORGANA, 5 }, { (long)ChampionsEnum.NORRA, 5 }, { (long)ChampionsEnum.SMOLDER, 5 }, { (long)ChampionsEnum.XERATH, 5 }, }; public static Dictionary> TraitsSteps = new Dictionary> { { (int)TraitsEnum.ARCANA, new List { 2, 3, 4, 5 } }, { (int)TraitsEnum.CHRONO, new List { 2, 4, 6 } }, { (int)TraitsEnum.DRAGON, new List { 2, 3 } }, { (int)TraitsEnum.DRUID, new List { 1 } }, { (int)TraitsEnum.ELDRICHT, new List { 3, 5, 7, 10 } }, { (int)TraitsEnum.FAERIE, new List { 3, 5, 7, 9 } }, { (int)TraitsEnum.FROST, new List { 3, 5, 7, 9 } }, { (int)TraitsEnum.HONEYMANCY, new List { 3, 5, 7 } }, { (int)TraitsEnum.PORTAL, new List { 3, 6, 8, 10 } }, { (int)TraitsEnum.PYRO, new List { 2, 3, 4, 5 } }, { (int)TraitsEnum.SUGARCRAFT, new List { 2, 4, 6 } }, { (int)TraitsEnum.WITCHCRAFT, new List { 2, 4, 6, 8 } }, { (int)TraitsEnum.BASTION, new List { 2, 4, 6, 8 } }, { (int)TraitsEnum.BLASTER, new List { 2, 4, 6 } }, { (int)TraitsEnum.HUNTER, new List { 2, 4, 6 } }, { (int)TraitsEnum.INCANTATOR, new List { 2, 4 } }, { (int)TraitsEnum.MAGE, new List { 3, 5, 7, 10 } }, { (int)TraitsEnum.MULTISTRIKER, new List { 3, 5, 7, 9 } }, { (int)TraitsEnum.PRESERVER, new List { 2, 3, 4, 5 } }, { (int)TraitsEnum.SCHOLAR, new List { 2, 4, 6 } }, { (int)TraitsEnum.SHAPESHIFTER, new List { 2, 4, 6, 8 } }, { (int)TraitsEnum.VANGUARD, new List { 2, 4, 6 } }, { (int)TraitsEnum.WARRIOR, new List { 2, 4, 6 } }, }; public static Dictionary minimalActivation = TraitsSteps.ToDictionary( kvp => kvp.Key, kvp => kvp.Value[0] ); public bool TraitEnabled(int trait, int traitChampCount) { return traitChampCount >= minimalActivation[trait]; } /// /// first int is the trait, second int is the number of champions with this trait /// /// /// public static Dictionary TraitCountInCompo(long compo) { Dictionary synergies = new Dictionary(); for (int i = 0; i < 64; i++) { if ((compo & (1L << i)) != 0) { var champ = (long)i; var traits = ChampsTraits[champ]; // combine the traits within synergies using bitwise operation for (int trait = 0; trait < 22; trait++) { if ((traits & (1 << trait)) != 0) { if (synergies.ContainsKey(trait)) { synergies[trait]++; } else { synergies.Add(trait, 1); } } } } } return synergies; } /// /// first int is trait, second int is the number of champions with this trait /// output is int of the flag of active traits /// /// /// public static int FilterActiveTraits(Dictionary synergies) { int output = 0; foreach (var kvp in synergies) { if (kvp.Value >= minimalActivation[kvp.Key]) { output |= kvp.Key; } } return output; } /// /// trait is the trait, count is the number of champions with this trait /// /// /// /// public static Dictionary MergeEmblems( Dictionary synergies, Dictionary additionalEmblems ) { Dictionary mergedEmblems = new Dictionary(); mergedEmblems = synergies .Concat(additionalEmblems) .GroupBy(x => x.Key) .ToDictionary(x => x.Key, x => x.Sum(y => y.Value)); return mergedEmblems; } void Start() { } public void DisplayTraits(Dictionary traits) { foreach (var kvp in traits) { Debug.Log($"{kvp.Key} : {kvp.Value}"); } } public string DisplayComposition(HashSet compo) { StringBuilder sb = new StringBuilder(); foreach (var champ in compo) { sb.Append(champ.ToString() + " / "); } return sb.ToString(); } // public static IEnumerator GetChampionSubsetsAsync( // long possibleChamp, // long mandatoryChamps, // int size, // Dictionary emblemList, // System.Action onCombinationGenerated // ) // { // List possibleChampList = new List(); // foreach (var champ in ChampsTraits.Keys) // { // if ((possibleChamp & champ) != 0) // { // possibleChampList.Add(champ); // } // } // int n = possibleChampList.Count; // } /// /// Create a list of compositions based on the possible champions, mandatory champions, size of the composition, and the list of emblems. /// each composition much contain all mandatory champs, and can contain any number of possible champs. /// No other champions are allowed in the composition. /// Composition is stored in the shape of a long, where each bit represents a champion. /// /// /// /// /// /// /// // /// // public static List GetCompositionList( // long possibleChamp, // long mandatoryChamps, // int size, // Dictionary emblemList, // System.Action onCombinationGenerated // ) // { // Dictionary allTraits = emblemList; // int alreadySelectionChampCount = mandatoryChamps.CountSetBits(); // } public static List> GetChampionSubsets( HashSet champs, int size ) { List> result = new List>(); if (size == 0) { result.Add(new HashSet()); return result; } List champList = champs.ToList(); // Handle the edge case when size is greater than the number of available champions. if (size > champList.Count) { return result; // No valid subsets if size is too large. } // Use a bit mask approach to generate all subsets of the specified size. int n = champList.Count; int[] indices = new int[size]; for (int i = 0; i < size; i++) indices[i] = i; while (true) { HashSet subset = new HashSet(); foreach (int index in indices) { subset.Add(champList[index]); } result.Add(subset); // Generate the next combination of indices int i; for (i = size - 1; i >= 0; i--) { if (indices[i] != i + n - size) { break; } } if (i < 0) { break; // All combinations have been generated. } indices[i]++; for (int j = i + 1; j < size; j++) { indices[j] = indices[j - 1] + 1; } } return result; } public static List> GetChampionSubsetsRec( HashSet champs, int size ) { List> result = new List>(); if (size == 0) { result.Add(new HashSet()); return result; } if (champs.Count == 0) { return result; } ChampionsEnum first = champs.First(); HashSet rest = new HashSet(champs); rest.Remove(first); List> subResult = GetChampionSubsetsRec(rest, size - 1); foreach (var set in subResult) { set.Add(first); } result.AddRange(subResult); result.AddRange(GetChampionSubsetsRec(rest, size)); return result; } public static int MaxIntForCombinationOfn(int n) { return (1 << n) - 1; } internal static string CompositionToString( HashSet composition ) { StringBuilder sb = new StringBuilder(); foreach (var champ in composition) { sb.Append(champ.ToString() + " / "); } sb.Append(" --------- "); // HashSet activeSynergies = FilterActiveTraits(ChampionUtils.ToLong(composition))); // foreach (var trait in activeSynergies) // { // sb.Append(trait.ToString() + " / "); // } return sb.ToString(); } /// /// I have a list of champion that are fixed, in a long called mandatoryChamps. /// I have a list of champions that are possible, in a long called possibleChamps. /// I want to generate all possible combinations of champions that contain all mandatory champions. /// I can use MaxIntForCombinationOfn to get the maximum number of possible combinations and iterate over all possible combination, /// each bit of the combination will represent the nth champion in the list of possible champions, which is not a list but a long. /// The composition will be composed of all the mandatory champs and some of the possible champs, to add up to the composition size exactly. /// /// /// /// /// public static List GenerateCombinations( long mandatoryChamps, long possibleChamps, int compositionSize ) { Assert.IsTrue((mandatoryChamps & possibleChamps) == 0); List compositions = new List(); int champToSelectCount = compositionSize - ChampionUtils.NumberOfChampions(mandatoryChamps); int possibleChampCount = ChampionUtils.NumberOfChampions(possibleChamps); Assert.IsTrue(champToSelectCount >= 0); // else we have too many mandatory champs HashSet combinations = BitWise.GetAllPermutation(champToSelectCount, possibleChampCount); foreach (var combinationOfPossibleChamps in combinations) { // generating one composition based on the combination. // combination 10010 will add the second and fifth champion of the possibleChamps list to the composition. long composition = mandatoryChamps; int possibleChampIterator = 0; int kThChampFound = 0; while (possibleChampIterator < champToSelectCount) { if ((combinationOfPossibleChamps & (1 << possibleChampIterator)) != 0) { long champ = ChampionUtils.GetNthChampion(possibleChamps,kThChampFound); composition |= champ; kThChampFound++; } possibleChampIterator++; } compositions.Add(composition); } return compositions; } public static IEnumerator DisplayCompositions(List compositions) { Debug.Log("Number of compositions : " + compositions.Count); yield return null; foreach (var compo in compositions) { Debug.Log(CompositionToString(ChampionUtils.FromLong(compo))); yield return null; } } } }