Пример #1
0
        /// <summary>
        /// <para>
        ///     Static-based Prediction Algorithm is an another high abstraction prediction algorithm.
        ///     Unlike the <see cref="LanchesterBasedPrediction(TargetPolicy)"/>, the computation focuses more
        ///     on time-related properties of combat. However, like the mentioned prediction algorithm, it still
        ///     exchanges fine detail for faster computing. Like the <see cref="LanchesterBasedPrediction(TargetPolicy)"/>,
        ///     It does not consider that the Energy decreases over time, and that some skills have cooldown and duration.
        ///     However, it does consider that the damage is not constant by adding noises to the damage such as
        ///     there are times it is the current damage, and sometimes it is more than the current damage. It also considers
        ///     that some units cannot target other units, and considers skills that deals damage/boost damage but not on the
        ///     finest detail. Lastly, it also consider that the dealt damage is reduced by the armor.
        /// </para>
        /// <para>
        ///     This method returns a string of survived units from the winning army, but the cost worth of doing
        ///     battle is always relative to the player. As such, if the opposing army won, the cost worth returned
        ///     is negative since it represents as a loss.
        /// </para>
        /// </summary>
        /// <remarks>
        /// <para>
        ///     While it still looks the army as a whole, it computes more parameters.
        ///     The probable running time is O(4n^2 + 32n)
        /// </para>
        /// <para>
        ///     In summary, it is almost like the Lanchester-based prediction where it looks at the army as
        ///     a whole, but also considers the time-related property of combat. Lastly, it also adds noise
        ///     to the damage being dealt to the target. It considers and does not consider the following:
        ///     Considers:
        ///     <list type="bullet">
        ///         <item>Current and Decreasing Health</item>
        ///         <item>True Current Damage (Current Damage applied with opposing Armor)</item>
        ///         <item>Restrictions in targeting unit</item>
        ///         <item>Skills that deals damage and gives boost to the damage of unit</item>
        ///         <item>Time-related properties to battle</item>
        ///     </list>
        ///     Does not Consider:
        ///     <list type="bullet">
        ///         <item>Decreasing Energy</item>
        ///         <item>Skills with Cooldown and Duration</item>
        ///         <item>Skills that affects Health/Energy</item>
        ///         <item>AoE Damage / Chaining Damage</item>
        ///         <item>Transforming Units</item>
        ///         <item>Damage with bonus to target type</item>
        ///     </list>
        /// </para>
        /// </remarks>
        /// <param name="target_policy"></param>
        /// <returns></returns>
        public Tuple <string, CostWorth> StaticBasedPrediction(TargetPolicy target_policy)
        {
            Tuple <string, CostWorth> battle_result = null;

            try
            {
                //Create a copy of the units
                var owned_units = _owned_units.GetDeepCopy();
                var enemy_units = _enemy_units.GetDeepCopy();

                //Set the targets for each army
                //This will get the true damage of unit, and a target to be attacked
                switch (target_policy)
                {
                case TargetPolicy.Random:
                    RandomBasedTargetPolicy(ref owned_units, enemy_units);
                    RandomBasedTargetPolicy(ref enemy_units, owned_units);
                    break;

                case TargetPolicy.Priority:
                    PriorityBasedTargetPolicy(ref owned_units, enemy_units);
                    PriorityBasedTargetPolicy(ref enemy_units, owned_units);
                    break;

                case TargetPolicy.Resource:
                    ResourceBasedTargetPolicy(ref owned_units, enemy_units);
                    ResourceBasedTargetPolicy(ref enemy_units, owned_units);
                    break;
                }

                //Compute the battle output
                var combat_result = new StaticCombatResult(owned_units, enemy_units);
                var combat_time   = StaticCombatResult.GetCombatTime(combat_result);

                //Let both armies attack each other
                owned_units.DealDamageToTarget(combat_time);
                enemy_units.DealDamageToTarget(combat_time);

                //Get the surviving units of the winner
                var survived_owned_units = owned_units.Where(unit => !unit.IsDefeated).ToArmy();
                var survived_enemy_units = enemy_units.Where(unit => !unit.IsDefeated).ToArmy();
                //Owned Army Loss
                if (survived_owned_units.Count() < survived_enemy_units.Count())
                {
                    battle_result = new Tuple <string, CostWorth>(survived_enemy_units.ToString(), !survived_enemy_units.GetValueOfArmy());
                }
                //Owned Army Won
                else if (survived_owned_units.Count() > survived_enemy_units.Count())
                {
                    battle_result = new Tuple <string, CostWorth>(survived_owned_units.ToString(), survived_owned_units.GetValueOfArmy());
                }
                //Draw
                else
                {
                    battle_result = new Tuple <string, CostWorth>(@"""""", default(CostWorth));
                }
            }
            catch (ArgumentNullException ex)
            {
                Console.WriteLine($@"StaticBasedPrediction() [{target_policy.ToString()}] -> {ex.Message}");
                throw new Exception("");
            }
            catch (Exception ex)
            {
                Console.WriteLine($@"StaticBasedPrediction() -> {ex.Message}");
                battle_result = null;
            }

            return(battle_result);
        }
Пример #2
0
 /// <summary>
 /// Returns the combat time
 /// </summary>
 /// <param name="combat_result"></param>
 /// <returns></returns>
 public static int GetCombatTime(StaticCombatResult combat_result) => Convert.ToInt32(Math.Ceiling(combat_result.TimeToKill));