public SimulationCalculator(RewardPool rewardPool)
        {
            this.rewardPool = rewardPool;
            Fraction product = new Fraction(1, 1);

            foreach (var rewardItem in rewardPool.RewardItems)
            {
                product *= rewardItem.Rarity;
            }
            totalSlots = (int)product.Denominator;
        }
Exemple #2
0
        static void FindAverage(string parameters, string[] lines, bool printItems)
        {
            if (parameters.Split('/').Length > 1)
            {
                foreach (var par in parameters.Split('/'))
                {
                    FindAverage(par, lines, printItems);
                }
                return;
            }
            var rewardPool = new RewardPool(lines);

            if (printItems)
            {
                rewardPool.PrintItems();
            }
            ICalculator calculator;
            var         sw         = new Stopwatch();
            string      calcText   = "";
            string      outputText = "";

            if (parameters.StartsWith("mc"))
            {
                calculator = new AnalyticCalculator(rewardPool);
                calcText   = "Trying to solve markov-chain";
                outputText = "Solving markov-chain took {0} ms";
            }
            else
            {
                if (parameters.Split(' ').Length == 2)
                {
                    SimulationCalculator.Tries = Convert.ToInt32(parameters.Split(' ')[1]);
                }
                else
                {
                    SimulationCalculator.Tries = defaultNSimulations;
                }
                calcText   = "Simulating until " + SimulationCalculator.Tries + " completions";
                calculator = new SimulationCalculator(rewardPool);
                outputText = "Simulation of " + SimulationCalculator.Tries + " completions took {0} ms";
            }
            Console.WriteLine(calcText);
            sw.Start();
            var result = calculator.CalculateAverage();

            sw.Stop();
            Console.WriteLine("On average needed {0:F2} tries", result);
            Console.WriteLine(outputText, sw.ElapsedMilliseconds);
        }
Exemple #3
0
        public static Matrix <double> CreateMatrix(RewardPool rewardPool)
        {
            rows = new List <int>();
            cols = new List <int>();
            vals = new List <double>();
            var table = new Dictionary <int[], int>(new MyComparer());
            var goal  = rewardPool.RewardItems.Select(t => t.Amount).ToArray();
            var probs = rewardPool.RewardItems.Select(t => (double)t.Rarity).ToArray();
            int len   = goal.Length;
            var list  = new List <int[]>();
            int index = 0;

            list.Add(goal);
            table.Add(goal, index++);
            NewValue(table[goal], table[goal], 1);
            while (list[0].Sum() != 0)
            {
                var newlist = new HashSet <int[]>(new MyComparer());
                for (int i = 0; i < list.Count; i++)
                {
                    for (int j = 0; j < len; j++)
                    {
                        if (list[i][j] > 0)
                        {
                            int[] arr = new int[len];
                            Array.Copy(list[i], arr, len);
                            arr[j]--;
                            if (!newlist.Contains(arr))
                            {
                                newlist.Add(arr);
                                table.Add(arr, index++);
                                NewValue(table[arr], table[arr], 1 - probs[j]);
                                NewValue(table[arr], table[list[i]], probs[j]);
                            }
                            else
                            {
                                AddToValue(table[arr], table[arr], -probs[j]);
                                NewValue(table[arr], table[list[i]], probs[j]);
                            }
                        }
                    }
                }
                list = newlist.ToList();
            }
            return(GetMatrix());
        }
Exemple #4
0
 public AnalyticCalculator(RewardPool rewardPool)
 {
     this.rewardPool = rewardPool;
 }