// Critic Tells the learning element how well the agent is doing with respect to a fixed performance measure
    private void Critic()
    {
        EMState currentStateEnum     = m_EMFSM.CurrentStateIndex;
        int     nCurrentEnemyChild   = m_EMFSM.AvailableChildNum;
        int     nCurrentPlayerChild  = PlayerChildFSM.GetActiveChildCount();
        int     nCurrentSquadChild   = 0;
        bool    bSquadCaptainIsAlive = false;

        if (PlayerSquadFSM.Instance != null)
        {
            nCurrentSquadChild   = PlayerSquadFSM.Instance.AliveChildCount();
            bSquadCaptainIsAlive = PlayerSquadFSM.Instance.IsAlive;
        }
        int nCurrentEnemyHealth  = m_EMFSM.Health;
        int nCurrentPlayerHealth = 0;

        if (PlayerMain.Instance != null)
        {
            nCurrentPlayerHealth = PlayerMain.Instance.Health;
        }
        // Pause calling the function for checking and wait for the result
        fCheckFreq = Random.Range(0.25f, .5f);
        StartCoroutine(PauseCheck(fCheckFreq, currentStateEnum, nCurrentEnemyChild, nCurrentPlayerChild, nCurrentSquadChild, bSquadCaptainIsAlive,
                                  nCurrentEnemyHealth, nCurrentPlayerHealth));
    }
 float ScoreCompressor(EMState state, float score)
 {
     if (EnemyMainFSM.Instance().LearningDictionary [state] > 0f)
     {
         return(score / Mathf.Sqrt(Mathf.Sqrt(Mathf.Abs(EnemyMainFSM.Instance().LearningDictionary [state]))));
     }
     else
     {
         return(score);
     }
 }
    /// <summary>
    /// Universal function for pausing transition availability
    /// <param name="fTIme">Used to indicate pause time.</param>
    /// </summary>
    public IEnumerator TransitionAvailability(float fTime)
    {
        EMState currentStateIndex = m_EMFSM.CurrentStateIndex;

        bCanTransit = false;
        yield return(new WaitForSeconds(fTime));

        // Reset transition availability only when it is still in the state which the call is from
        if (currentStateIndex == m_EMFSM.CurrentStateIndex)
        {
            bCanTransit = true;
        }
    }
Example #4
0
        public int InsUpdState(EMState objState)
        {
            Hashtable htparams = new Hashtable
            {
                { "@Id", objState.Id },
                { "@StateKey", objState.Key },
                { "@Name", objState.Name },
                { "@Country_id", objState.Country },
                { "@CreatedBy", objState.CreatedBy }
            };
            int IsSuccess = ExecuteNonQuery("StatesMaster_InsertUpdate", htparams);

            return(IsSuccess);
        }
