added backtracking

This commit is contained in:
Ninja-Jambon 2024-02-28 11:59:56 +01:00
parent 00a72c289c
commit ab7d525156
3 changed files with 186 additions and 4 deletions

View file

@ -7,13 +7,27 @@ public class AppLaser {
int start_j = 1;
int start_dir = 12;
Universe universe = new Universe(8, 8, start_i, start_j, start_dir);
Stack <Situation> stack = new Stack <Situation>();
Universe universe = new Universe(6, 6, start_i, start_j, start_dir);
Situation previousState, currentState = new Situation(start_i, start_j, start_dir, 0);
universe.addObstacle(4, 4);
//universe.addObstacle(4, 4);
universe.print();
do {
if (universe.canEvolve(currentState)) {
stack.push(currentState.copy(universe.possibleChoices(currentState)));
currentState = universe.evolve(currentState);
}
else {
currentState = stack.pop();
}
universe.print();
} while (stack.size() != 0);
}
}