/// Checks if goalState is a subset of curState static public bool compareStates(iThinkState curState, iThinkState goalState) { int counter = 0; if (curState != null) { foreach (iThinkFact fact in goalState.getFactList()) { foreach (iThinkFact check in curState.getFactList()) { if (check == null) { return(false); } else if (check.Equals(fact)) { counter++; } } } } if (counter == goalState.getFactList().Count) { return(true); } return(false); }
public void writeInitState(iThinkState st) { // create a writer and open the file TextWriter tw = new StreamWriter("initState.txt"); foreach (iThinkFact f in st.getFactList()) { // write a line of text to the file tw.WriteLine(f.ToString()); } // close the stream tw.Close(); }
/*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); }
public virtual int hFunction(iThinkState nextState, iThinkState GoalState) { int counter = 0; foreach (iThinkFact fact in nextState.getFactList()) { foreach (iThinkFact goalFact in GoalState.getFactList()) { if (fact.Equals(goalFact)) { counter++; break; } } } return(counter); }
/*! * Checks whether the action can be applied on iThinkState \a curState * @param curState The state to be checked * @returns A boolean value */ public bool isApplicable( iThinkState curState ) { int counter = 0; foreach ( iThinkFact fact in preconditions ) { //! TODO Get facts of wanted type/name only foreach ( iThinkFact checkFact in curState.getFactList() ) { if ( fact.Equals(checkFact) ) counter++; } } if ( counter == preconditions.Count ){ //Debug.LogError("Found applicable! " + this.ToString()); return true; } //if ( this.name.StartsWith("SFPSPlace") ) // Debug.Log("Unequal: " + counter + " of " + preconditions.Count + " - act: " + this.ToString()); return false; }
/*! * Checks whether the action can be applied on iThinkState \a curState * @param curState The state to be checked * @returns A boolean value */ public bool isApplicable(iThinkState curState) { int counter = 0; foreach (iThinkFact fact in preconditions) { //! TODO Get facts of wanted type/name only foreach (iThinkFact checkFact in curState.getFactList()) { if (fact.Equals(checkFact)) { counter++; } } } if (counter == preconditions.Count) { //Debug.LogError("Found applicable! " + this.ToString()); return(true); } //if ( this.name.StartsWith("SFPSPlace") ) // Debug.Log("Unequal: " + counter + " of " + preconditions.Count + " - act: " + this.ToString()); return(false); }
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; }
/// Checks if goalState is a subset of curState static public bool compareStates( iThinkState curState, iThinkState goalState ) { int counter = 0; if (curState != null) { foreach ( iThinkFact fact in goalState.getFactList() ) { foreach ( iThinkFact check in curState.getFactList() ) { if ( check == null ) return false; else if ( check.Equals(fact) ) counter++; } } } if ( counter == goalState.getFactList().Count ) return true; return false; }
public virtual int hFunction( iThinkState nextState, iThinkState GoalState ) { int counter = 0; foreach ( iThinkFact fact in nextState.getFactList() ) { foreach ( iThinkFact goalFact in GoalState.getFactList() ) { if ( fact.Equals( goalFact) ) { counter++; break; } } } return counter; }