Ejemplo n.º 1
0
        public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
        {
            //Debug.LogWarning(GoalState.ToString());
            //Debug.LogWarning(ActionManager.getActions().Count);
            //Debug.LogWarning(OpenStates.Count);
            //Debug.LogWarning(VisitedStates.Count);

            /*Debug.Log("Available Actions = " + totalActions);
             * foreach ( iThinkAction act in ActionManager.getActions() )
             *      Debug.Log(act.ToString());*/

            int         it = 0;
            iThinkPlan  curStep, nextStep;
            iThinkState CurrentState;

            while (OpenStates.Count != 0)
            {
                List <iThinkAction> applicableActions = new List <iThinkAction>();

                curStep      = new iThinkPlan(OpenStates[0]);
                CurrentState = OpenStates[0].getState();
                VisitedStates.Add(CurrentState);
                OpenStates.RemoveAt(0);

                //Debug.LogWarning( "Iteration #" + it + " - " + curStep.getState().ToString() );

                applicableActions = getApplicable(CurrentState, ActionManager.getActions());

                int count = 0;
                foreach (iThinkAction action in applicableActions)
                {
                    //Debug.Log(action.ToString());
                    nextStep = progress(curStep, action);

                    if (compareStates(nextStep.getState(), GoalState))
                    {
                        Debug.Log("Found Plan (DepthFS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count);
                        Plan.setPlan(nextStep);
                        return(Plan);
                    }

                    if (!VisitedStates.Contains(nextStep.getState()))
                    {
                        OpenStates.Insert(count, nextStep);
                        count++;
                    }
                }

                ++it;
            }
            Debug.Log("Didn't find Plan (DepthFS) " + it);
            return(null);
        }
Ejemplo n.º 2
0
		public override iThinkPlan SearchMethod( iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
		{
			//Debug.LogWarning(GoalState.ToString());
			//Debug.LogWarning(ActionManager.getActions().Count);
			//Debug.LogWarning(OpenStates.Count);
			//Debug.LogWarning(VisitedStates.Count);
			/*Debug.Log("Available Actions = " + totalActions);
			foreach ( iThinkAction act in ActionManager.getActions() )
				Debug.Log(act.ToString());*/
			
			int it = 0;
			iThinkPlan curStep, nextStep;
			iThinkState CurrentState;

			while ( OpenStates.Count != 0 )
			{
				List<iThinkAction> applicableActions = new List<iThinkAction>();

				curStep = new iThinkPlan( OpenStates[0] );
				CurrentState = OpenStates[0].getState();
				VisitedStates.Add( CurrentState );
				OpenStates.RemoveAt( 0 );

				//Debug.LogWarning( "Iteration #" + it + " - " + curStep.getState().ToString() );
				
				applicableActions = getApplicable( CurrentState, ActionManager.getActions() );

				int count=0;
				foreach ( iThinkAction action in applicableActions )
				{
					//Debug.Log(action.ToString());
					nextStep = progress( curStep, action );

					if ( compareStates( nextStep.getState(), GoalState ) )
					{
						Debug.Log( "Found Plan (DepthFS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count );
						Plan.setPlan( nextStep );
						return Plan;
					}

					if( !VisitedStates.Contains(nextStep.getState()))
					{
						OpenStates.Insert( count, nextStep );
						count++;
					}
				}

				++it;
			}
			Debug.Log( "Didn't find Plan (DepthFS) " + it );
			return null;
		}
Ejemplo n.º 3
0
		public bool forwardSearch( iThinkState InitialState, iThinkState GoalState, iThinkActionManager ActionManager)
		{
			iThinkPlan ReturnVal;

			_OpenStates.Clear();
			_VisitedStates.Clear();

			iThinkPlan step = new iThinkPlan( InitialState );
			_OpenStates.Add( step );
			_VisitedStates.Add( step.getState() );

			ReturnVal = SearchMethod( GoalState, ActionManager, _OpenStates, _VisitedStates );

			if ( ReturnVal == null )
				return false;
			else if ( ReturnVal.hasPlan() )
				return true;
			return false;
		}
Ejemplo n.º 4
0
        public bool forwardSearch(iThinkState InitialState, iThinkState GoalState, iThinkActionManager ActionManager)
        {
            iThinkPlan ReturnVal;

            _OpenStates.Clear();
            _VisitedStates.Clear();

            iThinkPlan step = new iThinkPlan(InitialState);

            _OpenStates.Add(step);
            _VisitedStates.Add(step.getState());

            ReturnVal = SearchMethod(GoalState, ActionManager, _OpenStates, _VisitedStates);

            if (ReturnVal == null)
            {
                return(false);
            }
            else if (ReturnVal.hasPlan())
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager,
                                                List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
        {
            int it = 0;

            actionManager = ActionManager;
            iThinkPlan  curStep, nextStep;
            iThinkState CurrentState = null;

            List <iThinkPlan> stateList = null;

            nodesVisited++;

            while (OpenStates.Count != 0)
            {
                List <iThinkAction> applicableActions = new List <iThinkAction>();

                stateList = new List <iThinkPlan>();

                curStep      = new iThinkPlan(OpenStates[0]);
                CurrentState = OpenStates[0].getState();
                VisitedStates.Add(CurrentState);

                /*
                 * for ( int i = 0 ; i < ((SimpleFPSActionManager)ActionManager).totalAreas ; i++ )
                 *      foreach (iThinkAction a in ((SimpleFPSActionManager)ActionManager).getActions(i))
                 *              a.ToStringLite();
                 */

                OpenStates.RemoveAt(0);
                if (curStep.getActionCount() < depth)
                {
                    applicableActions = getApplicable(curStep.getState(), ((SimpleFPSActionManager)ActionManager).getActions(Convert.ToInt32(curStep.getState().getFactList().Find(item => item.getName().Equals("npc-at")).getObj(0).name.Substring(4))));

                    foreach (iThinkAction action in applicableActions)
                    {
                        nextStep = progress(curStep, action);
                        nodesVisited++;
                        if (compareStates(nextStep.getState(), GoalState))
                        {
                            nodesExpanded++;
                            Debug.Log("Found Plan (A* FS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count + ", Nodes Expanded: " + nodesExpanded);
                            Plan.setPlan(nextStep);
                            repoFunct.completed = true;

                            return(Plan);
                        }

                        if (!VisitedStates.Contains(nextStep.getState()))
                        {
                            int Cost = hFunction(nextStep.getState(), GoalState);
                            Cost = Cost + nextStep.getPlanActions().Count;
                            nextStep.getState().setCost(Cost);
                            stateList.Add(nextStep);
                            nodesExpanded++;
                        }
                    }

                    OpenStates.AddRange(stateList);
                    OpenStates.Sort(delegate(iThinkPlan obj1, iThinkPlan obj2)
                    {
                        if (obj1.getState().getCost() == obj2.getState().getCost())
                        {
                            return(0);
                        }
                        else if (obj1.getState().getCost() < obj2.getState().getCost())
                        {
                            return(-1);
                        }
                        else
                        {
                            return(1);
                        }
                    }
                                    );
                    ++it;
                }
            }
            Debug.Log("Didn't find Plan (A* FS)");
            return(null);
        }
Ejemplo n.º 6
0
        public bool forwardSearchBounded(iThinkState InitialState, iThinkState GoalState, iThinkActionManager ActionManager, double timelimit, int retries = 3)
        {
            iThinkPlan ReturnVal;

            _OpenStates.Clear();
            _VisitedStates.Clear();

            iThinkPlan step = new iThinkPlan(InitialState);

            _OpenStates.Add(step);
            _VisitedStates.Add(step.getState());

            ReturnVal = SearchMethodBounded(GoalState, ActionManager, _OpenStates, _VisitedStates, timelimit);

            if (ReturnVal == null)
            {
                return(false);
            }
            else if (compareStates(ReturnVal.getState(), GoalState))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 7
0
 public virtual iThinkPlan SearchMethodBounded(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates, double timelimit)
 {
     return(null);
 }
Ejemplo n.º 8
0
 public virtual iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
 {
     return(null);
 }
Ejemplo n.º 9
0
		public virtual iThinkPlan SearchMethodBounded(iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates, double timelimit)
		{
			return null;
		}
Ejemplo n.º 10
0
		public override iThinkPlan SearchMethod ( iThinkState GoalState, iThinkActionManager ActionManager,
		                                         List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
		{
			int it = 0;
			actionManager = ActionManager;
			iThinkPlan curStep, nextStep;
			iThinkState CurrentState = null;

			List<iThinkPlan> stateList = null;
			nodesVisited++;

			while ( OpenStates.Count != 0 )
			{
				List<iThinkAction> applicableActions = new List<iThinkAction>();

				stateList = new List<iThinkPlan>();

				curStep = new iThinkPlan( OpenStates[0] );
				CurrentState = OpenStates[0].getState();
				VisitedStates.Add(CurrentState);
				
				/*
				for ( int i = 0 ; i < ((SimpleFPSActionManager)ActionManager).totalAreas ; i++ )
					foreach (iThinkAction a in ((SimpleFPSActionManager)ActionManager).getActions(i))
						a.ToStringLite();
				*/

				OpenStates.RemoveAt( 0 );
				if (curStep.getActionCount() < depth)
				{
					applicableActions = getApplicable( curStep.getState(), ((SimpleFPSActionManager)ActionManager).getActions( Convert.ToInt32(curStep.getState().getFactList().Find(item => item.getName().Equals("npc-at")).getObj(0).name.Substring(4))));

					foreach ( iThinkAction action in applicableActions )
					{
						nextStep = progress( curStep, action );
						nodesVisited++;
						if ( compareStates( nextStep.getState(), GoalState ) )
						{
							nodesExpanded++;
							Debug.Log( "Found Plan (A* FS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count + ", Nodes Expanded: " + nodesExpanded);
							Plan.setPlan( nextStep );
							repoFunct.completed=true;

							return Plan;
						}

						if ( !VisitedStates.Contains(nextStep.getState()) )
						{
							int Cost = hFunction( nextStep.getState(), GoalState );
							Cost = Cost + nextStep.getPlanActions().Count;
							nextStep.getState().setCost( Cost );
							stateList.Add( nextStep );
							nodesExpanded++;
						}

					}

					OpenStates.AddRange( stateList );
					OpenStates.Sort( delegate( iThinkPlan obj1, iThinkPlan obj2 )
					                {
					                	if ( obj1.getState().getCost() == obj2.getState().getCost() )
					                		return 0;
					                	else if ( obj1.getState().getCost() < obj2.getState().getCost() )
					                		return -1;
					                	else
					                		return 1;
					                }
					               );
					++it;
				}

			}
			Debug.Log( "Didn't find Plan (A* FS)" );
			return null;
		}
Ejemplo n.º 11
0
		public override iThinkPlan SearchMethod( iThinkState GoalState, iThinkActionManager ActionManager,
		                                        List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
		{
			int it = 0;
			iThinkPlan curStep, nextStep;
			iThinkState CurrentState = null;

			List<iThinkPlan> stateList = null;

			this.totalActions = ActionManager.getActions().Count;
			this.nodes += OpenStates.Count;

			/*Debug.Log("Available Actions = " + totalActions);
			foreach ( iThinkAction act in ActionManager.getActions() )
				Debug.Log(act.ToString());*/
			
			List<iThinkAction> applicableActions = new List<iThinkAction>();
			stateList = new List<iThinkPlan>();

			if ( compareStates( OpenStates[0].getState(), GoalState ) )
			{
				Debug.Log( "Found Plan (BestFS) - Already at goal state!" );
				Plan.setPlan( OpenStates[0] );
				repoFunct.completed=true;
				return Plan;
			}
			
			while ( OpenStates.Count != 0 )
			{
				if(it % 200 == 0 && it!=0){
					//InitRepo();
					this.repoOpenStates = new List<iThinkPlan>(OpenStates);
					this.repoVisitedStates = new List<iThinkState>(VisitedStates);
					this.repoStateList = new List<iThinkPlan>(stateList);
					this.repoCurrentState = new iThinkState(CurrentState);
					this.repoIterations = it;
					repoFunct.loadData = true;
					return null;
				}else if( repoFunct.loadData ){
					OpenStates = this.repoOpenStates;
					VisitedStates = this.repoVisitedStates;
					stateList = this.repoStateList;
					CurrentState = this.repoCurrentState;
					it = this.repoIterations;
					repoFunct.loadData = false;
					//ClearRepo();
				}else{
					stateList = new List<iThinkPlan>();
				}

				curStep = new iThinkPlan( OpenStates[0] );
				CurrentState = OpenStates[0].getState();
				
				//Debug.Log(GoalState.ToString());
				//Debug.Log(CurrentState.ToString());
				
				//Debug.LogWarning( "Iteration #" + it + " - " + curStep.getState().ToString() );
				
				VisitedStates.Add( OpenStates[0].getState() );
				OpenStates.RemoveAt( 0 );
				applicableActions = getApplicable( CurrentState, ActionManager.getActions() );

				this.nodesExpanded++;
				this.totalApplicable += applicableActions.Count;

				foreach ( iThinkAction action in applicableActions )
				{
					//Debug.Log(action.ToString());

					nextStep = progress( curStep, action );

					if ( compareStates( nextStep.getState(), GoalState ) )
					{
						Debug.Log( "Found Plan (BestFS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count );
						Plan.setPlan( nextStep );
						repoFunct.completed=true;
						return Plan;
					}

					if ( VisitedStates.Contains(nextStep.getState()) == false )
					{
						int Cost = hFunction( nextStep.getState(), GoalState );
						nextStep.getState().setCost( Cost );
						stateList.Add( nextStep );
						this.nodes ++;
						this.totalActionsUsed++;
					}
				}

				OpenStates.AddRange( stateList );
				OpenStates.Sort( delegate( iThinkPlan obj1, iThinkPlan obj2 )
				                {
				                	if ( obj1.getState().getCost() == obj2.getState().getCost() )
				                		return 0;
				                	else if ( obj1.getState().getCost() > obj2.getState().getCost() )
				                		return -1;
				                	else
				                		return 1;
				                }
				               );
				++it;
			}
			Debug.Log( "Didn't find plan (BestFS) " + it );
			return null;
		}
Ejemplo n.º 12
0
        public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager,
                                                List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
        {
            int         it = 0;
            iThinkPlan  curStep, nextStep;
            iThinkState CurrentState = null;

            List <iThinkPlan> stateList = null;

            while (OpenStates.Count != 0)
            {
                List <iThinkAction> applicableActions = new List <iThinkAction>();

                stateList = new List <iThinkPlan>();

                curStep      = new iThinkPlan(OpenStates[0]);
                CurrentState = OpenStates[0].getState();
                //VisitedStates.Add(CurrentState);

                OpenStates.RemoveAt(0);
                if (curStep.getActionCount() < depth)
                {
                    applicableActions = getApplicable(CurrentState, ActionManager.getActions());

                    foreach (iThinkAction action in applicableActions)
                    {
                        nextStep = progress(curStep, action);
                        if (compareStates(nextStep.getState(), GoalState))
                        {
                            Debug.Log("Found Plan (A*-weak FS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count + ", Nodes Expanded: " + nodesExpanded);
                            Plan.setPlan(nextStep);
                            repoFunct.completed = true;
                            return(Plan);
                        }

                        if (!VisitedStates.Contains(nextStep.getState()))
                        {
                            int Cost = hFunction(nextStep.getState(), GoalState);
                            Cost = Cost + nextStep.getPlanActions().Count;
                            nextStep.getState().setCost(Cost);
                            stateList.Add(nextStep);
                        }
                    }
                    OpenStates.AddRange(stateList);
                    OpenStates.Sort(delegate(iThinkPlan obj1, iThinkPlan obj2)
                    {
                        if (obj1.getState().getCost() == obj2.getState().getCost())
                        {
                            return(0);
                        }
                        else if (obj1.getState().getCost() < obj2.getState().getCost())
                        {
                            return(-1);
                        }
                        else
                        {
                            return(1);
                        }
                    }
                                    );
                    ++it;
                }
            }
            Debug.Log("Didn't find Plan (A*-weak FS)");
            return(null);
        }
Ejemplo n.º 13
0
		public bool forwardSearchBounded( iThinkState InitialState, iThinkState GoalState, iThinkActionManager ActionManager, double timelimit, int retries = 3)
		{
			iThinkPlan ReturnVal;

			_OpenStates.Clear();
			_VisitedStates.Clear();

			iThinkPlan step = new iThinkPlan( InitialState );
			_OpenStates.Add( step );
			_VisitedStates.Add( step.getState() );

			ReturnVal = SearchMethodBounded( GoalState, ActionManager, _OpenStates, _VisitedStates, timelimit );

			if ( ReturnVal == null )
				return false;
			else if ( compareStates(ReturnVal.getState(), GoalState ) )
				return true;
			return false;
		}
        public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
        {
            int it = 0;

            nodesVisited  = 0;
            nodesExpanded = 0;
            DateTime    n1 = DateTime.Now;
            iThinkPlan  curStep, nextStep;
            iThinkState CurrentState;

            nodesVisited++;
            actionManager = ActionManager;
            List <iThinkAction> applicableActions;

            if (compareStates(OpenStates[0].getState(), GoalState))
            {
                Debug.Log("Found Plan (HFS) - Already at goal state!");
                Plan.setPlan(OpenStates[0]);
                repoFunct.completed = true;
                return(Plan);
            }

            //Debug.Log("Available actions: " + ActionManager.getActions().Count);

            while (OpenStates.Count != 0)
            {
                curStep      = new iThinkPlan(OpenStates[0]);
                CurrentState = OpenStates[0].getState();
                VisitedStates.Add(CurrentState);
                OpenStates.RemoveAt(0);
                int curArea = Convert.ToInt32(curStep.getState().getFactList().Find(item => item.getName().Equals("npc-at")).getObj(0).name.Substring(4));
                if (curStep.getActionCount() == depth)
                {
                    DateTime n2     = DateTime.Now;
                    TimeSpan interv = n2 - n1;
                    interval = ((int)interv.TotalMilliseconds / 100) / (double)10;
                    curStep.debugPrintPlan();
                    return(curStep);
                }
                if (curStep.getActionCount() < depth)
                {
                    List <iThinkPlan> successors = new List <iThinkPlan>();
                    ///applicableActions = getApplicable( CurrentState, ((SimpleFPSActionManager)ActionManager).getActions(-1) );
                    applicableActions = getApplicable(CurrentState, ((SimpleFPSActionManager)ActionManager).getActions(curArea));
                    nodesExpanded++;

                    foreach (iThinkAction action in applicableActions)
                    {
                        nextStep = progress(curStep, action);

                        if (compareStates(nextStep.getState(), GoalState))
                        {
                            nodesVisited++;
                            Debug.Log("Found Plan (H-DepthFS) " + nextStep.getActionCount() +
                                      " (Nodes: " + nodesVisited + "/" + nodesExpanded + ")");
                            Plan.setPlan(nextStep);
                            return(Plan);
                        }

                        if (!VisitedStates.Contains(nextStep.getState()))
                        {
                            int Cost = hFunction(nextStep.getState(), GoalState, curArea);
                            if (Cost != -1)
                            {
                                nextStep.getState().setCost(Cost);
                                successors.Add(nextStep);
                                nodesVisited++;
                            }
                        }
                    }
                    successors.Sort(delegate(iThinkPlan obj1, iThinkPlan obj2)
                    {
                        if (obj1.getState().getCost() == obj2.getState().getCost())
                        {
                            return(0);
                        }
                        else if (obj1.getState().getCost() < obj2.getState().getCost())
                        {
                            return(-1);
                        }
                        else
                        {
                            return(1);
                        }
                    }
                                    );
                    OpenStates.InsertRange(0, successors);

                    /*TimeSpan timediff = n1 - DateTime.Now;
                     * if ( timediff.TotalSeconds > 60 )
                     *      return OpenStates[0];*/
                    ++it;
                }
                else
                {
                }
            }
            Debug.Log("Didn't find Plan (H-DepthFS)");
            return(null);
        }
Ejemplo n.º 15
0
        public override iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager,
                                                List <iThinkPlan> OpenStates, List <iThinkState> VisitedStates)
        {
            int         it = 0;
            iThinkPlan  curStep, nextStep;
            iThinkState CurrentState = null;

            List <iThinkPlan> stateList = null;

            this.totalActions = ActionManager.getActions().Count;
            this.nodes       += OpenStates.Count;

            /*Debug.Log("Available Actions = " + totalActions);
             * foreach ( iThinkAction act in ActionManager.getActions() )
             *      Debug.Log(act.ToString());*/

            List <iThinkAction> applicableActions = new List <iThinkAction>();

            stateList = new List <iThinkPlan>();

            if (compareStates(OpenStates[0].getState(), GoalState))
            {
                Debug.Log("Found Plan (BestFS) - Already at goal state!");
                Plan.setPlan(OpenStates[0]);
                repoFunct.completed = true;
                return(Plan);
            }

            while (OpenStates.Count != 0)
            {
                if (it % 200 == 0 && it != 0)
                {
                    //InitRepo();
                    this.repoOpenStates    = new List <iThinkPlan>(OpenStates);
                    this.repoVisitedStates = new List <iThinkState>(VisitedStates);
                    this.repoStateList     = new List <iThinkPlan>(stateList);
                    this.repoCurrentState  = new iThinkState(CurrentState);
                    this.repoIterations    = it;
                    repoFunct.loadData     = true;
                    return(null);
                }
                else if (repoFunct.loadData)
                {
                    OpenStates         = this.repoOpenStates;
                    VisitedStates      = this.repoVisitedStates;
                    stateList          = this.repoStateList;
                    CurrentState       = this.repoCurrentState;
                    it                 = this.repoIterations;
                    repoFunct.loadData = false;
                    //ClearRepo();
                }
                else
                {
                    stateList = new List <iThinkPlan>();
                }

                curStep      = new iThinkPlan(OpenStates[0]);
                CurrentState = OpenStates[0].getState();

                //Debug.Log(GoalState.ToString());
                //Debug.Log(CurrentState.ToString());

                //Debug.LogWarning( "Iteration #" + it + " - " + curStep.getState().ToString() );

                VisitedStates.Add(OpenStates[0].getState());
                OpenStates.RemoveAt(0);
                applicableActions = getApplicable(CurrentState, ActionManager.getActions());

                this.nodesExpanded++;
                this.totalApplicable += applicableActions.Count;

                foreach (iThinkAction action in applicableActions)
                {
                    //Debug.Log(action.ToString());

                    nextStep = progress(curStep, action);

                    if (compareStates(nextStep.getState(), GoalState))
                    {
                        Debug.Log("Found Plan (BestFS) after " + it + " iterations, of length " + nextStep.getPlanActions().Count);
                        Plan.setPlan(nextStep);
                        repoFunct.completed = true;
                        return(Plan);
                    }

                    if (VisitedStates.Contains(nextStep.getState()) == false)
                    {
                        int Cost = hFunction(nextStep.getState(), GoalState);
                        nextStep.getState().setCost(Cost);
                        stateList.Add(nextStep);
                        this.nodes++;
                        this.totalActionsUsed++;
                    }
                }

                OpenStates.AddRange(stateList);
                OpenStates.Sort(delegate(iThinkPlan obj1, iThinkPlan obj2)
                {
                    if (obj1.getState().getCost() == obj2.getState().getCost())
                    {
                        return(0);
                    }
                    else if (obj1.getState().getCost() > obj2.getState().getCost())
                    {
                        return(-1);
                    }
                    else
                    {
                        return(1);
                    }
                }
                                );
                ++it;
            }
            Debug.Log("Didn't find plan (BestFS) " + it);
            return(null);
        }
Ejemplo n.º 16
0
		public override iThinkPlan SearchMethod( iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
		{
			int it = 0;
			DateTime n1 = DateTime.Now;
			iThinkPlan curStep, nextStep;
			iThinkState CurrentState;
			nodesVisited++;
			actionManager = ActionManager;
			List<iThinkAction> applicableActions;

			if ( compareStates( OpenStates[0].getState(), GoalState ) )
			{
				Debug.Log( "Found Plan (HFS) - Already at goal state!" );
				Plan.setPlan( OpenStates[0] );
				repoFunct.completed=true;
				return Plan;
			}
			
			//Debug.Log("Available actions: " + ActionManager.getActions().Count);
			
			while ( OpenStates.Count != 0 )
			{
				curStep = new iThinkPlan( OpenStates[0] );
				CurrentState = OpenStates[0].getState();
				VisitedStates.Add( CurrentState );
				OpenStates.RemoveAt( 0 );
				int curArea = Convert.ToInt32(curStep.getState().getFactList().Find(item => item.getName().Equals("npc-at")).getObj(0).name.Substring(4));
				
				if (curStep.getActionCount() < depth)
				{
					List<iThinkPlan> successors = new List<iThinkPlan>();
					applicableActions = getApplicable( CurrentState, ((SimpleFPSActionManager)ActionManager).getActions(-1) );
					///applicableActions = getApplicable( CurrentState, ((SimpleFPSActionManager)ActionManager).getActions(curArea) );
					nodesExpanded++;
					foreach ( iThinkAction action in applicableActions )
					{
						nextStep = progress( curStep, action );
						
						if ( compareStates( nextStep.getState(), GoalState ) )
						{
							nodesVisited++;
							Debug.Log( "Found Plan (H-DepthFS) " + nextStep.getActionCount() +
							          " (Nodes: "+nodesVisited+"/"+nodesExpanded+")");
							Plan.setPlan( nextStep );
							return Plan;
						}

						//if ( !VisitedStates.Contains(nextStep.getState()) ) {
							int Cost = hFunction( nextStep.getState(), GoalState, curArea );
							if (Cost != -1)
							{
								nextStep.getState().setCost( Cost );
								successors.Add(nextStep);

								nodesVisited++;
							}
						//}
					}
					successors.Sort( delegate( iThinkPlan obj1, iThinkPlan obj2 )
					                {
					                	if ( obj1.getState().getCost() == obj2.getState().getCost() )
					                		return 0;
					                	else if ( obj1.getState().getCost() < obj2.getState().getCost() )
					                		return -1;
					                	else
					                		return 1;
					                }
					               );
					OpenStates.InsertRange(0, successors);
					TimeSpan timediff = n1 - DateTime.Now;
					if ( timediff.TotalSeconds > 60 )
						return OpenStates[0];
					++it;
				}
				else {
					Debug.LogWarning("Depth Sucks!");
				}
			}
			Debug.Log( "Didn't find Plan (H-DepthFS)" );
			return null;
		}
Ejemplo n.º 17
0
		public virtual iThinkPlan SearchMethod(iThinkState GoalState, iThinkActionManager ActionManager, List<iThinkPlan> OpenStates, List<iThinkState> VisitedStates )
		{
			return null;
		}