Example #1
0
 private void Explain(EvolutionOutcome evolutionOutcome, int stars)
 {
     Console.WriteLine($"We want to make a {stars}, best input was {evolutionOutcome.Input}, computed value was {evolutionOutcome.Value}");
     Console.WriteLine("Total Cost:");
     Console.WriteLine(evolutionOutcome.Cost);
     Console.WriteLine("Here's the steps");
     foreach (var action in evolutionOutcome.Actions)
     {
         Console.WriteLine(action);
     }
 }
Example #2
0
        /* private Tuple<Node,Cost, List<Node>,Tuple<int, int, int, int, int>> GetUnit(int stars)
         * {
         *   return stars < MinMakeThreshold ? Tuple.Create(new Node(stars), new Cost(),  new List<Node>(), Tuple.Create(1,0,0,0,0)) : Make(stars);
         * }
         *
         * private Tuple<Node, Cost, List<Node>> Make(int stars)
         * {
         *   var possibleInputs = GetPossiblePowerUpCombos(stars - 1);
         *   var from = GetUnit(stars - 1);
         *   var baseUnit = from.Item1;
         *   var cost = from.Item2;
         *   var output = new List<Node>();
         *   var minValue = double.MaxValue;
         *   var bestOutput = (List<Node>)null;
         *   var bestCost = (Cost)null;
         *   var bestInput = default(Tuple<int, int, int, int, int>);
         *   foreach (var possibleInput in possibleInputs)
         *   {
         *       var input = new Node[possibleInput.Item1 + possibleInput.Item2 + possibleInput.Item3 +
         *                            possibleInput.Item4 + possibleInput.Item5];
         *       var i = 0;
         *       for (int j = 0; j < possibleInput.Item1; j++,i++)
         *       {
         *           var unit = GetUnit(1);
         *           input[i] = unit.Item1;
         *           cost.Add(unit.Item2);
         *           output.AddRange(unit.Item3);
         *       }
         *
         *       for (int j = 0; j < possibleInput.Item2; j++, i++)
         *       {
         *           var unit = GetUnit(2);
         *           input[i] = unit.Item1;
         *           cost.Add(unit.Item2);
         *           output.AddRange(unit.Item3);
         *       }
         *       for (int j = 0; j < possibleInput.Item3; j++, i++)
         *       {
         *           var unit = GetUnit(3);
         *           input[i] = unit.Item1;
         *           cost.Add(unit.Item2);
         *           output.AddRange(unit.Item3);
         *       }
         *       for (int j = 0; j < possibleInput.Item4; j++, i++)
         *       {
         *           var unit = GetUnit(4);
         *           input[i] = unit.Item1;
         *           cost.Add(unit.Item2);
         *           output.AddRange(unit.Item3);
         *       }
         *       for (int j = 0; j < possibleInput.Item5; j++, i++)
         *       {
         *           var unit = GetUnit(5);
         *           input[i] = unit.Item1;
         *           cost.Add(unit.Item2);
         *           output.AddRange(unit.Item3);
         *       }
         *       baseUnit.MakeMaxLevel(cost);
         *       baseUnit.ApplyPowerUp(cost,input);
         *       output.Add( baseUnit.Evolve(cost));
         *       var value = _costAnalysis(cost, output);
         *       if (value < minValue)
         *       {
         *           minValue = value;
         *           bestCost = cost;
         *           bestOutput = output;
         *           bestInput = possibleInput;
         *       }
         *   }
         *   return Tuple.Create(new Node(stars), bestCost, bestOutput, bestInput);
         * }
         *
         * public Tuple<Node, Cost> CreateUnit(int stars)
         * {
         *   var x = GetUnit(stars);
         *   Bag[1] -= x.Item4.Item1;
         *   Bag[2] -= x.Item4.Item2;
         *   Bag[3] -= x.Item4.Item3;
         *   Bag[4] -= x.Item4.Item4;
         *   Bag[5] -= x.Item4.Item5;
         *   foreach (var node in x.Item3)
         *   {
         *       Bag[node.Stars]++;
         *   }
         *
         *   return Tuple.Create(x.Item1, x.Item2);
         * }*/

        public void Go()
        {
            var bestCostPerStar = new EvolutionOutcome[6];

            bestCostPerStar[0] = new EvolutionOutcome();
            for (var i = 0; i < bestCostPerStar.Length; i++)
            {
                bestCostPerStar[i] = GetBestCostPerStar(i + 1, bestCostPerStar);
                Explain(bestCostPerStar[i], i + 1);
            }

            Console.Read();
        }
