protected override void ExecuteInternal(ParameterSet parameters)
        {
            var sheetName   = parameters.Get(Sheet);
            var expr        = parameters.Get(Expression);
            var balanceData = BalanceLibrary.GetBalanceData(sheetName);

            var evaluator = new BalanceStringEvaluator(balanceData);
            var result    = evaluator.Evaluate(expr);

            Console.WriteLine(result);
        }
Example #2
0
        protected override void ExecuteInternal(ParameterSet parameters)
        {
            var sheetName               = parameters.Get(Sheet);
            var debug                   = parameters.Get(Debug);
            CardDataSpreadsheet sheet   = this.Context.SpreadsheetManager.Load(sheetName);
            SheetPrinter        printer = new SheetPrinter(this.Context, new PrintOptions(debug, parameters.Get(NoCount), parameters.Get(NoPic)));

            printer.CreatePDF(sheet);

            Console.WriteLine("Done!");
            Console.WriteLine();
        }
Example #3
0
        protected override void ExecuteInternal(ParameterSet parameters)
        {
            var cmdName = parameters.Get(Command);

            if (cmdName != null)
            {
                var cmd = Program.Commands.FirstOrDefault(x => x.Name == cmdName);
                if (cmd != null)
                {
                    cmd.PrintHelp();
                }
                else
                {
                    Console.WriteLine("Unrecognized command: " + cmdName);
                }
            }
            else
            {
                foreach (var cmd in Program.Commands)
                {
                    Console.WriteLine(cmd.Name + ": " + cmd.Description);
                }
            }

            Console.WriteLine();
        }
        protected override void ExecuteInternal(ParameterSet parameters)
        {
            var sheet       = parameters.Get(Sheet);
            var balanceData = BalanceLibrary.GetBalanceData(sheet);

            List <Tuple <int, int> > crops = new List <Tuple <int, int> >()
            {
                new Tuple <int, int>(2, 2),
                new Tuple <int, int>(3, 3),
                new Tuple <int, int>(5, 4),
                new Tuple <int, int>(7, 5),
            };

            foreach (Tuple <int, int> crop in crops)
            {
                int cropHand = crop.Item1;
                int cropDew  = crop.Item2;

                Console.WriteLine();
                Console.WriteLine($"Sim with cropHand={cropHand} cropDew={cropDew} cropNet={FormatDouble(balanceData.Data[$"cropnet{cropHand}_{cropDew}"])}");

                var sum   = 0;
                var turns = new double[] { 5, 5, 5, 4, 4, 4, 3, 3, 3 };

                for (int i = 0; i < turns.Length; i++)
                {
                    var income = turns[i];
                    sum += (int)income;

                    if (i != turns.Length - 1)
                    {
                        var net = balanceData.Data[$"cropnet{cropHand}_{cropDew}"];
                        net *= income / cropHand;
                        Console.WriteLine($"Turn {i}: {FormatDouble(income)} nets {FormatDouble(net)}");

                        if (i + cropDew < turns.Length)
                        {
                            turns[i + cropDew] += net;
                        }
                        else
                        {
                            turns[turns.Length - 1] += net;
                        }
                    }
                    else
                    {
                        Console.WriteLine($"Turn {i}: {FormatDouble(income)} (no net on last turn)");
                    }
                }

                Console.WriteLine($"Sum: {FormatDouble(sum)}");
            }
        }
Example #5
0
        protected override MutationMemory Remember(ParameterSet initialExample, ParameterSet mutatedExample)
        {
            string focusPath = mutatedExample.GetDifference(initialExample).FieldPath;

            MutationMemory memory = new MutationMemory();
            memory.Lifetime = memory.ResetLifetime = 10;
            memory.Mutate = delegate(ParameterSet initial)
            {
                ParameterSet mutated = initial.Clone();
                ParameterValue parameter = mutated.Get(focusPath);
                Mutate(parameter);
                return mutated;
            };
            memory.IsRelevant = (initial, mutated) => mutated.GetDifference(initial).FieldPath == focusPath;
            return memory;
        }
Example #6
0
 protected override IEnumerable <MutationMemory> InitializeMemory()
 {
     foreach (string parameterPath in ParameterPaths)
     {
         string         parameterPathCopy = parameterPath;
         MutationMemory memory            = new MutationMemory();
         memory.Lifetime = memory.ResetLifetime = 20;
         memory.Mutate   = delegate(ParameterSet initial)
         {
             ParameterSet   mutated   = initial.Clone();
             ParameterValue parameter = mutated.Get(parameterPathCopy);
             Mutate(parameter);
             return(mutated);
         };
         memory.IsRelevant = (initial, mutated) => mutated.GetDifference(initial).FieldPath == parameterPathCopy;
         yield return(memory);
     }
 }
Example #7
0
        public ParameterSet Mutate(ParameterSet initial)
        {
            var advices = (from advisor in Advisors
                           from repeat in Enumerable.Range(0, MultipleAdvices)
                           from advice in advisor.Advise(initial)
                           select advice).ToList();

            AdjustExtractorWeight(advices);

            ParameterSet mutated = PickAdvice(advices).Mutated;

            string mutatedPath = mutated.GetDifference(initial).FieldPath;

            if (OnMutation != null)
            {
                OnMutation(initial.Get(mutatedPath), mutated.Get(mutatedPath));
            }

            return(mutated);
        }