Example #5
0
    // Change current state, perform exit and enter functions
    public void ChangeState(EMState newState)
    {
        // Make sure the state we are transitioning to is not the current state
        if (newState != CurrentStateIndex)
        {
            if (m_CurrentState != null)
            {
                m_CurrentState.Exit();
            }

            m_currentStateIndex = newState;
            m_CurrentState      = m_statesDictionary [newState];
            m_CurrentState.Enter();
        }
    }
    // Check only once within a given perio of time
    IEnumerator PauseCheck(float checkFreq, EMState pastState, int pastEnemyChild, int pastPlayerChild, int pastSquadChild, bool squadCaptainWasAlive,
                           int pastEnemyHealth, int pastPlayerHealth)
    {
        bCanStartCheck = false;                 // One check at a time
        yield return(new WaitForSeconds(checkFreq));

        // If we are still in the same state then proceed
        if (EMLeraningAgent.instance != null && PlayerChildFSM.playerChildPool != null && PlayerSquadFSM.Instance != null)
        {
            if (pastState == m_EMFSM.CurrentStateIndex)
            {
                LearningElement(pastState, pastEnemyChild, m_EMFSM.AvailableChildNum, pastPlayerChild, PlayerChildFSM.GetActiveChildCount(),
                                pastSquadChild, PlayerSquadFSM.Instance.AliveChildCount(), squadCaptainWasAlive, PlayerSquadFSM.Instance.IsAlive,
                                pastEnemyHealth, pastPlayerHealth);
            }
        }

        bCanStartCheck = true;                  //Reset the checking availability
    }
    /// <summary>
    /// Universal transition probability checking function
    /// <param name="nChanceFactor">Equal to one tenth of the persentage.</param>
    /// <param name="state">State trying to transition to.</param>
    /// <param name="fExtraChanceFactor">Extra chance if any (1.0f by default).</param>
    /// </summary>
    public bool Transition(float nChanceFactor, EMState state, float fExtraChanceFactor)
    {
        float nChance = 0f;

        if (nChanceFactor * fExtraChanceFactor <= 10f)
        {
            m_EMFSM.ChangeState (state);
            return true;
        }
        else
        {
            nChance = Random.Range (0f, nChanceFactor);
            if (nChance <= 1f)
                m_EMFSM.ChangeState (state);
            return true;
        }

        return false;
    }
    /// <summary>
    /// Universal transition probability checking function
    /// <param name="nChanceFactor">Equal to one tenth of the persentage.</param>
    /// <param name="state">State trying to transition to.</param>
    /// <param name="fExtraChanceFactor">Extra chance if any (1.0f by default).</param>
    /// </summary>
    public bool Transition(float nChanceFactor, EMState state, float fExtraChanceFactor)
    {
        float nChance = 0f;

        if (nChanceFactor * fExtraChanceFactor <= 10f)
        {
            m_EMFSM.ChangeState(state);
            return(true);
        }
        else
        {
            nChance = Random.Range(0f, nChanceFactor);
            if (nChance <= 1f)
            {
                m_EMFSM.ChangeState(state);
            }
            return(true);
        }

        return(false);
    }
 float ScoreCompressor(EMState state, float score)
 {
     if (EnemyMainFSM.Instance ().LearningDictionary [state] > 0f) {
         return score / Mathf.Sqrt (Mathf.Sqrt (Mathf.Abs(EnemyMainFSM.Instance ().LearningDictionary [state])));
     }
     else
         return score;
 }
Example #10
0
    void Start()
    {
        enemyMainObject = this.gameObject;
        #region Initialize state dictionary
        m_statesDictionary = new Dictionary <EMState, IEMState>();
        m_statesDictionary.Add(EMState.Production, new EMProductionState(this));
        m_statesDictionary.Add(EMState.Maintain, new EMMaintainState(this));
        m_statesDictionary.Add(EMState.Defend, new EMDefendState(this));
        m_statesDictionary.Add(EMState.AggressiveAttack, new EMAggressiveAttackState(this));
        m_statesDictionary.Add(EMState.CautiousAttack, new EMCautiousAttackState(this));
        m_statesDictionary.Add(EMState.Landmine, new EMLandmineState(this));
        m_statesDictionary.Add(EMState.Stunned, new EMStunnedState(this));
        m_statesDictionary.Add(EMState.Die, new EMDieState(this));
        m_statesDictionary.Add(EMState.Win, new EMWinState(this));
        #endregion

        #region Initialize the Learning Element dictionary
        m_learningDictionary = new Dictionary <EMState, float>();
        m_learningDictionary.Add(EMState.Production, 0f);
        m_learningDictionary.Add(EMState.Maintain, 0f);
        m_learningDictionary.Add(EMState.Defend, 0f);
        m_learningDictionary.Add(EMState.AggressiveAttack, 0f);
        m_learningDictionary.Add(EMState.CautiousAttack, 0f);
        m_learningDictionary.Add(EMState.Landmine, 0f);
        m_learningDictionary.Add(EMState.Stunned, 0f);
        m_learningDictionary.Add(EMState.Die, 0f);
        m_learningDictionary.Add(EMState.Win, 0f);
        #endregion

        // Initialize the default to Production
        m_CurrentState      = m_statesDictionary [EMState.Production];
        m_currentStateIndex = EMState.Production;

        // Get the enemy main controller, helper class and transition class
        emController = GetComponent <EMController> ();
        emHelper     = GetComponent <EMHelper> ();
        emTransition = GetComponent <EMTransition> ();

        //Initialize and refresh the point database for Enemy Child Cells
        PointDatabase.Instance.InitializeDatabase();
        PointDatabase.Instance.RefreshDatabase();
        FormationDatabase.Instance.RefreshDatabases(ECList);

        // Initialise the enemy child list

        /*
         *      EnemyChildFSM[] ecClasses = (EnemyChildFSM[])GameObject.FindObjectsOfType (typeof(EnemyChildFSM));
         *      foreach (EnemyChildFSM ecClass in ecClasses)
         *      {
         *              if (ecClass.CurrentStateEnum != ECState.Dead)
         *                      ecList.Add (ecClass);
         *      }
         */
        // ecList = GameObject.FindGameObjectsWithTag("EnemyChild").Select(gameObject => gameObject.GetComponent<EnemyChildFSM>()).ToList();
        // Count the number of child cells in list

        /*
         * for (int i = 0; i < ecList.Count; i++) {
         *      if(ecList[i].CurrentStateEnum != ECState.Dead)
         *              nAvailableChildNum++;
         * }
         */
    }
