/** * Execute an action from the contingency plan * * @param percept a percept. * @return an action from the contingency plan. */ public override IAction Execute(IPercept percept) { // check if goal state VacuumEnvironmentState state = (VacuumEnvironmentState)this .getPerceptToStateFunction()(percept); if (state.getLocationState(VacuumEnvironment.LOCATION_A) == VacuumEnvironment.LocationState.Clean && state.getLocationState(VacuumEnvironment.LOCATION_B) == VacuumEnvironment.LocationState.Clean) { return(DynamicAction.NO_OP); } // check stack size if (this.stack.Size() < 1) { if (this.contingencyPlan.Size() < 1) { return(DynamicAction.NO_OP); } else { this.stack.Add(this.getContingencyPlan().Pop()); } } // pop... object currentStep = this.stack.Peek(); // push... if (currentStep is IAction) { return((IAction)this.stack.Pop()); } // case: next step is a plan else if (currentStep is Plan) { Plan newPlan = (Plan)currentStep; if (newPlan.Size() > 0) { this.stack.Add(newPlan.Pop()); } else { this.stack.Pop(); } return(this.Execute(percept)); } // case: next step is an if-then else if (currentStep is IfStateThenPlan) { IfStateThenPlan conditional = (IfStateThenPlan)this.stack.Pop(); this.stack.Add(conditional.ifStateMatches(percept)); return(this.Execute(percept)); } // case: ignore next step if null else if (currentStep == null) { this.stack.Pop(); return(this.Execute(percept)); } else { throw new RuntimeException("Unrecognized contingency plan step."); } }
public LocationState getLocationState(string location) { return(envState.getLocationState(location)); }
public static bool testGoal(VacuumEnvironmentState state) { return(state.getLocationState(VacuumEnvironment.LOCATION_A) == VacuumEnvironment.LocationState.Clean && state.getLocationState(VacuumEnvironment.LOCATION_B) == VacuumEnvironment.LocationState.Clean); }