Example #8
0
        protected override void ExecuteInternal(ParameterSet parameters)
        {
            var sheetName             = parameters.Get(Sheet);
            var balanceData           = BalanceLibrary.GetBalanceData(sheetName);
            CardDataSpreadsheet sheet = this.Context.SpreadsheetManager.Load(sheetName);

            var evaluator = new BalanceStringEvaluator(balanceData);
            List <BalancedCard> balanced = new List <BalancedCard>();

            List <Tuple <double, string> > spells = new List <Tuple <double, string> >();
            List <Tuple <double, string> > crops  = new List <Tuple <double, string> >();

            foreach (var card in sheet.Cards)
            {
                if (card.Id.Contains("blank"))
                {
                    continue;
                }

                if (card.Type == "spell")
                {
                    var    spellCard = (SpellCardData)card;
                    double budget    = balanceData.Data[$"spellbudget{spellCard.PlantValue}"];
                    double effectest = evaluator.Evaluate(spellCard.EffectPowerEstimate);
                    double vp        = spellCard.Offerings;

                    double opness = budget - effectest - vp;
                    Tuple <double, string> output = new Tuple <double, string>(
                        opness,
                        $"{spellCard.Title}: budget={FormatDouble(budget)} est={FormatDouble(effectest)} vp={vp} sum={FormatDouble(effectest + vp)} delta={FormatDouble(opness)}");

                    spells.Add(output);
                }
                else if (card.Type == "crop")
                {
                    var cropCard = (CropCardData)card;

                    double budget = balanceData.Data[$"cropbudget{cropCard.PlantCost}_{cropCard.HarvestCost}"];
                    double effectsingleturnest = evaluator.Evaluate(cropCard.EffectPowerEstimate);
                    double effectest           = balanceData.CostCropEffect(cropCard.PlantCost, cropCard.HarvestCost, cropCard.EffectCost, effectsingleturnest);
                    double harvestest          = evaluator.Evaluate(cropCard.HarvestPowerEstimate);
                    double vp = cropCard.Offerings;

                    double totalpower             = effectest + harvestest + vp;
                    double opness                 = budget - totalpower;
                    Tuple <double, string> output = new Tuple <double, string>(
                        opness,
                        $"{cropCard.Title}: budget={FormatDouble(budget)} harvestest={FormatDouble(harvestest)} effectest={FormatDouble(effectest)} vp={vp} sum={FormatDouble(totalpower)} delta={FormatDouble(opness)}");

                    crops.Add(output);
                }
            }

            Console.WriteLine("Spells");
            foreach (var s in spells.OrderBy(x => x.Item1).Select(x => x.Item2))
            {
                Console.WriteLine(s);
            }

            Console.WriteLine();
            Console.WriteLine("Crops");
            foreach (var s in crops.OrderBy(x => x.Item1).Select(x => x.Item2))
            {
                Console.WriteLine(s);
            }
        }
Example #9
0
        protected override void ExecuteInternal(ParameterSet parameters)
        {
            var sheetName = parameters.Get(Sheet);
            var debug     = parameters.Get(Debug);

            CardDataSpreadsheet sheet = this.Context.SpreadsheetManager.Load(sheetName);
            var spellCards            = sheet.Cards.Where(x => x is SpellCardData).Select(x => x as SpellCardData);
            var cropCards             = sheet.Cards.Where(x => x is CropCardData).Select(x => x as CropCardData);

            int[] cropSums  = new int[8];
            int[] spellSums = new int[8];
            for (int i = 0; i < 8; i++)
            {
                cropSums[i]  = cropCards.Where(x => x.Color != "white").Where(x => x.PlantCost == i).Sum(x => x.Count);
                spellSums[i] = spellCards.Where(x => x.PlantValue == i).Sum(x => x.Count);
            }

            Console.WriteLine("");
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Crops");
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("");
            for (int i = 0; i < 8; i++)
            {
                string bar = new string('=', cropSums[i]);
                Console.WriteLine(i.ToString() + ": " + bar + " " + cropSums[i].ToString());
            }

            int[,] cropMatrix = new int[8, 8];
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    cropMatrix[i, j] = cropCards.Where(x => x.Color != "white").Where(x => x.PlantCost == i && x.HarvestCost == j).Sum(x => x.Count);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Plant \\ Dew");
            Console.WriteLine("   1   2   3   4   5   6   7");
            for (int i = 1; i < 8; i++)
            {
                Console.Write(i + ": ");

                for (int j = 1; j < 8; j++)
                {
                    Console.Write($"{cropMatrix[i, j].ToString().PadLeft(3)} ");
                }

                Console.WriteLine();
            }

            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("Spells");
            Console.WriteLine("----------------------------------------------------------------");
            Console.WriteLine("");
            for (int i = 0; i < 8; i++)
            {
                string bar = new string('=', spellSums[i]);
                Console.WriteLine(i.ToString() + ": " + bar + " " + spellSums[i].ToString());
            }
        }