additions to previous commit

This commit is contained in:
Ninja-Jambon 2024-02-28 12:49:50 +01:00
parent ab7d525156
commit 6de2a3ac93
2 changed files with 31 additions and 12 deletions

View file

@ -17,17 +17,25 @@ public class AppLaser {
universe.print(); universe.print();
int i = 0;
do { do {
System.out.printf("%d %d %d %d %d", currentState.pos_i, currentState.pos_j, currentState.direction, currentState.nb_choix, universe.possibleChoices(currentState));
if (universe.canEvolve(currentState)) { if (universe.canEvolve(currentState)) {
stack.push(currentState.copy(universe.possibleChoices(currentState))); stack.push(currentState.copy(universe.possibleChoices(currentState)));
currentState = universe.evolve(currentState); currentState = universe.evolve(currentState);
} }
else { else {
currentState = stack.pop(); currentState = stack.pop();
universe.reset(currentState);
System.out.println("\n\n");
universe.print();
} }
universe.print();
} while (stack.size() != 0); } while (!universe.isSolved());
} }
} }

View file

@ -5,6 +5,7 @@ public class Universe {
private int[][] grid; private int[][] grid;
private int length, height; private int length, height;
private int boxes_to_fill;
// Constructors // Constructors
@ -30,6 +31,14 @@ public class Universe {
} }
this.grid[i_start][j_start] = dir_start; this.grid[i_start][j_start] = dir_start;
this.boxes_to_fill = 0;
for (i = 1; i < this.height - 1; i++) {
for (j = 1; j < this.length - 1; j++) {
if (this.grid[i][j] == 0) this.boxes_to_fill++;
}
}
} }
// Methods // Methods
@ -41,10 +50,6 @@ public class Universe {
else {} else {}
} }
public boolean isSolved() {
return true;
}
public int possibleChoices(Situation s) { public int possibleChoices(Situation s) {
int i = s.pos_i; int i = s.pos_i;
int j = s.pos_j; int j = s.pos_j;
@ -173,21 +178,27 @@ public class Universe {
j ++; j ++;
d = 12; d = 12;
} }
else if (c == 1 && d == 12 || c == 2 && d == 10 || c == 3 && d == 11) { else if (c == 1 && d == 13 || c == 2 && d == 10 || c == 3 && d == 11) {
j --; j --;
d = 13; d = 13;
} }
return new Situation(i, j, d, c); this.boxes_to_fill++;
return new Situation(i, j, d, 0);
} }
public void reset(int i, int j) { public void reset(Situation s) {
this.grid[i][j] = -1; this.grid[s.pos_i][s.pos_j] = 0;
} }
public Situation restore(Situation current, Situation prev) { public boolean isSolved() {
return this.boxes_to_fill == 0;
}
/*public Situation restore(Situation current, Situation prev) {
} }*/
public void print() { public void print() {
int i, j; int i, j;