Exemple #1
0
    public override void Enter()
    {
        transition = m_EMFSM.emTransition;
        helper     = m_EMFSM.emHelper;

        // Turn blink animation on
        EMAnimation.Instance().CanBlink = true;

        // Reset availability to command mini cell to Landmine state
        if (!helper.CanAddLandmine)
        {
            helper.CanAddLandmine = true;
        }

        // Enable expand animation
        if (!EMAnimation.Instance().IsExpanding)
        {
            EMAnimation.Instance().IsExpanding = true;
        }

        // Reset transition availability
        transition.CanTransit = true;
        // Pause the transition for randomized time
        float fPauseTime = Random.Range((m_EMFSM.CurrentAggressiveness / 1.5f) / EMDifficulty.Instance().CurrentDiff,
                                        (m_EMFSM.CurrentAggressiveness) / EMDifficulty.Instance().CurrentDiff);

        helper.StartPauseTransition(fPauseTime);
    }
Exemple #2
0
    public override void Enter()
    {
        // Reset transition availability
        EMTransition.Instance().CanTransit = true;
        // Reset spawn availability

        // Pause the transition for randomized time based on num of available nutrient
        float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 1f) * 2f) / EMDifficulty.Instance().CurrentDiff,
                                        Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 1f) * 10f) / EMDifficulty.Instance().CurrentDiff);

        helper.StartPauseTransition(fPauseTime);
    }
    public override void Enter()
    {
        transition = m_EMFSM.emTransition;
        helper = m_EMFSM.emHelper;

        transition = m_EMFSM.emTransition;
        // Reset transition availability
        transition.CanTransit = true;
        // Pause the transition for randomized time based on num of available child cells
        float fPauseTime = Random.Range (Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().AvailableChildNum) * 10f) / EMDifficulty.Instance().CurrentDiff,
                                         Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().AvailableChildNum) * 50f) / EMDifficulty.Instance().CurrentDiff);
        helper.StartPauseTransition (fPauseTime);
    }
Exemple #4
0
    public override void Enter()
    {
        transition = m_EMFSM.emTransition;
        helper     = m_EMFSM.emHelper;

        transition = m_EMFSM.emTransition;
        // Reset transition availability
        transition.CanTransit = true;
        // Pause the transition for randomized time based on num of available child cells
        float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().AvailableChildNum) * 10f) / EMDifficulty.Instance().CurrentDiff,
                                        Mathf.Sqrt(Mathf.Sqrt(EnemyMainFSM.Instance().AvailableChildNum) * 50f) / EMDifficulty.Instance().CurrentDiff);

        helper.StartPauseTransition(fPauseTime);
    }
	public override void Enter ()
	{
		transition = m_EMFSM.emTransition;
		helper = m_EMFSM.emHelper;

		// Turn blink animation on
		EMAnimation.Instance ().CanBlink = true;

		// Reset availability to command mini cell to Attack state
		if (!helper.CanAddAttack)
			helper.CanAddAttack = true;
		
		// Reset transition availability
		transition.CanTransit = true;
		// Pause the transition for randomized time
		float fPauseTime = Random.Range (Mathf.Sqrt (m_EMFSM.CurrentAggressiveness) * 2.5f/ EMDifficulty.Instance().CurrentDiff, 
		                                 Mathf.Sqrt (m_EMFSM.CurrentAggressiveness) * 3f / EMDifficulty.Instance().CurrentDiff);
		helper.StartPauseTransition (fPauseTime);
	}
