switch set, automatize more of the content without UI change
This commit is contained in:
8
Assets/Set/Data.meta
Normal file
8
Assets/Set/Data.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02eade1755b3bee4ba788d4232fa4dd8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
73
Assets/Set/Data/ChampionUtils.cs
Normal file
73
Assets/Set/Data/ChampionUtils.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Set.Data
|
||||
{
|
||||
public class ChampionUtils
|
||||
{
|
||||
public static HashSet<ChampionsEnum> FromLong(long champions)
|
||||
{
|
||||
HashSet<ChampionsEnum> result = new HashSet<ChampionsEnum>();
|
||||
foreach (ChampionsEnum champion in System.Enum.GetValues(typeof(ChampionsEnum)))
|
||||
{
|
||||
if ((champions & (long)champion) != 0)
|
||||
{
|
||||
result.Add(champion);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long ToLong(HashSet<ChampionsEnum> champions)
|
||||
{
|
||||
long result = 0;
|
||||
foreach (ChampionsEnum champion in champions)
|
||||
{
|
||||
result |= (long)champion;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static long ToLong(ChampionsEnum champions)
|
||||
{
|
||||
return (long)champions;
|
||||
}
|
||||
public static bool ContainsChampion(long champions, ChampionsEnum champion)
|
||||
{
|
||||
return (champions & (long)champion) != 0;
|
||||
}
|
||||
|
||||
|
||||
public static bool ContainsChampion(long champions, long champion)
|
||||
{
|
||||
return (champions & champion) != 0;
|
||||
}
|
||||
|
||||
public static int NumberOfChampions(long champions)
|
||||
{
|
||||
return BitWise.HammingWeight(champions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 0 to n-1
|
||||
/// </summary>
|
||||
/// <param name="champions"></param>
|
||||
/// <param name="n"></param>
|
||||
/// <returns></returns>
|
||||
public static long GetNthChampion(long champions, int n)
|
||||
{
|
||||
int kThFoundChampion = 0;
|
||||
for (int i = 0; i < 64; i++)
|
||||
{
|
||||
if ((champions & (1L << i)) != 0)
|
||||
{
|
||||
if (kThFoundChampion == n)
|
||||
{
|
||||
return 1L << i;
|
||||
}
|
||||
kThFoundChampion++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Assets/Set/Data/ChampionUtils.cs.meta
Normal file
7
Assets/Set/Data/ChampionUtils.cs.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae22ada17bccee84b817a24470d45e6a
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
81
Assets/Set/Data/ChampionsEnum.cs
Normal file
81
Assets/Set/Data/ChampionsEnum.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
|
||||
namespace Set.Data
|
||||
{
|
||||
[Flags]
|
||||
public enum ChampionsEnum : long
|
||||
{
|
||||
// Cost 1 Champions
|
||||
AATROX = 1L << 0,
|
||||
EZREAL = 1L << 1,
|
||||
GAREN = 1L << 2,
|
||||
GNAR = 1L << 3,
|
||||
KALISTA = 1L << 4,
|
||||
KAYLE = 1L << 5,
|
||||
KENNEN = 1L << 6,
|
||||
LUCIAN = 1L << 7,
|
||||
MALPHITE = 1L << 8,
|
||||
NAAFIRI = 1L << 9,
|
||||
RELL = 1L << 10,
|
||||
SIVIR = 1L << 11,
|
||||
SYNDRA = 1L << 12,
|
||||
ZAC = 1L << 13,
|
||||
|
||||
// Cost 2 Champions
|
||||
DRMUNDO = 1L << 14,
|
||||
GANGPLANK = 1L << 15,
|
||||
JANNA = 1L << 16,
|
||||
JHIN = 1L << 17,
|
||||
KAISA = 1L << 18,
|
||||
KATARINA = 1L << 19,
|
||||
KOBUKO = 1L << 20,
|
||||
LUX = 1L << 21,
|
||||
RAKAN = 1L << 22,
|
||||
SHEN = 1L << 23,
|
||||
VI = 1L << 24,
|
||||
XAYAH = 1L << 25,
|
||||
XINZHAO = 1L << 26,
|
||||
|
||||
// Cost 3 Champions
|
||||
AHRI = 1L << 27,
|
||||
CAITLYN = 1L << 28,
|
||||
DARIUS = 1L << 29,
|
||||
JAYCE = 1L << 30,
|
||||
KOGMAW = 1L << 31,
|
||||
LULU = 1L << 32,
|
||||
MALZAHAR = 1L << 33,
|
||||
NEEKO = 1L << 34,
|
||||
RAMMUS = 1L << 35,
|
||||
SENNA = 1L << 36,
|
||||
SMOLDER = 1L << 37,
|
||||
SWAIN = 1L << 38,
|
||||
UDYR = 1L << 39,
|
||||
VIEGO = 1L << 40,
|
||||
YASUO = 1L << 41,
|
||||
ZIGGS = 1L << 42,
|
||||
|
||||
// Cost 4 Champions
|
||||
AKALI = 1L << 43,
|
||||
ASHE = 1L << 44,
|
||||
JARVANIV = 1L << 45,
|
||||
JINX = 1L << 46,
|
||||
KARMA = 1L << 47,
|
||||
KSANTE = 1L << 48,
|
||||
LEONA = 1L << 49,
|
||||
POPPY = 1L << 50,
|
||||
RYZE = 1L << 51,
|
||||
SAMIRA = 1L << 52,
|
||||
SETT = 1L << 53,
|
||||
VOLIBEAR = 1L << 54,
|
||||
YUUMI = 1L << 55,
|
||||
|
||||
// Cost 5 Champions
|
||||
BRAUM = 1L << 56,
|
||||
EKKO = 1L << 57,
|
||||
GWEN = 1L << 58,
|
||||
LEESIN = 1L << 59,
|
||||
SERAPHINE = 1L << 60,
|
||||
TWISTEDFATE = 1L << 61,
|
||||
VARUS = 1L << 62,
|
||||
}
|
||||
}
|
||||
2
Assets/Set/Data/ChampionsEnum.cs.meta
Normal file
2
Assets/Set/Data/ChampionsEnum.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a75df9c17190edf428ce88624342f5c9
|
||||
109
Assets/Set/Data/TraitSelectorManager.cs
Normal file
109
Assets/Set/Data/TraitSelectorManager.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UI;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Set.Data
|
||||
{
|
||||
public class TraitSelectorManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TMP_InputField _compositionSize;
|
||||
|
||||
[SerializeField]
|
||||
private ChampionSelector _mandatorychampionSelector;
|
||||
|
||||
[SerializeField]
|
||||
private ChampionSelector _acceptablechampionSelector;
|
||||
|
||||
[SerializeField]
|
||||
private EmblemSelector _emblemSelector;
|
||||
|
||||
[SerializeField]
|
||||
private int _traitThreshold = 7;
|
||||
|
||||
[SerializeField]
|
||||
public int _compositionPerFrame = 100;
|
||||
|
||||
public void ListAllActivableCompo()
|
||||
{
|
||||
var emblemList = _emblemSelector.GetEmblems();
|
||||
var mandatoryChampions = ChampionUtils.ToLong(
|
||||
_mandatorychampionSelector.GetSelectedChampions()
|
||||
);
|
||||
var acceptableChampions = ChampionUtils.ToLong(
|
||||
_acceptablechampionSelector.GetSelectedChampions()
|
||||
);
|
||||
int compositionSize =
|
||||
_compositionSize.text == "" ? 1 : int.Parse(_compositionSize.text);
|
||||
|
||||
Coroutine coroutine = StartCoroutine(
|
||||
ComputeCompositionAsync(
|
||||
mandatoryChampions,
|
||||
acceptableChampions,
|
||||
compositionSize,
|
||||
emblemList
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public IEnumerator<float> ComputeCompositionAsync(
|
||||
long mandatoryChampions,
|
||||
long acceptableChampions,
|
||||
int compositionSize,
|
||||
Dictionary<int, int> emblemList
|
||||
)
|
||||
{
|
||||
var compositions = TraitsMapping.GenerateCombinations(
|
||||
mandatoryChampions,
|
||||
acceptableChampions,
|
||||
compositionSize
|
||||
);
|
||||
Debug.Log($"{compositions.Count} Compositions generated.");
|
||||
yield return 0f;
|
||||
int compHandled = 0;
|
||||
int totalCompHandled = 0;
|
||||
int totalSucessfulCompFound = 0;
|
||||
foreach (var composition in compositions)
|
||||
{
|
||||
int activeSynergies = GetActiveSynergy(composition, emblemList);
|
||||
compHandled++;
|
||||
totalCompHandled++;
|
||||
if (TraitUtils.TraitCountFromInt(activeSynergies) >= _traitThreshold)
|
||||
{
|
||||
totalSucessfulCompFound++;
|
||||
HashSet<ChampionsEnum> champions = ChampionUtils.FromLong(composition);
|
||||
var s = TraitsMapping.CompositionToString(champions);
|
||||
Debug.Log(
|
||||
$"{totalSucessfulCompFound}: {s} - {TraitUtils.TraitCountFromInt(activeSynergies)}"
|
||||
);
|
||||
}
|
||||
if (compHandled >= _compositionPerFrame)
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"{totalSucessfulCompFound} : {totalCompHandled} Compositions handled."
|
||||
);
|
||||
compHandled = 0;
|
||||
yield return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("Total successful compositions found: " + totalSucessfulCompFound);
|
||||
}
|
||||
|
||||
private int GetActiveSynergy(long combination, Dictionary<int, int> emblemList)
|
||||
{
|
||||
var synergies = TraitsMapping.TraitCountInCompo(combination);
|
||||
|
||||
var synergiesWithEmblem = TraitsMapping.MergeEmblems(synergies, emblemList);
|
||||
var activeSynergies = TraitsMapping.FilterActiveTraits(synergiesWithEmblem);
|
||||
return activeSynergies;
|
||||
}
|
||||
|
||||
public void StopAll()
|
||||
{
|
||||
StopAllCoroutines();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Set/Data/TraitSelectorManager.cs.meta
Normal file
2
Assets/Set/Data/TraitSelectorManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 73ed0a195abac8049bbd09802659e2a6
|
||||
52
Assets/Set/Data/TraitUtils.cs
Normal file
52
Assets/Set/Data/TraitUtils.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Numerics;
|
||||
|
||||
namespace Set.Data
|
||||
{
|
||||
public class TraitUtils
|
||||
{
|
||||
public static HashSet<TraitsEnum> FromInt(int traits)
|
||||
{
|
||||
HashSet<TraitsEnum> result = new HashSet<TraitsEnum>();
|
||||
foreach (TraitsEnum trait in System.Enum.GetValues(typeof(TraitsEnum)))
|
||||
{
|
||||
if ((traits & (int)trait) != 0)
|
||||
{
|
||||
result.Add(trait);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int ToInt(HashSet<TraitsEnum> traits)
|
||||
{
|
||||
int result = 0;
|
||||
foreach (TraitsEnum trait in traits)
|
||||
{
|
||||
result |= (int)trait;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int TraitCountFromInt(int traits)
|
||||
{
|
||||
int count = 0;
|
||||
while (traits != 0)
|
||||
{
|
||||
count += traits & 1;
|
||||
traits >>= 1;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public static bool ContainsTrait(int traits, TraitsEnum trait)
|
||||
{
|
||||
return (traits & (int)trait) != 0;
|
||||
}
|
||||
public static bool ContainsTrait(int traits, int trait)
|
||||
{
|
||||
return (traits & trait) != 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
2
Assets/Set/Data/TraitUtils.cs.meta
Normal file
2
Assets/Set/Data/TraitUtils.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88f87d6992be1ef4c96d540fad7f6b25
|
||||
34
Assets/Set/Data/TraitsEnum.cs
Normal file
34
Assets/Set/Data/TraitsEnum.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
|
||||
namespace Set.Data
|
||||
{
|
||||
[Flags]
|
||||
public enum TraitsEnum : int
|
||||
{
|
||||
BATTLEACADEMIA = 1 << 0,
|
||||
CRYSTALGAMBIT = 1 << 1,
|
||||
LUCHADOR = 1 << 2,
|
||||
MIGHTYMECH = 1 << 3,
|
||||
MONSTERTRAINER = 1 << 4,
|
||||
SOULFIGHTER = 1 << 5,
|
||||
STARGUARDIAN = 1 << 6,
|
||||
SUPREMECELLS = 1 << 7,
|
||||
THECREW = 1 << 8,
|
||||
WRAITH = 1 << 9,
|
||||
MENTOR = 1 << 10,
|
||||
PRODIGY = 1 << 11,
|
||||
THECHAMP = 1 << 12,
|
||||
STANCEMASTER = 1 << 13,
|
||||
ROGUECAPTAIN = 1 << 14,
|
||||
BASTION = 1 << 15,
|
||||
DUELIST = 1 << 16,
|
||||
EDGELORD = 1 << 17,
|
||||
EXECUTIONER = 1 << 18,
|
||||
HEAVYWEIGHT = 1 << 19,
|
||||
JUGGERNAUT = 1 << 20,
|
||||
PROTECTOR = 1 << 21,
|
||||
SNIPER = 1 << 22,
|
||||
SORCERER = 1 << 23,
|
||||
STRATEGIST = 1 << 24
|
||||
}
|
||||
}
|
||||
2
Assets/Set/Data/TraitsEnum.cs.meta
Normal file
2
Assets/Set/Data/TraitsEnum.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1370abde62662fc488093e0861760ee2
|
||||
1106
Assets/Set/Data/TraitsMapping.cs
Normal file
1106
Assets/Set/Data/TraitsMapping.cs
Normal file
File diff suppressed because it is too large
Load Diff
2
Assets/Set/Data/TraitsMapping.cs.meta
Normal file
2
Assets/Set/Data/TraitsMapping.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e486327ee9799854e84d9924d1e547c1
|
||||
Reference in New Issue
Block a user