Example #11
0
 public void SetLearningScore(EMState key, float value)
 {
     m_learningDictionary [key] = value;
 }
Example #12
0
    void Start()
    {
        enemyMainObject = this.gameObject;
        #region Initialize state dictionary
        m_statesDictionary = new Dictionary<EMState, IEMState>();
        m_statesDictionary.Add (EMState.Production, new EMProductionState (this));
        m_statesDictionary.Add (EMState.Maintain, new EMMaintainState (this));
        m_statesDictionary.Add (EMState.Defend, new EMDefendState (this));
        m_statesDictionary.Add (EMState.AggressiveAttack, new EMAggressiveAttackState (this));
        m_statesDictionary.Add (EMState.CautiousAttack, new EMCautiousAttackState (this));
        m_statesDictionary.Add (EMState.Landmine, new EMLandmineState (this));
        m_statesDictionary.Add (EMState.Stunned, new EMStunnedState (this));
        m_statesDictionary.Add (EMState.Die, new EMDieState (this));
        m_statesDictionary.Add (EMState.Win, new EMWinState (this));
        #endregion

        #region Initialize the Learning Element dictionary
        m_learningDictionary = new Dictionary<EMState, float>();
        m_learningDictionary.Add (EMState.Production, 0f);
        m_learningDictionary.Add (EMState.Maintain, 0f);
        m_learningDictionary.Add (EMState.Defend, 0f);
        m_learningDictionary.Add (EMState.AggressiveAttack, 0f);
        m_learningDictionary.Add (EMState.CautiousAttack, 0f);
        m_learningDictionary.Add (EMState.Landmine, 0f);
        m_learningDictionary.Add (EMState.Stunned, 0f);
        m_learningDictionary.Add (EMState.Die, 0f);
        m_learningDictionary.Add (EMState.Win, 0f);
        #endregion

        // Initialize the default to Production
        m_CurrentState = m_statesDictionary [EMState.Production];
        m_currentStateIndex = EMState.Production;

        // Get the enemy main controller, helper class and transition class
        emController = GetComponent<EMController> ();
        emHelper = GetComponent<EMHelper> ();
        emTransition = GetComponent<EMTransition> ();

        //Initialize and refresh the point database for Enemy Child Cells
        PointDatabase.Instance.InitializeDatabase();
        PointDatabase.Instance.RefreshDatabase();
        FormationDatabase.Instance.RefreshDatabases(ECList);

        // Initialise the enemy child list
        /*
        EnemyChildFSM[] ecClasses = (EnemyChildFSM[])GameObject.FindObjectsOfType (typeof(EnemyChildFSM));
        foreach (EnemyChildFSM ecClass in ecClasses)
        {
            if (ecClass.CurrentStateEnum != ECState.Dead)
                ecList.Add (ecClass);
        }
        */
        // ecList = GameObject.FindGameObjectsWithTag("EnemyChild").Select(gameObject => gameObject.GetComponent<EnemyChildFSM>()).ToList();
        // Count the number of child cells in list
        /*
        for (int i = 0; i < ecList.Count; i++) {
            if(ecList[i].CurrentStateEnum != ECState.Dead)
                nAvailableChildNum++;
        }
        */
    }