Exemple #6
0
    public override void Enter()
    {
        transition = m_EMFSM.emTransition;
        helper     = m_EMFSM.emHelper;

        // Turn blink animation on
        EMAnimation.Instance().CanBlink = true;

        // Reset availability to command mini cell to Attack state
        if (!helper.CanAddAttack)
        {
            helper.CanAddAttack = true;
        }

        // Reset transition availability
        transition.CanTransit = true;
        // Pause the transition for randomized time
        float fPauseTime = Random.Range(Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 1.5f / EMDifficulty.Instance().CurrentDiff,
                                        Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 2.5f / EMDifficulty.Instance().CurrentDiff);

        helper.StartPauseTransition(fPauseTime);
    }
    public override void Enter()
    {
        transition = m_EMFSM.emTransition;
        helper = m_EMFSM.emHelper;

        // Turn blink animation on
        EMAnimation.Instance ().CanBlink = true;

        // Reset availability to command mini cell to Landmine state
        if (!helper.CanAddLandmine)
            helper.CanAddLandmine = true;

        // Enable expand animation
        if (!EMAnimation.Instance ().IsExpanding)
            EMAnimation.Instance ().IsExpanding = true;

        // Reset transition availability
        transition.CanTransit = true;
        // Pause the transition for randomized time
        float fPauseTime = Random.Range ((m_EMFSM.CurrentAggressiveness / 1.5f) / EMDifficulty.Instance().CurrentDiff,
                                         (m_EMFSM.CurrentAggressiveness) / EMDifficulty.Instance().CurrentDiff);
        helper.StartPauseTransition (fPauseTime);
    }
Exemple #8
0
    public override void Enter()
    {
        transition = m_EMFSM.emTransition;
        controller = m_EMFSM.emController;
        helper     = m_EMFSM.emHelper;

        // Turn blink animation on
        EMAnimation.Instance().CanBlink = true;

        // Reset availability to command mini cell to Defend state
        if (!helper.CanAddDefend)
        {
            helper.CanAddDefend = true;
        }
        // Set status to defending
        controller.bIsDefend = true;

        // Reset transition availability
        transition.CanTransit = true;
        // Pause the transition for randomized time
        float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt((float)PlayerChildFSM.GetActiveChildCount() + 4f)) * 2f, Mathf.Sqrt((float)PlayerChildFSM.GetActiveChildCount() + 4f) * 2f);

        helper.StartPauseTransition(fPauseTime);
    }
Exemple #9
0
    public override void Execute()
    {
        transition = m_EMFSM.emTransition;
        controller = m_EMFSM.emController;
        helper     = m_EMFSM.emHelper;

        #region Command child cells to transit to Defend state only when there are more player mini cells than enemy mini cells
        if (m_EMFSM.AvailableChildNum < PlayerChildFSM.GetActiveChildCount() && helper.CanAddDefend)
        {
            float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
            float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

            // If there are more than 10 and less than 25 available enemy mini cells
            if (m_EMFSM.AvailableChildNum > 10 && m_EMFSM.AvailableChildNum <= 25 && helper.CanAddDefend)
            {
                for (int nAmount = 0; nAmount < Random.Range(5, 11); nAmount++)
                {
                    int nIndex = Random.Range(0, m_EMFSM.ECList.Count);
                    if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid)
                    {
                        MessageDispatcher.Instance.DispatchMessage(m_EMFSM.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Defend, 0.0);
                        helper.CanAddDefend = false;
                    }
                }

                if (helper.CanAddDefend)
                {
                    EMHelper.Instance().StartPauseAddDefend(0.25f);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 25 && m_EMFSM.AvailableChildNum <= 50 && helper.CanAddDefend)
            {
                for (int nAmount = 0; nAmount < Random.Range(3, 9); nAmount++)
                {
                    int nIndex = Random.Range(0, m_EMFSM.ECList.Count);
                    if (m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Idle || m_EMFSM.ECList[nIndex].CurrentStateEnum == ECState.Avoid)
                    {
                        MessageDispatcher.Instance.DispatchMessage(m_EMFSM.EnemyMainObject, m_EMFSM.ECList[nIndex].gameObject, MessageType.Defend, 0.0);
                        helper.CanAddDefend = false;
                    }
                }
            }

            // Pause commanding enemy mini cells to defend state
            helper.StartPauseTransition(2f);
        }
        #endregion

        //Start checking transition only when transition is allowed
        if (transition.CanTransit)
        {
            // Transit to other states only when there are more player mini cells than enemy mini cells
            if (m_EMFSM.AvailableChildNum >= PlayerChildFSM.GetActiveChildCount())
            {
                m_EMFSM.ChangeState(EMState.Production);
            }

            // If not transit to Production state, then transit to Maintain state
            m_EMFSM.ChangeState(EMState.Maintain);
        }

        // Check transition every 0.2 second to save computing power
        if (transition.CanTransit)
        {
            helper.StartPauseTransition(.2f);
        }
    }
