Exemplo n.º 1
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;
		}
        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);
        }
Exemplo n.º 3
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;
		}
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }