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();
int i = 0;
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)) {
stack.push(currentState.copy(universe.possibleChoices(currentState)));
currentState = universe.evolve(currentState);
}
else {
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 length, height;
private int boxes_to_fill;
// Constructors
@ -30,6 +31,14 @@ public class Universe {
}
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
@ -41,10 +50,6 @@ public class Universe {
else {}
}
public boolean isSolved() {
return true;
}
public int possibleChoices(Situation s) {
int i = s.pos_i;
int j = s.pos_j;
@ -173,22 +178,28 @@ public class Universe {
j ++;
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 --;
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) {
this.grid[i][j] = -1;
public void reset(Situation s) {
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() {
int i, j;
for (i = 0; i < this.height; i++) {