Skip to content

Instantly share code, notes, and snippets.

@pablormier
Last active August 29, 2015 14:02
Show Gist options
  • Save pablormier/4f8c44fc235f1047a7fa to your computer and use it in GitHub Desktop.
Save pablormier/4f8c44fc235f1047a7fa to your computer and use it in GitHub Desktop.
enum Action { UP, DOWN, LEFT, RIGHT }
Hipster.SearchProblem p =
ProblemBuilder.create()
.initialState(Arrays.asList(5,4,0,7,2,6,8,1,3))
.defineProblemWithExplicitActions()
.useActionFunction(new ActionFunction<Action, List<Integer>>() {
public Iterable<Action> actionsFor(List<Integer> board) {
return validMovements(board);
}
}).useTransitionFunction(new ActionStateTransitionFunction<Action, List<Integer>>() {
public List<Integer> apply(Action action, List<Integer> board) {
return applyActionToBoard(action, board);
}
}).useCostFunction(new CostFunction<Action, List<Integer>, Double>() {
public Double evaluate(Transition<Action, List<Integer>> transition) {
return 1d;
}
}).build();
System.out.println(Hipster.createAStar(p).search(Arrays.asList(0,1,2,3,4,5,6,7,8)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment