/// A positive iThinkFact is added to the \a State, and a negative one is removed from it.
		public void applyFact( iThinkState State )
		{
			if ( this.positive == false )
				State.delFact( this );
			else
				State.addFact( this );
		}
Example #2
0
 /// A positive iThinkFact is added to the \a State, and a negative one is removed from it.
 public void applyFact(iThinkState State)
 {
     if (this.positive == false)
     {
         State.delFact(this);
     }
     else
     {
         State.addFact(this);
     }
 }
		/*!
		 * Returns a new iThinkState, based on \a State and applies the action's effects to it
		 * @param State The state to be effected
		 * @returns A new iThinkState
		 */
		public virtual iThinkState applyEffects( iThinkState State )
		{
			iThinkState NewState = new iThinkState( State );

			foreach ( iThinkFact effect in this.effects )
			{
				if (effect.getPositive())
					NewState.addFact(effect);
				else
					NewState.delFact(effect);
			}

			return NewState;
		}
        /*public int hFunction(iThinkState nextState, iThinkState GoalState, int area)
         * {
         *      return base.hFunction(nextState, GoalState);
         * }*/

        public int hFunction(iThinkState nextState, iThinkState GoalState, int area)
        {
            //Debug.LogError(area);
            iThinkState tempState = new iThinkState(GoalState);
            iThinkState curState  = new iThinkState(nextState);

            for (int i = 0; i < depth; i++)
            {
                List <int> areas = new List <int>();
                foreach (iThinkFact f in curState.getFactList())
                {
                    if (f.getName() == "npc-at")
                    {
                        string name = f.getObj(0).name;
                        int    a    = Convert.ToInt32(name.Substring(4));
                        areas.Add(a);
                    }

                    tempState.delFact(f);
                }

                if (tempState.getFactList().Count == 0)
                {
                    return(i);
                }

                ///List<iThinkAction> applicableActions = getApplicable(curState,  ((SimpleFPSActionManager)actionManager).getActions(-1) );
                ///List<iThinkAction> applicableActions = getApplicable(curState,  ((SimpleFPSActionManager)actionManager).getActions(area) );

                List <iThinkAction> allApplicableActions = new List <iThinkAction>();
                foreach (int k in areas)
                {
                    List <iThinkAction> applicableActions = getApplicable(curState, ((SimpleFPSActionManager)actionManager).getActions(k));
                    allApplicableActions.InsertRange(0, applicableActions);
                }

                iThinkPlan curStep = new iThinkPlan(curState);
                foreach (iThinkAction act in allApplicableActions)
                {
                    iThinkPlan nextStep = progressPositive(curStep, act);
                    //iThinkPlan nextStep = progress(curStep, act);
                    curStep = nextStep;
                }
                curState = curStep.getState();
            }
            //in case the planning graph has #layers = depth, return -1, indicating that no solution can be found starting from current state)
            //consequenlty, the state will not be added in the fringe.
            return(-1);
        }
Example #5
0
        /*!
         * Returns a new iThinkState, based on \a State and applies the action's effects to it
         * @param State The state to be effected
         * @returns A new iThinkState
         */
        public virtual iThinkState applyEffects(iThinkState State)
        {
            iThinkState NewState = new iThinkState(State);

            foreach (iThinkFact effect in this.effects)
            {
                if (effect.getPositive())
                {
                    NewState.addFact(effect);
                }
                else
                {
                    NewState.delFact(effect);
                }
            }

            return(NewState);
        }
		public int hFunction(iThinkState nextState, iThinkState GoalState, int area)
		{
			//Debug.LogError(area);
			iThinkState tempState = new iThinkState(GoalState);
			iThinkState curState = new iThinkState(nextState);
			for (int i=0 ; i<depth ; i++)
			{
				List<int> areas = new List<int>();
				foreach (iThinkFact f in curState.getFactList())
				{
					if (f.getName() == "npc-at")
					{
						string name = f.getObj(0).name;
						int a = Convert.ToInt32(name.Substring(4));
						areas.Add(a);
					}

					tempState.delFact(f);
				}

				if (tempState.getFactList().Count == 0)
					return i;
				
				///List<iThinkAction> applicableActions = getApplicable(curState,  ((SimpleFPSActionManager)actionManager).getActions(-1) );
				///List<iThinkAction> applicableActions = getApplicable(curState,  ((SimpleFPSActionManager)actionManager).getActions(area) );
				
				List<iThinkAction> allApplicableActions = new List<iThinkAction>();
				foreach (int k in areas)
				{
					List<iThinkAction> applicableActions = getApplicable(curState,  ((SimpleFPSActionManager)actionManager).getActions(k) );
					allApplicableActions.InsertRange(0, applicableActions);
				}
				
				iThinkPlan curStep = new iThinkPlan(curState);
				foreach (iThinkAction act in allApplicableActions)
				{
					iThinkPlan nextStep = progressPositive(curStep, act);
					//iThinkPlan nextStep = progress(curStep, act);
					curStep = nextStep;
				}
				curState = curStep.getState();
			}
			//in case the planning graph has #layers = depth, return -1, indicating that no solution can be found starting from current state)
			//consequenlty, the state will not be added in the fringe.
			return -1;
		}