added backtracking
This commit is contained in:
parent
00a72c289c
commit
ab7d525156
3 changed files with 186 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue