Example #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("<options file location> <output file location>");
                return;
            }

            List <List <round> > results = new List <List <round> > ();

            _runoptions = Newtonsoft.Json.JsonConvert.DeserializeObject <run_options> (System.IO.File.ReadAllText(args[0]));

            string out_location = args[1];

            int[] atk_assets = _runoptions.attacking_assets.Select(e => e).ToArray();

            int[] def_assets = _runoptions.defending_assets.Select(e => e).ToArray();

            List <Asset> attacking_assets = initialize_assets(_runoptions.atk_asset_hp, atk_assets);

            List <Asset> defending_assets = initialize_assets(_runoptions.def_asset_hp, def_assets);

            Faction attacking_faction = null;

            if (_runoptions.attacking_id != 0)
            {
                attacking_faction = _dbc.get_faction(con, _runoptions.attacking_id);
            }

            Faction defending_faction = null;

            if (_runoptions.defending_id != 0)
            {
                defending_faction = _dbc.get_faction(con, _runoptions.defending_id);

                if (_runoptions.def_faction_hp > 0)
                {
                    defending_faction.hp = _runoptions.def_faction_hp;
                }
            }

            run_options.apply_runoptions(ref attacking_assets, ref defending_assets, ref attacking_faction, ref defending_faction, _runoptions);

            using (var progress = new ProgressBar())
            {
                for (int i = 0; i < _runoptions.iterations; i++)
                {
                    progress.Report((double)i / _runoptions.iterations);
                    attacking_assets.ForEach(e => e.resetHP());
                    defending_assets.ForEach(e => e.resetHP());
                    var result = run_sim(attacking_faction, defending_faction, attacking_assets, defending_assets);
                    results.Add(result);
                }
            }

            var stats = get_results(results, attacking_assets, _runoptions.iterations);

            System.IO.File.WriteAllText(out_location, Newtonsoft.Json.JsonConvert.SerializeObject(stats, Formatting.Indented));

            var stats_loc = args[0].Replace(".json", "_stats.json");

            var statistics = Classes.stats.GenStats(results);

            System.IO.File.WriteAllText(stats_loc, Newtonsoft.Json.JsonConvert.SerializeObject(statistics, Formatting.Indented));

            con.Close();

            return;
        }
Example #2
0
        public static void apply_runoptions(ref List <Asset> atk_assets, ref List <Asset> def_assets, ref Faction atk_faction, ref Faction def_faction, run_options opt)
        {
            if (opt.atk_reroll_ids.Count() > 0)
            {
                atk_assets.First(e => e.AttackerReroll == false && opt.atk_reroll_ids.Contains(e.Id)).AttackerReroll = true;
            }

            if (opt.def_reroll_ids.Count() > 0)
            {
                def_assets.First(e => e.DefenderReroll == false && opt.def_reroll_ids.Contains(e.Id)).DefenderReroll = true;
            }

            if (opt.atk_extra_dice.Count() > 0)
            {
                atk_assets.First(e => e.AttackerExtraDice == false && opt.atk_extra_dice.Contains(e.Id)).AttackerExtraDice = true;
            }

            if (opt.def_extra_dice.Count() > 0)
            {
                def_assets.First(e => e.DefenderExtraDice == false && opt.def_extra_dice.Contains(e.Id)).DefenderExtraDice = true;
            }

            if (atk_faction != null)
            {
                atk_faction.PMax = opt.attacker_pmax;
            }
            if (def_faction != null)
            {
                def_faction.PMax = opt.defender_pmax;
            }
        }