Ejemplo n.º 1
0
        public LogBattle ExecuteBattle(BattleSettingsItem battleSettingsItem)
        {
            var battle = new Battle();

            battle.AttackHands          = GetHandsFromViewGroups(battleSettingsItem.AttackHands);
            battle.DefenceHands         = GetHandsFromViewGroups(battleSettingsItem.DefenceHands);
            battle.DefenceTurrelsGroups = GetUnitGroupsFromViewGroups(battleSettingsItem.DefenceTurrels);

            var ret = battle.SimBattle();

            return(ret);
        }
Ejemplo n.º 2
0
        public LogBattle Optimize(BattleSettingsItem battleSettingsItem)
        {
            var watch             = System.Diagnostics.Stopwatch.StartNew();
            var threadCount       = battleSettingsItem.ThreadCount;
            var quantumWeight     = battleSettingsItem.HandWeight / (battleSettingsItem.Precision == 0 ? 1 : battleSettingsItem.Precision);
            var attackHandPattern = battleSettingsItem.AttackHands[0];

            var quantumList = new List <List <UnitsView> >();

            foreach (var paternUnit in attackHandPattern.UnitsView.Where(p => p.Weight > 0).Where(p => p.Count > 0))
            {
                var unitsPerQuant               = (int)Math.Max(quantumWeight / paternUnit.Weight, 1);
                var quantumPerHandCount         = (int)(battleSettingsItem.HandWeight / (unitsPerQuant * paternUnit.Weight));
                var quantumFromExistsUnitsCount = (int)paternUnit.Count / unitsPerQuant;
                var quantumCount    = Math.Min(quantumPerHandCount, quantumFromExistsUnitsCount);
                var quantumListItem = new List <UnitsView>();
                for (var i = 0; i < quantumCount; i++)
                {
                    var quantomUnit = new UnitsView
                    {
                        Count           = unitsPerQuant * (i + 1),
                        ClassName       = paternUnit.ClassName,
                        UnitAttackPower = paternUnit.UnitAttackPower,
                        UnitArmor       = paternUnit.UnitArmor,
                        Weight          = paternUnit.Weight
                    };
                    quantumListItem.Add(quantomUnit);
                }
                quantumList.Add(quantumListItem);
            }

            var combinations = new List <List <UnitsView> >();

            for (var i = 0; i < quantumList.Count; i++)
            {
                Combine(quantumList, new List <UnitsView>(), battleSettingsItem.HandWeight, combinations, i);
            }
            var defenceHands         = GetHandsFromViewGroups(battleSettingsItem.DefenceHands);
            var defenceTurrelsGroups = GetUnitGroupsFromViewGroups(battleSettingsItem.DefenceTurrels);
            var bestResult           = decimal.MaxValue;
            var bestIndex            = 0;



            var itemsForLastThread = combinations.Count % threadCount;
            var itemsPerThread     = (combinations.Count - itemsForLastThread) / threadCount;
            var tasksList          = new Task <(decimal BestResult, int BestIndex)> [threadCount];