Beispiel #1
0
        internal void MultiWaveBattleCompleteHandler(object sender, EventArgs args)
        {
            m_simulationComplete = true;
            MultiWaveBattle battle = (sender as MultiWaveBattle);

            if (battle != null)
            {
                battle.OnBattleComplete -= MultiWaveBattleCompleteHandler;
                battle.OnWaveComplete   -= MultiWaveBattleWaveCompleteHandler;
            }
        }
Beispiel #2
0
 internal MultiWaveStatistics(MultiWaveBattle battle)
 {
     m_battle           = battle;
     m_dummyTotalBattle = new Battle(battle.Units.ToArray(), null, battle.EnemyUnits.ToArray(), null);
     m_dummyTotalBattle.StatisticsType = battle.StatisticsType;
 }
        internal void Calculate()
        {
            Calculator calculator = new Calculator(Options.Instance.Rounds);
            //unist, counts, general, enemy units, counts, generals
            MultiWaveBattle battle = new MultiWaveBattle(Options.Instance.Rounds);

            battle.BattleType     = Options.Instance.MultiWaveBattleType;
            battle.StatisticsType = StatisticsType.All;

            bool isEnemyEmpty    = true;
            bool isAttackerEmpty = true;

            for (int i = 0; i < MAX_WAVES_COUNT; i++)
            {
                battle.AddAttackerWave(PlayerWaves[i], m_playerGenerals[i], m_playerTowerBonus[i]);
                battle.AddEnemyWave(EnemyWaves[i], null, m_enemyTowerBonus[i], m_enemyCampDestroyTime[i]);

                if (isAttackerEmpty)
                {
                    foreach (UnitSquad squad in PlayerWaves[i])
                    {
                        if (squad.Count > 0)
                        {
                            isAttackerEmpty = false;
                        }
                    }
                }

                if (isEnemyEmpty)
                {
                    foreach (UnitSquad squad in EnemyWaves[i])
                    {
                        if (squad.Count > 0)
                        {
                            isEnemyEmpty = false;
                        }
                    }
                }
            }

            if (isEnemyEmpty || isAttackerEmpty)
            {
                Simulation    = null;
                m_totalLosses = null;
                m_waveLosses.Clear();

                OnPropertyChanged("TotalLosses");
                OnPropertyChanged("WaveLosses");
                return;
            }

            MultiWaveStatistics statistics = new MultiWaveStatistics(battle);

            battle.OnBattleComplete += statistics.MultiWaveBattleCompleteHandler;
            battle.OnWaveComplete   += statistics.MultiWaveBattleWaveCompleteHandler;

            MultyWaveBattleSimulation simulation = new MultyWaveBattleSimulation();

            battle.OnBattleComplete += simulation.MultiWaveBattleCompleteHandler;
            battle.OnWaveComplete   += simulation.MultiWaveBattleWaveCompleteHandler;

            battle.Calculate(calculator);

            battle.OnBattleComplete -= statistics.MultiWaveBattleCompleteHandler;
            battle.OnWaveComplete   -= statistics.MultiWaveBattleWaveCompleteHandler;

            battle.OnBattleComplete -= simulation.MultiWaveBattleCompleteHandler;
            battle.OnWaveComplete   -= simulation.MultiWaveBattleWaveCompleteHandler;

            statistics.Calculate();

            m_totalLosses = GenerateBattleLosses(statistics.TotalStatistics, battle);

            m_waveLosses.Clear();
            foreach (KeyValuePair <WaveKey, Statistics.Statistics> pair in statistics.Statistics)
            {
                BattleLosses waveLosses = GenerateBattleLosses(pair.Value, pair.Value.Battle);
                waveLosses.PlayerWaveIndex = pair.Key.AttackerWave + 1;
                waveLosses.EnemyWaveIndex  = pair.Key.DefenderWave + 1;
                m_waveLosses.Add(waveLosses);
            }

            OnPropertyChanged("TotalLosses");
            OnPropertyChanged("WaveLosses");

            if (simulation.Simulations.Count == 0)
            {
                simulation = null;
            }

            Simulation = simulation;
        }
 private static BattleLosses GenerateBattleLosses(Statistics.Statistics statistics, MultiWaveBattle battle)
 {
     return(GenerateBattleLosses(statistics, battle.Units, battle.EnemyUnits));
 }
        /// <summary>
        /// Combine statistics from two battle.
        /// </summary>
        /// <param name="statistics">Other battle statistics.</param>
        /// <param name="battle">Multiwave battle.</param>
        internal void CombineStatistics(Statistics statistics, MultiWaveBattle battle)
        {
            ConvertLossesToChanse();
            statistics.ConvertLossesToChanse();
            if (m_attackerLossesStatistics.Count == 0)
            {
                foreach (KeyValuePair <short[], double> lossesStatistic in statistics.m_attackerLossesStatistics)
                {
                    m_attackerLossesStatistics[ConvertLosses(lossesStatistic.Key, statistics.Battle.Units, battle.Units)] = lossesStatistic.Value;
                }
                m_isCountInAttackerLossesStatistics = statistics.m_isCountInAttackerLossesStatistics;
            }
            else
            {
                CombineLossesStatistics(
                    m_attackerLossesStatistics, m_count, battle.Units,
                    statistics.m_attackerLossesStatistics, statistics.m_count, statistics.Battle.Units);
            }

            if (m_defenderLossesStatistics.Count == 0)
            {
                foreach (KeyValuePair <short[], double> lossesStatistic in statistics.m_defenderLossesStatistics)
                {
                    m_defenderLossesStatistics[ConvertLosses(lossesStatistic.Key, statistics.Battle.EnemyUnits, battle.EnemyUnits)] = lossesStatistic.Value;
                }
                m_isCountInDefenderLossesStatistics = statistics.m_isCountInDefenderLossesStatistics;
            }
            else
            {
                CombineLossesStatistics(
                    m_defenderLossesStatistics, m_count, battle.EnemyUnits,
                    statistics.m_defenderLossesStatistics, statistics.m_count, statistics.Battle.EnemyUnits);
            }

            m_count = statistics.m_count;

            statistics.CalculateBattleTime();
            m_minBattleTime += statistics.m_minBattleTime;
            m_maxBattleTime += statistics.m_maxBattleTime;
            m_avgBattleTime += statistics.m_avgBattleTime;

            if (statistics.BattleTimeStatistics.Count > 0)
            {
                if (BattleTimeStatistics.Count == 0)
                {
                    foreach (KeyValuePair <double, double> newTimeStatistic in statistics.BattleTimeStatistics)
                    {
                        BattleTimeStatistics[newTimeStatistic.Key] = newTimeStatistic.Value;
                    }
                }
                else
                {
                    SortedDictionary <double, double> timeStatistics = new SortedDictionary <double, double>();
                    foreach (KeyValuePair <double, double> timeStatistic in BattleTimeStatistics)
                    {
                        foreach (KeyValuePair <double, double> newTimeStatistic in statistics.BattleTimeStatistics)
                        {
                            double time   = timeStatistic.Key + newTimeStatistic.Key;
                            double chance = timeStatistic.Value * newTimeStatistic.Value;
                            if (!timeStatistics.ContainsKey(time))
                            {
                                timeStatistics[time] = chance;
                            }
                            else
                            {
                                timeStatistics[time] += chance;
                            }
                        }
                    }
                    m_battleTimeStatistics = timeStatistics;
                }
            }
        }