コード例 #1
0
ファイル: Hero.cs プロジェクト: LucasBousselet/LogicalAgentAI
 /// <summary>
 /// Do the most appropriate action.
 /// </summary>
 /// <param name="p_paAction"> Action to do. </param>
 public void DoAction(PossibleAction p_paAction)
 {
     if (p_paAction != null)
     {
         p_paAction.Act();
     }
 }
コード例 #2
0
ファイル: Hero.cs プロジェクト: LucasBousselet/LogicalAgentAI
        /// <summary>
        /// Calculate worthitness of an action
        /// </summary>
        /// <param name="p_paAction"> Action. </param>
        /// <param name="p_sMyGoal"> Hero goal. </param>
        /// <param name="p_iStateEnv"> Environment state. </param>
        /// <returns></returns>
        private int CalculateWorthiness(PossibleAction p_paAction, string p_sMyGoal, int p_iStateEnv)
        {
            int iWorthiness = -1;

            /* Depending on the state of the environment and the goal, we logically attibute a number of point to each counter
             * This way, a particularly interesting action to perform will be set a high value of worthiness.
             */
            switch (p_iStateEnv)
            {
            // Empty cell.
            case 0:
                if (p_paAction.Name() == "Move")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockLeft")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockRight")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockTop")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockBottom")
                {
                    iWorthiness = 0;
                }
                break;

            // Cell with rad.
            case 1:
                if (p_paAction.Name() == "Move")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockLeft")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockRight")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockTop")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockBottom")
                {
                    iWorthiness = 1;
                }
                break;

            // Cell with Wind.
            case 2:
                if (p_paAction.Name() == "Move")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockLeft")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockRight")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockTop")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockBottom")
                {
                    iWorthiness = 0;
                }
                break;

            // Cell with wind + rad.
            case 3:
                if (p_paAction.Name() == "Move")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockLeft")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockRight")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockTop")
                {
                    iWorthiness = 1;
                }
                if (p_paAction.Name() == "ThrowRockBottom")
                {
                    iWorthiness = 1;
                }
                break;

            // Cell with light.
            case 4:
                if (p_paAction.Name() == "Move")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockLeft")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockRight")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockTop")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "ThrowRockBottom")
                {
                    iWorthiness = 0;
                }
                if (p_paAction.Name() == "Exit")
                {
                    iWorthiness = 1;
                }
                break;

            default:
                break;
            }

            // Then, we return the counter associated with the current goal of the agent.
            int iResult = -1;

            if (p_sMyGoal == "GETOUTOMG!")
            {
                iResult = iWorthiness;
            }
            return(iResult);
        }