Example #13
0
 public void SetLearningScore(EMState key, float value)
 {
     m_learningDictionary [key] = value;
 }
Example #14
0
    // Change current state, perform exit and enter functions
    public void ChangeState(EMState newState)
    {
        // Make sure the state we are transitioning to is not the current state
        if (newState != CurrentStateIndex)
        {
            if (m_CurrentState != null)
                m_CurrentState.Exit ();

            m_currentStateIndex = newState;
            m_CurrentState = m_statesDictionary [newState];
            m_CurrentState.Enter ();
        }
    }
    // Learning Element: Correspond with the FSM to make improvements
    private void LearningElement(EMState state, int pastEnemyChild, int currentEnemyChild, int pastPlayerChild, int currentPlayerChild, 
	                              int pastSquadChild, int currentSquadChild, bool squadCaptainWasAlive, bool squadCaptainIsAlive, 
	                              int pastEnemyHealth, int pastPlayerHealth)
    {
        #region General transition probability change
        // Initialize the overall score
        float fOverallScore = 0f;
        // Reward for increment of the number of enemy child cells, vice versa
        // The less aggressive the enemy is, the more it wants to increase the number of its child cells
        fOverallScore += Random.Range (((float)(currentEnemyChild - pastEnemyChild) * Mathf.Pow (3f, 2f) / m_EMFSM.CurrentAggressiveness) * 1.25f,
                                       ((float)(currentEnemyChild - pastEnemyChild) * Mathf.Pow (3f, 2f) / m_EMFSM.CurrentAggressiveness) * .75f);
        // Reward for player child cells killed, vice versa
        if (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * .5f) <
            ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * 1f))
            fOverallScore += Random.Range (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f,
                                           ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * 1f);
        else
            fOverallScore += Random.Range (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * 1f,
                                           ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f);
        // Penalty for increment of the number of player squad child cells, vice versa
        // (float)(currentSquadChild - pastSquadChild) * m_EMFSM.InitialAggressiveness
        fOverallScore -= Random.Range (((float)(currentSquadChild - pastSquadChild) * m_EMFSM.CurrentAggressiveness) * .5f,
                                       ((float)(currentSquadChild - pastSquadChild) * m_EMFSM.CurrentAggressiveness) * 1f);
        // Reward for killing the player squad captain based on enemy initial aggressiveness
        if (squadCaptainWasAlive && !squadCaptainIsAlive) {
            fOverallScore += Random.Range (m_EMFSM.CurrentAggressiveness, m_EMFSM.CurrentAggressiveness * 2f);
        }
        // Penalty for loss of health of the enemy main cell
        if (pastEnemyHealth > m_EMFSM.Health) {
            fOverallScore -= Random.Range ((float)(pastEnemyHealth - m_EMFSM.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness),
                                           (float)(pastEnemyHealth - m_EMFSM.Health) * m_EMFSM.CurrentAggressiveness);
        }

        #endregion
        #region Peculiar transition probability changes
        // Production state
        if (state == EMState.Production)
        {
            fOverallScore += Random.Range (((float)(currentEnemyChild - pastEnemyChild) / m_EMFSM.CurrentAggressiveness) * 15f,
                                           ((float)(currentEnemyChild - pastEnemyChild) / m_EMFSM.CurrentAggressiveness) * 30f);
        }
        // Defned state
        if (state == EMState.Defend && Mathf.Abs(pastEnemyChild - currentEnemyChild) != 0)
        {
            fOverallScore += (Mathf.Sqrt(10f) / m_EMFSM.CurrentAggressiveness) / (Mathf.Abs(pastEnemyChild - currentEnemyChild));
        }
        // AggressiveAttack, CautiousAttack and Landmine state
        if (state == EMState.AggressiveAttack || state == EMState.CautiousAttack || state == EMState.Landmine)
        {
            // Reward for player child cells killed, vice versa
            if (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * .25f) <
                ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * .5f))
                fOverallScore += Random.Range (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .25f,
                                               ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f);
            else
                fOverallScore += Random.Range (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f,
                                               ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .25f);
            // Reward for squad child cells killed, vice versa
            if (((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness * 1.5f) <
                ((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness * 3f))
                fOverallScore += Random.Range (((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 1.5f,
                                               ((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 3f);
            else
                fOverallScore += Random.Range (((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 3f,
                                               ((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 1.5f);

            // Penalty for loss of health of the enemy main cell
            if (pastEnemyHealth > m_EMFSM.Health) {
                if (((pastEnemyHealth - m_EMFSM.Health) * 3f / Mathf.Sqrt(m_EMFSM.CurrentAggressiveness)) <
                    (pastEnemyHealth - m_EMFSM.Health))
                    fOverallScore -= Random.Range ((pastEnemyHealth - m_EMFSM.Health) * 3f / Mathf.Sqrt(m_EMFSM.CurrentAggressiveness),
                                                   (pastEnemyHealth - m_EMFSM.Health));
                else
                    fOverallScore -= Random.Range ((pastEnemyHealth - m_EMFSM.Health),
                                                   (pastEnemyHealth - m_EMFSM.Health) * 3f / Mathf.Sqrt(m_EMFSM.CurrentAggressiveness));
            }

            // Reward for loss of health of the player main cell
            if (((pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness)) * 4f <
                (pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 8f)
            {
                fOverallScore += Random.Range ((pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 4f,
                                               (pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 8f);
            }
            else
                fOverallScore += Random.Range ((pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 8f,
                                               (pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 4f);
        }
        // Landmine state
        if (state == EMState.Landmine)
        {
            fOverallScore += Mathf.Sqrt ((float)currentEnemyChild);
            fOverallScore += Random.Range (Mathf.Sqrt ((float)currentPlayerChild) * m_EMFSM.InitialAggressiveness / 5f,
                                           Mathf.Sqrt ((float)currentPlayerChild) * m_EMFSM.InitialAggressiveness / 2.5f);
        }
        // Main state
        if (fOverallScore < 0f && state == EMState.Maintain)
        {
            EnemyMainFSM.Instance().LearningDictionary[EMState.Maintain] += Mathf.Sqrt(Mathf.Abs (fOverallScore) * 2f);
        }
        #endregion

        fOverallScore = ScoreCompressor (state, fOverallScore);
        EnemyMainFSM.Instance ().LearningDictionary [state] += fOverallScore;
    }
 public float OriginalScore(EMState state)
 {
     return(EnemyMainFSM.Instance().LearningDictionary[state]);
 }
    // Check only once within a given perio of time
    IEnumerator PauseCheck(float checkFreq, EMState pastState,int pastEnemyChild, int pastPlayerChild, int pastSquadChild, bool squadCaptainWasAlive, 
	                        int pastEnemyHealth, int pastPlayerHealth)
    {
        bCanStartCheck = false;		// One check at a time
        yield return new WaitForSeconds (checkFreq);

        // If we are still in the same state then proceed
        if (EMLeraningAgent.instance != null && PlayerChildFSM.playerChildPool != null && PlayerSquadFSM.Instance != null)
        {
            if (pastState == m_EMFSM.CurrentStateIndex)
                LearningElement (pastState, pastEnemyChild, m_EMFSM.AvailableChildNum, pastPlayerChild, PlayerChildFSM.GetActiveChildCount(),
                                 pastSquadChild, PlayerSquadFSM.Instance.AliveChildCount (), squadCaptainWasAlive, PlayerSquadFSM.Instance.IsAlive,
                                 pastEnemyHealth, pastPlayerHealth);
        }

        bCanStartCheck = true;		//Reset the checking availability
    }
Example #18
0
 /// <summary>
 /// Constructor of Transition function
 /// </summary>
 public bool Transition(float nChanceFactor, EMState state)
 {
     return Transition (nChanceFactor, state, 1.0f);
 }
    // Learning Element: Correspond with the FSM to make improvements
    private void LearningElement(EMState state, int pastEnemyChild, int currentEnemyChild, int pastPlayerChild, int currentPlayerChild,
                                 int pastSquadChild, int currentSquadChild, bool squadCaptainWasAlive, bool squadCaptainIsAlive,
                                 int pastEnemyHealth, int pastPlayerHealth)
    {
        #region General transition probability change
        // Initialize the overall score
        float fOverallScore = 0f;
        // Reward for increment of the number of enemy child cells, vice versa
        // The less aggressive the enemy is, the more it wants to increase the number of its child cells
        fOverallScore += Random.Range(((float)(currentEnemyChild - pastEnemyChild) * Mathf.Pow(3f, 2f) / m_EMFSM.CurrentAggressiveness) * 1.25f,
                                      ((float)(currentEnemyChild - pastEnemyChild) * Mathf.Pow(3f, 2f) / m_EMFSM.CurrentAggressiveness) * .75f);
        // Reward for player child cells killed, vice versa
        if (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * .5f) <
            ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * 1f))
        {
            fOverallScore += Random.Range(((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f,
                                          ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * 1f);
        }
        else
        {
            fOverallScore += Random.Range(((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * 1f,
                                          ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f);
        }
        // Penalty for increment of the number of player squad child cells, vice versa
        // (float)(currentSquadChild - pastSquadChild) * m_EMFSM.InitialAggressiveness
        fOverallScore -= Random.Range(((float)(currentSquadChild - pastSquadChild) * m_EMFSM.CurrentAggressiveness) * .5f,
                                      ((float)(currentSquadChild - pastSquadChild) * m_EMFSM.CurrentAggressiveness) * 1f);
        // Reward for killing the player squad captain based on enemy initial aggressiveness
        if (squadCaptainWasAlive && !squadCaptainIsAlive)
        {
            fOverallScore += Random.Range(m_EMFSM.CurrentAggressiveness, m_EMFSM.CurrentAggressiveness * 2f);
        }
        // Penalty for loss of health of the enemy main cell
        if (pastEnemyHealth > m_EMFSM.Health)
        {
            fOverallScore -= Random.Range((float)(pastEnemyHealth - m_EMFSM.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness),
                                          (float)(pastEnemyHealth - m_EMFSM.Health) * m_EMFSM.CurrentAggressiveness);
        }

        #endregion
        #region Peculiar transition probability changes
        // Production state
        if (state == EMState.Production)
        {
            fOverallScore += Random.Range(((float)(currentEnemyChild - pastEnemyChild) / m_EMFSM.CurrentAggressiveness) * 15f,
                                          ((float)(currentEnemyChild - pastEnemyChild) / m_EMFSM.CurrentAggressiveness) * 30f);
        }
        // Defned state
        if (state == EMState.Defend && Mathf.Abs(pastEnemyChild - currentEnemyChild) != 0)
        {
            fOverallScore += (Mathf.Sqrt(10f) / m_EMFSM.CurrentAggressiveness) / (Mathf.Abs(pastEnemyChild - currentEnemyChild));
        }
        // AggressiveAttack, CautiousAttack and Landmine state
        if (state == EMState.AggressiveAttack || state == EMState.CautiousAttack || state == EMState.Landmine)
        {
            // Reward for player child cells killed, vice versa
            if (((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * .25f) <
                ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness * .5f))
            {
                fOverallScore += Random.Range(((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .25f,
                                              ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f);
            }
            else
            {
                fOverallScore += Random.Range(((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .5f,
                                              ((float)(pastPlayerChild - currentPlayerChild) * m_EMFSM.CurrentAggressiveness) * .25f);
            }
            // Reward for squad child cells killed, vice versa
            if (((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness * 1.5f) <
                ((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness * 3f))
            {
                fOverallScore += Random.Range(((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 1.5f,
                                              ((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 3f);
            }
            else
            {
                fOverallScore += Random.Range(((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 3f,
                                              ((float)(pastSquadChild - currentSquadChild) * m_EMFSM.CurrentAggressiveness) * 1.5f);
            }

            // Penalty for loss of health of the enemy main cell
            if (pastEnemyHealth > m_EMFSM.Health)
            {
                if (((pastEnemyHealth - m_EMFSM.Health) * 3f / Mathf.Sqrt(m_EMFSM.CurrentAggressiveness)) <
                    (pastEnemyHealth - m_EMFSM.Health))
                {
                    fOverallScore -= Random.Range((pastEnemyHealth - m_EMFSM.Health) * 3f / Mathf.Sqrt(m_EMFSM.CurrentAggressiveness),
                                                  (pastEnemyHealth - m_EMFSM.Health));
                }
                else
                {
                    fOverallScore -= Random.Range((pastEnemyHealth - m_EMFSM.Health),
                                                  (pastEnemyHealth - m_EMFSM.Health) * 3f / Mathf.Sqrt(m_EMFSM.CurrentAggressiveness));
                }
            }

            // Reward for loss of health of the player main cell
            if (((pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness)) * 4f <
                (pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 8f)
            {
                fOverallScore += Random.Range((pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 4f,
                                              (pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 8f);
            }
            else
            {
                fOverallScore += Random.Range((pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 8f,
                                              (pastPlayerHealth - PlayerMain.Instance.Health) * Mathf.Sqrt(m_EMFSM.CurrentAggressiveness) * 4f);
            }
        }
        // Landmine state
        if (state == EMState.Landmine)
        {
            fOverallScore += Mathf.Sqrt((float)currentEnemyChild);
            fOverallScore += Random.Range(Mathf.Sqrt((float)currentPlayerChild) * m_EMFSM.InitialAggressiveness / 5f,
                                          Mathf.Sqrt((float)currentPlayerChild) * m_EMFSM.InitialAggressiveness / 2.5f);
        }
        // Main state
        if (fOverallScore < 0f && state == EMState.Maintain)
        {
            EnemyMainFSM.Instance().LearningDictionary[EMState.Maintain] += Mathf.Sqrt(Mathf.Abs(fOverallScore) * 2f);
        }
        #endregion

        fOverallScore = ScoreCompressor(state, fOverallScore);
        EnemyMainFSM.Instance().LearningDictionary[state] += fOverallScore;
    }
 public float RealScore(EMState state)
 {
     return(2f * Mathf.Sqrt(EnemyMainFSM.Instance().LearningDictionary[state]));
 }
Example #21
0
 /// <summary>
 /// Constructor of Transition function
 /// </summary>
 public bool Transition(float nChanceFactor, EMState state)
 {
     return(Transition(nChanceFactor, state, 1.0f));
 }
 public float OriginalScore(EMState state)
 {
     return EnemyMainFSM.Instance().LearningDictionary[state];
 }
 public float RealScore(EMState state)
 {
     return 2f * Mathf.Sqrt (EnemyMainFSM.Instance().LearningDictionary[state]);
 }
Example #24
0
 public int InsUpdState(EMState objState)
 {
     return(objDAState.InsUpdState(objState));
 }