Exemple #10
0
    public override void Execute()
    {
        transition = m_EMFSM.emTransition;
        controller = m_EMFSM.emController;
        helper     = m_EMFSM.emHelper;

        // Start checking transition only when there are more than 10 available enemy mini cells and transition is allowed
        if (m_EMFSM.AvailableChildNum > 10 && transition.CanTransit)
        {
            // If there are more than 10  and less than 25 available enemy mini cells
            if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15)
            {
                float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f)
                {
                    transition.Transition(1000f /
                                          (nPlayerChildFactor * 10f +
                                           EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                          EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f)
                {
                    transition.Transition(1000f /
                                          (helper.Pow(nEnemyChildFactor * 1f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.5f +
                                           EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                          EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor)
                {
                    transition.Transition(1000f /
                                          (helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2f +
                                           EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                          EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) +
                                                        m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                       EMState.Landmine);
                }

                // Transition to Production
                if (controller.NutrientNum > 0)
                {
                    transition.Transition(1000f /
                                          (helper.Pow(Mathf.Sqrt(controller.NutrientNum), 2f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.Production)),
                                          EMState.Production);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30)
            {
                float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f)
                {
                    transition.Transition(1000f /
                                          (nPlayerChildFactor * 10f +
                                           EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                          EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f)
                {
                    transition.Transition(1000f /
                                          ((helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.75f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                          EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor)
                {
                    transition.Transition(1000f /
                                          ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2.25f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                          EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) +
                                                        m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                       EMState.Landmine);
                }

                // Transition to Production
                if (controller.NutrientNum > 0)
                {
                    transition.Transition(1000f /
                                          (helper.Pow(Mathf.Sqrt(controller.NutrientNum), 2f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.Production)),
                                          EMState.Production);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 30)
            {
                float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f)
                {
                    transition.Transition(1000f /
                                          ((helper.Pow(nEnemyChildFactor * 1.75f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 4f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                          EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor)
                {
                    transition.Transition(1000f /
                                          ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 7.5f + m_EMFSM.CurrentAggressiveness * 2.5f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                          EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) +
                                                        m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                       EMState.Landmine);
                }

                // Transition to Production
                if (controller.NutrientNum > 0)
                {
                    transition.Transition(1000f /
                                          (helper.Pow(Mathf.Sqrt(controller.NutrientNum), 2f) +
                                           EMLeraningAgent.Instance().RealScore(EMState.Production)),
                                          EMState.Production);
                }
            }

            // Check transition every 0.1 second to save computing power
            if (transition.CanTransit)
            {
                helper.StartPauseTransition(.1f);
            }
        }
    }
Exemple #11
0
    public override void Execute()
    {
        controller = m_EMFSM.emController;
        helper     = m_EMFSM.emHelper;

        // Produce enemy mini cell if has nutrient and can spawn
        if (controller.NutrientNum > 0 && helper.CanSpawn && Level_Manager.LevelID < 4)
        {
            helper.ECPool.SpawnFromPool(EMHelper.Instance().Position, false);
        }
        else if (controller.NutrientNum > 0 && helper.CanSpawn && Level_Manager.LevelID > 3)
        {
            for (int i = 0; i < 2; i++)
            {
                helper.ECPool.SpawnFromPool(EMHelper.Instance().Position, false);
            }
        }
        else if (controller.NutrientNum == 0 && EMTransition.Instance().CanTransit)
        {
            m_EMFSM.ChangeState(EMState.Maintain);
        }

        // Start checking transition only when there are more than 10 available enemy mini cells, transition is allowed and has nutrient
        if (m_EMFSM.AvailableChildNum > 10 && EMTransition.Instance().CanTransit&& controller.NutrientNum > 0)
        {
            // If there are more than 10  and less than 25 available enemy mini cells
            if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15)
            {
                float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       (nPlayerChildFactor * 10f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                                       EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nEnemyChildFactor * 1f / nPlayerChildFactor, 2f) * 3f) + m_EMFSM.CurrentAggressiveness * 3.5f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                                       EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       (helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                                       EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) +
                                                        m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                       EMState.Landmine);
                }

                // Transition to Maintain
                if (nPlayerChildFactor <= 5f && helper.Abs((nEnemyChildFactor - nPlayerChildFactor)) <= 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       (helper.Pow(5f - helper.Pow(nEnemyChildFactor - nPlayerChildFactor, 1.5f), 2f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Maintain)),
                                                       EMState.Maintain);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30)
            {
                float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       (nPlayerChildFactor * 10f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                                       EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nEnemyChildFactor * 1.5f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.75f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                                       EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2.25f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                                       EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) +
                                                        m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                       EMState.Landmine);
                }

                // Transition to Maintain
                if (nPlayerChildFactor <= 5f && helper.Abs((nEnemyChildFactor - nPlayerChildFactor)) <= 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       (helper.Pow(5f - helper.Pow(nEnemyChildFactor - nPlayerChildFactor, 1.25f), 2f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Maintain)),
                                                       EMState.Maintain);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 30)
            {
                float nEnemyChildFactor  = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount() / 10f + 1f;

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nEnemyChildFactor * 1.75f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 4f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                                       EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nEnemyChildFactor * 2f / nPlayerChildFactor, 2f) * 7.5f + m_EMFSM.CurrentAggressiveness * 2.5f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                                       EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       ((helper.Pow(nPlayerChildFactor, 2f) / helper.Sqrt(nPlayerChildFactor) * 1f) +
                                                        m_EMFSM.CurrentAggressiveness * 2f +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                       EMState.Landmine);
                }

                // Transition to Maintain
                if (nPlayerChildFactor <= 5f && helper.Abs((nEnemyChildFactor - nPlayerChildFactor)) <= 1f)
                {
                    EMTransition.Instance().Transition(1000f /
                                                       (helper.Pow(5f - helper.Pow(nEnemyChildFactor - nPlayerChildFactor, 1f), 2f) +
                                                        EMLeraningAgent.Instance().RealScore(EMState.Maintain)),
                                                       EMState.Maintain);
                }
            }

            // Check transition every 0.2 to 0.4 second to save computing power
            // With the value given by learning element increases, the transition check will be less frequent
            // Thus transition probability will decline
            if (EMTransition.Instance().CanTransit)
            {
                helper.StartPauseTransition(.2f * (1f + EnemyMainFSM.Instance().LearningDictionary[EMState.Production] / 100f));
            }
        }
    }
    public override void Execute()
    {
        transition = m_EMFSM.emTransition;
        controller = m_EMFSM.emController;
        helper = m_EMFSM.emHelper;

        // Start checking transition only when there are more than 10 available enemy mini cells and transition is allowed
        if (m_EMFSM.AvailableChildNum > 10 && transition.CanTransit)
        {
            // If there are more than 10  and less than 25 available enemy mini cells
            if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15)
            {
                float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount () / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f) {
                    transition.Transition (1000f /
                                           (nPlayerChildFactor * 10f +
                     EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                           EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) {
                    transition.Transition (1000f /
                                           (helper.Pow (nEnemyChildFactor*1f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.5f +
                     EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                           EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor) {
                    transition.Transition (1000f /
                                           (helper.Pow (nEnemyChildFactor*1.5f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                           EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1.5f) {
                    EMTransition.Instance().Transition (1000f /
                                                        ((helper.Pow (nPlayerChildFactor, 2f) / helper.Sqrt (nPlayerChildFactor) * 1f) +
                     m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                        EMState.Landmine);
                }

                // Transition to Production
                if (controller.NutrientNum > 0) {
                    transition.Transition (1000f /
                                           (helper.Pow (Mathf.Sqrt(controller.NutrientNum), 2f) +
                     EMLeraningAgent.Instance().RealScore(EMState.Production)),
                                           EMState.Production);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30)
            {
                float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount () / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f) {
                    transition.Transition (1000f /
                                           (nPlayerChildFactor * 10f +
                     EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                           EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) {
                    transition.Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*1.5f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.75f) +
                     EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                           EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor) {
                    transition.Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*2f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2.25f) +
                     EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                           EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f) {
                    EMTransition.Instance().Transition (1000f /
                                                        ((helper.Pow (nPlayerChildFactor, 2f) / helper.Sqrt (nPlayerChildFactor) * 1f) +
                     m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                        EMState.Landmine);
                }

                // Transition to Production
                if (controller.NutrientNum > 0) {
                    transition.Transition (1000f /
                                           (helper.Pow (Mathf.Sqrt(controller.NutrientNum), 2f) +
                     EMLeraningAgent.Instance().RealScore(EMState.Production)),
                                           EMState.Production);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 30)
            {
                float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount () / 10f + 1f;

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) {
                    transition.Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*1.75f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 4f) +
                     EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                           EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor) {
                    transition.Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*2f / nPlayerChildFactor, 2f) * 7.5f + m_EMFSM.CurrentAggressiveness * 2.5f) +
                     EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                           EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f) {
                    EMTransition.Instance().Transition (1000f /
                                                        ((helper.Pow (nPlayerChildFactor, 2f) / helper.Sqrt (nPlayerChildFactor) * 1f) +
                     m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                        EMState.Landmine);
                }

                // Transition to Production
                if (controller.NutrientNum > 0) {
                    transition.Transition (1000f /
                                           (helper.Pow (Mathf.Sqrt(controller.NutrientNum), 2f) +
                     EMLeraningAgent.Instance().RealScore(EMState.Production)),
                                           EMState.Production);
                }
            }

            // Check transition every 0.1 second to save computing power
            if (transition.CanTransit)
                helper.StartPauseTransition (.1f);
        }
    }
    public override void Execute()
    {
        controller = m_EMFSM.emController;
        helper = m_EMFSM.emHelper;

        // Produce enemy mini cell if has nutrient and can spawn
        if (controller.NutrientNum > 0 && helper.CanSpawn && Level_Manager.LevelID < 4)
            helper.ECPool.SpawnFromPool (EMHelper.Instance ().Position, false);
        else if (controller.NutrientNum > 0 && helper.CanSpawn && Level_Manager.LevelID > 3)
        {
            for (int i = 0; i < 2; i++)
                helper.ECPool.SpawnFromPool (EMHelper.Instance ().Position, false);
        }
        else if (controller.NutrientNum == 0 && EMTransition.Instance().CanTransit)
            m_EMFSM.ChangeState (EMState.Maintain);

        // Start checking transition only when there are more than 10 available enemy mini cells, transition is allowed and has nutrient
        if (m_EMFSM.AvailableChildNum > 10 && EMTransition.Instance().CanTransit && controller.NutrientNum > 0)
        {
            // If there are more than 10  and less than 25 available enemy mini cells
            if (m_EMFSM.AvailableChildNum > 0 && m_EMFSM.AvailableChildNum <= 15)
            {
                float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount () / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f) {
                    EMTransition.Instance().Transition (1000f /
                                                        (nPlayerChildFactor * 10f +
                     EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                           EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) {
                    EMTransition.Instance().Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*1f / nPlayerChildFactor, 2f) * 3f) + m_EMFSM.CurrentAggressiveness * 3.5f +
                     EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                           EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor) {
                    EMTransition.Instance().Transition (1000f /
                                           (helper.Pow (nEnemyChildFactor*1.5f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                           EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1.5f) {
                    EMTransition.Instance().Transition (1000f /
                                                        ((helper.Pow (nPlayerChildFactor, 2f) / helper.Sqrt (nPlayerChildFactor) * 1f) +
                     m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                        EMState.Landmine);
                }

                // Transition to Maintain
                if (nPlayerChildFactor <= 5f && helper.Abs ((nEnemyChildFactor - nPlayerChildFactor)) <= 1f) {
                    EMTransition.Instance().Transition (1000f /
                                           (helper.Pow (5f - helper.Pow (nEnemyChildFactor - nPlayerChildFactor, 1.5f), 2f) +
                     EMLeraningAgent.Instance().RealScore(EMState.Maintain)),
                                           EMState.Maintain);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 15 && m_EMFSM.AvailableChildNum <= 30)
            {
                float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount () / 10f + 1f;

                // Transition to Defend
                if (EMHelper.Instance().MinToMaxYRatio > 0.5f) {
                    EMTransition.Instance().Transition (1000f /
                                                        (nPlayerChildFactor * 10f +
                     EMLeraningAgent.Instance().RealScore(EMState.Defend)) * (1f + EMHelper.Instance().MinToMaxYRatio),
                                           EMState.Defend);
                }

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) {
                    EMTransition.Instance().Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*1.5f / nPlayerChildFactor, 2f) * 3f + m_EMFSM.CurrentAggressiveness * 3.75f) +
                     EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                           EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor) {
                    EMTransition.Instance().Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*2f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 2.25f) +
                     EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                           EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f) {
                    EMTransition.Instance().Transition (1000f /
                                                        ((helper.Pow (nPlayerChildFactor, 2f) / helper.Sqrt (nPlayerChildFactor) * 1f) +
                     m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                        EMState.Landmine);
                }

                // Transition to Maintain
                if (nPlayerChildFactor <= 5f && helper.Abs ((nEnemyChildFactor - nPlayerChildFactor)) <= 1f) {
                    EMTransition.Instance().Transition (1000f /
                                           (helper.Pow (5f - helper.Pow (nEnemyChildFactor - nPlayerChildFactor, 1.25f), 2f) +
                     EMLeraningAgent.Instance().RealScore(EMState.Maintain)),
                                           EMState.Maintain);
                }
            }
            else if (m_EMFSM.AvailableChildNum > 30)
            {
                float nEnemyChildFactor = (float)m_EMFSM.AvailableChildNum / 10f + 1f;
                float nPlayerChildFactor = (float)PlayerChildFSM.GetActiveChildCount () / 10f + 1f;

                // Transition to EMAggressiveAttack
                if (nEnemyChildFactor > nPlayerChildFactor * 1.5f) {
                    EMTransition.Instance().Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*1.75f / nPlayerChildFactor, 2f) * 5f + m_EMFSM.CurrentAggressiveness * 4f) +
                     EMLeraningAgent.Instance().RealScore(EMState.AggressiveAttack)),
                                           EMState.AggressiveAttack);
                }

                // Transition to EMCautiousAttack
                if (nEnemyChildFactor > nPlayerChildFactor) {
                    EMTransition.Instance().Transition (1000f /
                                           ((helper.Pow (nEnemyChildFactor*2f / nPlayerChildFactor, 2f) * 7.5f + m_EMFSM.CurrentAggressiveness * 2.5f) +
                     EMLeraningAgent.Instance().RealScore(EMState.CautiousAttack)),
                                           EMState.CautiousAttack);
                }

                // Transition to Landmine
                if (nPlayerChildFactor > 1f) {
                    EMTransition.Instance().Transition (1000f /
                                                        ((helper.Pow (nPlayerChildFactor, 2f) / helper.Sqrt (nPlayerChildFactor) * 1f) +
                     m_EMFSM.CurrentAggressiveness * 2f +
                     EMLeraningAgent.Instance().RealScore(EMState.Landmine)),
                                                        EMState.Landmine);
                }

                // Transition to Maintain
                if (nPlayerChildFactor <= 5f && helper.Abs ((nEnemyChildFactor - nPlayerChildFactor)) <= 1f) {
                    EMTransition.Instance().Transition (1000f /
                                           (helper.Pow (5f - helper.Pow (nEnemyChildFactor - nPlayerChildFactor, 1f), 2f) +
                     EMLeraningAgent.Instance().RealScore(EMState.Maintain)),
                                           EMState.Maintain);
                }
            }

            // Check transition every 0.2 to 0.4 second to save computing power
            // With the value given by learning element increases, the transition check will be less frequent
            // Thus transition probability will decline
            if (EMTransition.Instance().CanTransit)
                helper.StartPauseTransition (.2f * (1f + EnemyMainFSM.Instance().LearningDictionary[EMState.Production] / 100f));
        }
    }