Example #3
0
 private Node GetUnit(int stars, EvolutionOutcome current, EvolutionOutcome[] bestCostPerStar)
 {
     //if we have one, we return that one
     if (current.OutputUnits.Bag[stars] > 0)
     {
         current.Actions.Add($"Needed a {stars}, had one in inventory, using that");
         current.OutputUnits.Decrement(stars);
         current.CreatedUnits.Increment(stars);
         current.Actions.Add($"Current output bag state: {current.OutputUnits}");
         current.Actions.Add($"Current create bag state: {current.CreatedUnits}");
         return(new Node(stars));
     }
     //else we need to make a new one
     current.Actions.Add($"Needed a {stars}, creating one by {bestCostPerStar[stars-1].CreateMethod}");
     current.Cost.Add(bestCostPerStar[stars - 1].Cost);
     current.OutputUnits.Add(bestCostPerStar[stars - 1].OutputUnits);
     current.CreatedUnits.Increment(stars);
     current.Actions.Add($"Current output bag state: {current.OutputUnits}");
     current.Actions.Add($"Current create bag state: {current.CreatedUnits}");
     return(new Node(stars));
 }
Example #4
0
        private static double UnitCount(EvolutionOutcome o)
        {
            var c = o.Cost;

            return(o.Input.Bag.Sum(kvp => kvp.Value));
        }
Example #5
0
        private static double ExpBooks(EvolutionOutcome o)
        {
            var c = o.Cost;

            return(c.Experience / 100.0 + c.Books * c.Books - o.OutputUnits.Level1 - o.OutputUnits.Level2 * 10 - o.OutputUnits.Level3 * 100 - o.OutputUnits.Level4 * 1000 - o.OutputUnits.Level5 * 10000);
        }
Example #6
0
        private static double ExpOnly(EvolutionOutcome o)
        {
            var c = o.Cost;

            return(c.Experience);
        }
Example #7
0
        private static double SumAll(EvolutionOutcome o)
        {
            var c = o.Cost;

            return((double)(c.EvolutionStones + c.Experience + c.Gold + c.MovementStones + 1000000 * c.Books));
        }
Example #8
0
        /// <summary>
        /// gets the best cost of making a <paramref name="stars"/> unit. Meaning powering up a
        /// unit thats one level lower to +5 and evolving it
        /// </summary>
        /// <param name="stars"></param>
        /// <param name="bestCostPerStar"></param>
        /// <returns></returns>
        private EvolutionOutcome GetBestCostPerStar(int stars, EvolutionOutcome[] bestCostPerStar)
        {
            if (stars == 1)
            {
                var ret = new EvolutionOutcome();
                ret.Actions.Add("Summon a level 1");
                ret.Cost.Gold += 3000;
                ret.Cost.Books++;
                ret.CreatedUnits.Level1++;
                ret.CreateMethod = "Summon";
                return(ret);
            }

            if (stars == 2)
            {
                var ret = new EvolutionOutcome();
                ret.Actions.Add("Summon a level 2");
                ret.Cost.Gold  += 30000;
                ret.Cost.Books += 10;
                ret.CreatedUnits.Level2++;
                ret.CreateMethod = "Summon";
                return(ret);
            }
            var possibleInputs = GetPossiblePowerUpCombos(stars - 1);
            var minValue       = double.MaxValue;
            var bestCost       = new EvolutionOutcome();

            foreach (var possibleInput in possibleInputs)
            {
                var current = new EvolutionOutcome {
                    Input = possibleInput
                };
                var baseUnit = GetUnit(stars - 1, current, bestCostPerStar);
                //var baseUnit = new Node(stars-1);
                for (var i = 0; i < possibleInput.Level5; i++)
                {
                    GetUnit(5, current, bestCostPerStar);
                }
                for (var i = 0; i < possibleInput.Level4; i++)
                {
                    GetUnit(4, current, bestCostPerStar);
                }
                for (var i = 0; i < possibleInput.Level3; i++)
                {
                    GetUnit(3, current, bestCostPerStar);
                }
                for (var i = 0; i < possibleInput.Level2; i++)
                {
                    GetUnit(2, current, bestCostPerStar);
                }
                for (var i = 0; i < possibleInput.Level1; i++)
                {
                    GetUnit(1, current, bestCostPerStar);
                }

                baseUnit.MakeMaxLevel(current.Cost);
                baseUnit.ApplyPowerUp(current.Cost, current.CreatedUnits);
                baseUnit.Evolve(current);
                var value = _costAnalysis(current);
                current.Value = value;
                if (value < minValue)
                {
                    minValue = value;
                    bestCost = current;
                }
            }
            bestCost.Input.Increment(stars - 1);
            bestCost.CreateMethod = $"Evolve with {bestCost.Input}";
            return(bestCost);
        }