daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jul 15th, 2018 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     private List<Operator> alg(List<Fact> state, List<List<Fact>> history,
  2.             List<Operator> path) {
  3.         List<Operator> result = null;
  4.  
  5.         // final state included in current state => WIN
  6.         if (state.containsAll(finalState)) {
  7.             result = new ArrayList<Operator>();
  8.             result.addAll(path);
  9.         } else {
  10.             List<Operator> viableActions = viableActions(state, history);
  11.             if (viableActions.isEmpty()) { // no possible actions => FAIL
  12.                 result = null;
  13.             } else {
  14.                 // choose operator
  15.                 Operator chosen = viableActions.get(0);
  16.                 List<Fact> newState = applyOperator(state, chosen);
  17.  
  18.                 history.add(state);
  19.  
  20.                 // recursive call
  21.                 path.add(chosen);
  22.                 List<Operator> call = alg(newState, history, path);
  23.                 path.remove(path.size() - 1);
  24.  
  25.                 if (call == null) {
  26.                     viableActions.remove(chosen);
  27.                     if (viableActions.isEmpty()) {
  28.                         result = null;
  29.                     } else {
  30.                         // choose next operator from the list
  31.                         chosen = viableActions.get(0);
  32.                         newState = applyOperator(state, chosen);
  33.  
  34.                         // recursive call
  35.                         path.add(chosen);
  36.                         result = alg(newState, history, path);
  37.                         path.remove(path.size() - 1);
  38.                     }
  39.                 } else {
  40.                     result = call;
  41.                 }
  42.  
  43.                 history.remove(state);
  44.             }
  45.         }
  46.         return result;
  47.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top