I have implemented a depth first search (recursive) for the 8 puzzle problem in Java:
protected PuzzleState depthFirstSearch(PuzzleState state) {
PuzzleState start = this.getStartState();
PuzzleState goal = this.getGoalState();
PuzzleState stop = null;
int limit = 35;
int depth = state.getDepth();
boolean tooDeep = false;
if (state.equals(goal)) {
return state;
} else {
if (depth == limit) {
return stop;
} else {
Collection<Integer> actions = PuzzleAction.getPuzzleActions();
for (Integer action : actions) {
PuzzleState starter = start;
PuzzleState next = state.succ(action);
if (next != null) {
starter = depthFirstSearch(next);
}
if (starter == stop) {
tooDeep = true;
} else {
if (!starter.equals(start)) {
return starter;
}
}
}
}
}
if (tooDeep)
return stop;
else
return start;
}
I don't know what I have to change to transform it to a iterative deepening depth search. I know that there is no limit for the depth, because it increases in every round. Tried this:
protected PuzzleState iterativeDeepSearch(PuzzleState state) {
int depth = state.getDepth();
for(int limit = 1; limit < depth; limit ++){
depthFirstSearch(state, limit);
}
}
Does anyone know how to change it to the needed IDS? Thank you in advance!