public double RandomWeightCalcualte(LargeCombo large1, LargeCombo large2, int flag) { Random random = new Random(); if (!inited) { wCost = random.NextDouble(); wAOE = random.NextDouble(); wHQ = random.NextDouble(); wRemove = random.NextDouble(); wCostL = random.NextDouble() / 2; wAOEL = random.NextDouble() / 2; wHQL = random.NextDouble() / 2; wRemoveL = random.NextDouble() / 2; wCostH = random.NextDouble() / 2 + 0.5; wAOEH = random.NextDouble() / 2 + 0.5; wHQH = random.NextDouble() / 2 + 0.5; wRemoveH = random.NextDouble() / 2 + 0.5; inited = true; } return(Calculate(large1, large2, flag)); }
public static bool CheckMerge(LargeCombo large1, LargeCombo large2, int flag) { if (large1.ComboCards.Count + large2.ComboCards.Count > 30) { return(false); } if (large1.ComboClass != "NEUTRAL" && large2.ComboClass != "NEUTRAL" && large1.ComboClass != large2.ComboClass) { return(false); } if (HasIllegalDuplicate(large1, large2)) { return(false); } double p = new DynamicVectorCalculator().RandomWeightCalcualte(large1, large2, flag); ////???? if (rand.NextDouble() > p) { Console.WriteLine("ref, p = " + p.ToString()); return(false); } return(true); }
public double RandomWeightCalcualte(LargeCombo large1, LargeCombo large2) { Random random = new Random(); if (!inited) { wCost = random.NextDouble(); wAOE = random.NextDouble(); wHQ = random.NextDouble(); wRemove = random.NextDouble(); Console.WriteLine("Writing......weights"); Console.WriteLine(wCost + ", " + wAOE + ", " + wHQ + ", " + wRemove); using (StreamWriter sw = File.AppendText(@"C:\Users\weizsw\iCloudDrive\Documents\Ai for Games\EvoStone\TestBed\StrategySearch\weight.txt")) { sw.WriteLine("wCost = " + wCost + ", " + "wAoe = " + wAOE + ", " + "wHQ = " + wHQ + ", " + "wRemove = " + wRemove); sw.WriteLine("\n"); sw.Flush(); sw.Close(); } wCostL = random.NextDouble() / 2; wAOEL = random.NextDouble() / 2; wHQL = random.NextDouble() / 2; wRemoveL = random.NextDouble() / 2; wCostH = random.NextDouble() / 2 + 0.5; wAOEH = random.NextDouble() / 2 + 0.5; wHQH = random.NextDouble() / 2 + 0.5; wRemoveH = random.NextDouble() / 2 + 0.5; inited = true; } return(Calculate(large1, large2)); }
public LargeCombo(LargeCombo large1, LargeCombo large2) { ComboClass = "NEUTRAL"; if (large1.ComboClass != "NEUTRAL") { ComboClass = large1.ComboClass; } if (large2.ComboClass != "NEUTRAL") { ComboClass = large2.ComboClass; } Tags = new Dictionary <string, int>(); Tags.Add("AOE", 0); Tags.Add("Remove", 0); Tags.Add("High Quality", 0); foreach (var pair in large1.Tags) { string key = pair.Key; int value = pair.Value; Tags[key] += value; } foreach (var pair in large2.Tags) { string key = pair.Key; int value = pair.Value; Tags[key] += value; } Cost = large1.Cost + large2.Cost; ComboCards = large1.ComboCards.Concat(large2.ComboCards).ToList(); RMScore = (large1.RMScore + large2.RMScore); AOEScore = (large1.AOEScore + large2.AOEScore); HQScore = (large1.HQScore + large2.HQScore); }
public bool HasIllegalDuplicate(LargeCombo large1, LargeCombo large2) { Dictionary <string, int> countOfCard = new Dictionary <string, int>(); foreach (Card card in large1.ComboCards) { string key = card.Name; if (!countOfCard.ContainsKey(key)) { countOfCard.Add(key, 0); } countOfCard[key]++; if (countOfCard[key] > 2) { return(true); } } foreach (Card card in large2.ComboCards) { string key = card.Name; if (!countOfCard.ContainsKey(key)) { countOfCard.Add(key, 0); } countOfCard[key]++; if (countOfCard[key] > 2) { return(true); } } return(false); }
public static void Write(LargeCombo cardList) { StreamWriter sw = new StreamWriter("/Users/hc/Desktop/Evostone-master/TestBed/StrategySearch/resources/decks/pools/metaDecks.tml"); Console.WriteLine("Writing............"); sw.WriteLine("PoolName = \"Meta Decks\""); sw.WriteLine("[[Decks]]"); sw.WriteLine("DeckName = \"Tempo Rogue\""); string className = cardList.ComboClass.ToLower(); sw.WriteLine("ClassName = \"" + Char.ToUpper(className[0]) + className.Substring(1) + "\""); sw.Write("CardList = ["); int i = 0; while (i < 29) { sw.Write("\"" + cardList.ComboCards[i].Name + "\"" + ", "); i++; } sw.Write("\"" + cardList.ComboCards[29].Name + "\""); sw.Write("]"); sw.Flush(); sw.Close(); }
public double CalculateNew(LargeCombo large1, LargeCombo large2) { double vecP = 1.0; double vecCost = 1.0; double vecAOE = 1.0; double vecRemove = 1.0; double vecHQ = 1.0; vecP = (vecCost * wCost + vecAOE * wAOE + vecRemove * wRemove + vecHQ * wHQ) / (wRemove + wHQ + wAOE + wCost); return(vecP); }
public void randomCombine(DNA dna) { int index1 = rand.Next(Container.Count), index2 = rand.Next(Container.Count); LargeCombo large1 = Container[index1], large2 = Container[index2]; if (CheckMerge(large1, large2, dna)) { LargeCombo merged = new LargeCombo(large1, large2); if (merged.ComboCards.Count == 30) { Deck = merged; return; } Container.Add(merged); } }
public double CalculateByEvolution(LargeCombo large1, LargeCombo large2, DNA dna) { wAOE = dna.weights[DNA.AOEW]; wRemove = dna.weights[DNA.RMW]; wHQ = dna.weights[DNA.HQW]; wCost = dna.weights[DNA.CW]; int count = large1.ComboCards.Count + large2.ComboCards.Count; double vecCost = (large1.Cost + large2.Cost) / count; double vecAOE = (large1.AOEScore + large2.AOEScore) / count; double vecRemove = (large1.RMScore + large2.RMScore) / count; double vecHQ = (large2.HQScore + large2.HQScore) / count; double vecP = (vecCost * wCost + vecAOE * wAOE + vecRemove * wRemove + vecHQ * wHQ) / (wRemove + wHQ + wAOE + wCost); return(vecP); }
public static LargeCombo[] DeckBuildingBinary(List <SingleCard> CardWithTag, HashSet <SmallCombo> ComboSet) { InitToLarge(CardWithTag, ComboSet); Deck = null; while (Deck == null) { randomCombine(0); } DeckArray[0] = Deck; Deck = null; while (Deck == null) { randomCombine(1); } DeckArray[1] = Deck; Deck = null; return(DeckArray); }
public double CalculateByEvolution(LargeCombo large1, LargeCombo large2, DNA dna) { wAOE = dna.weights[DNA.AOEW]; wRemove = dna.weights[DNA.RMW]; wHQ = dna.weights[DNA.HQW]; wCost = dna.weights[DNA.CW]; int count = large1.ComboCards.Count + large2.ComboCards.Count; double vecCost = (large1.Cost + large2.Cost) / count; double vecAOE = (large1.AOEScore + large2.AOEScore) / count; double vecRemove = (large1.RMScore + large2.RMScore) / count; double vecHQ = (large1.HQScore + large2.HQScore) / count; double costPenalty = Math.Max(0, vecCost - 4.5) * wCost; double vecP = ((vecAOE * wAOE + vecRemove * wRemove + vecHQ * wHQ) / (100 * (wRemove + wHQ + wAOE))) - costPenalty; return(Math.Max(0.1, vecP)); }
public bool CheckMerge(LargeCombo large1, LargeCombo large2, DNA dna) { if (large1.ComboCards.Count + large2.ComboCards.Count > 30) { return(false); } if (large1.ComboClass != "NEUTRAL" && large2.ComboClass != "NEUTRAL" && large1.ComboClass != large2.ComboClass) { return(false); } if (HasIllegalDuplicate(large1, large2)) { return(false); } double p = new DynamicVectorCalculator().CalculateByEvolution(large1, large2, dna); if (rand.NextDouble() > p) { //Console.WriteLine("ref, p = " + p.ToString()); return(false); } return(true); }
public double Calculate(LargeCombo large1, LargeCombo large2) { double vecP = 1.0; double vecCost = 1.0; double vecAOE = 1.0; double vecRemove = 1.0; double vecHQ = 1.0; int len1 = large1.ComboCards.Count; int len2 = large2.ComboCards.Count; int lenBig = len2; int lenSmall = len1; double avg1 = large1.Cost / len1; double avg2 = large2.Cost / len2; double avgBig = avg1; double avgSmall = avg2; if (len1 > len2) { lenBig = len1; lenSmall = len2; avgBig = avg1; avgSmall = avg2; } if ((large1.Tags["AOE"] + large2.Tags["AOE"]) > 4) { vecAOE = 0.1; } else if (((large1.Tags["AOE"] + large2.Tags["AOE"]) == 1) || ((large1.Tags["AOE"] + large2.Tags["AOE"]) == 2)) { vecAOE = 0.8; } if ((large1.Tags["Remove"] + large2.Tags["Remove"]) > 4) { vecRemove = 0.1; } else if (((large1.Tags["Remove"] + large2.Tags["Remove"]) == 1) || ((large1.Tags["Remove"] + large2.Tags["Remove"]) == 2)) { vecRemove = 0.8; } if ((large1.Tags["High Quality"] + large2.Tags["High Quality"]) > 4) { vecHQ = 0.1; } else if (((large1.Tags["High Quality"] + large2.Tags["High Quality"]) == 1) || ((large1.Tags["High Quality"] + large2.Tags["High Quality"]) == 2)) { vecHQ = 0.8; } if ((len1 + len2) < 20) { vecCost = 1; } else { if (avgSmall <= 2.7) { vecCost = 1; } else if (avgSmall >= 5 && avgBig <= 3.5) { vecCost = 1; } else { vecCost = 0.5; } } vecP = (vecCost * wCost + vecAOE * wAOE + vecRemove * wRemove + vecHQ * wHQ) / (wRemove + wHQ + wAOE + wCost); return(vecP); }
public double Calculate(LargeCombo large1, LargeCombo large2, int RangeFlag) { // 0: low, 1: high double vecP = 1.0; double vecCost = 1.0; double vecAOE = 1.0; double vecRemove = 1.0; double vecHQ = 1.0; double wAOE, wRemove, wHQ, wCost; if (RangeFlag == 0) { wAOE = wAOEL; wRemove = wRemoveL; wHQ = wHQL; wCost = wCostL; } else { wAOE = wAOEH; wRemove = wRemoveH; wHQ = wHQH; wCost = wCostH; } int len1 = large1.ComboCards.Count; int len2 = large2.ComboCards.Count; int lenBig = len2; int lenSmall = len1; double avg1 = large1.Cost / len1; double avg2 = large2.Cost / len2; double avgBig = avg1; double avgSmall = avg2; if (len1 > len2) { lenBig = len1; lenSmall = len2; avgBig = avg1; avgSmall = avg2; } if ((large1.Tags["AOE"] + large2.Tags["AOE"]) > 4) { vecAOE = 0.1; } else if (((large1.Tags["AOE"] + large2.Tags["AOE"]) == 1) || ((large1.Tags["AOE"] + large2.Tags["AOE"]) == 2)) { vecAOE = 0.8; } if ((large1.Tags["Remove"] + large2.Tags["Remove"]) > 4) { vecRemove = 0.1; } else if (((large1.Tags["Remove"] + large2.Tags["Remove"]) == 1) || ((large1.Tags["Remove"] + large2.Tags["Remove"]) == 2)) { vecRemove = 0.8; } if ((large1.Tags["High Quality"] + large2.Tags["High Quality"]) > 4) { vecHQ = 0.1; } else if (((large1.Tags["High Quality"] + large2.Tags["High Quality"]) == 1) || ((large1.Tags["High Quality"] + large2.Tags["High Quality"]) == 2)) { vecHQ = 0.8; } if ((len1 + len2) < 20) { vecCost = 1; } else { if (avgSmall <= 2.7) { vecCost = 1; } else if (avgSmall >= 5 && avgBig <= 3.5) { vecCost = 1; } else { vecCost = 0.5; } } vecP = (vecCost * wCost + vecAOE * wAOE + vecRemove * wRemove + vecHQ * wHQ) / (wRemove + wHQ + wAOE + wCost); return(vecP); }