bug resolutions

This commit is contained in:
Lukian LEIZOUR 2024-02-28 17:48:09 +01:00
parent 665498f98b
commit 561069b074
3 changed files with 36 additions and 21 deletions

View file

@ -5,7 +5,7 @@ public class AppLaser {
public static void main(String [] args) {
int start_i = 3;
int start_j = 1;
int start_dir = 12;
int start_dir = 10;
int firstState_i = 0;
int firstState_j = 0;
@ -29,7 +29,7 @@ public class AppLaser {
Stack <Situation> stack = new Stack <Situation>();
Universe universe = new Universe(5, 5, start_i, start_j, start_dir);
Universe universe = new Universe(8, 8, start_i, start_j, start_dir);
Situation previousState, currentState = new Situation(firstState_i, firstState_j, start_dir, 0);
@ -39,19 +39,25 @@ public class AppLaser {
int i = 0;
while (!universe.isSolved()) {
System.out.printf("%d %d %d %d %d", currentState.pos_i, currentState.pos_j, currentState.direction, currentState.nb_choix, universe.possibleChoices(currentState));
System.out.printf("i: %d, j: %d, dir: %d, choice: %d, possible: %d\n", 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 {
else if (stack.size() > 0) {
currentState = stack.pop();
universe.reset(currentState);
System.out.println("\n\n");
universe.print();
//System.out.println("\n\n");
//universe.print();
} else {
break;
}
}
System.out.println("\n\n");
universe.print();
}
}

View file

@ -13,7 +13,7 @@ public class Universe {
this.grid = new int[height][length];
this.height = height;
this.length = length;
int i, j;
for (i = 1; i < this.height - 1; i++) {
for (j = 1; j < this.length - 1; j++) {
@ -61,25 +61,25 @@ public class Universe {
case 0: {
switch (d) {
case 10: // north
if (this.grid[i - 1][j] == 0) return 1; // front
if (this.grid[i - 1][j] == 0) return 1; // front
else if (this.grid[i][j - 1] == 0) return 2; // left
else if (this.grid[i][j + 1] == 0) return 3; // right
else return -1; // back
case 11: // south
if (this.grid[i + 1][j] == 0) return 1; // front
if (this.grid[i + 1][j] == 0) return 1; // front
else if (this.grid[i][j + 1] == 0) return 2; // left
else if (this.grid[i][j - 1] == 0) return 3; // right
else return -1; // back
case 12: // east
if (this.grid[i][j + 1] == 0) return 1; // front
if (this.grid[i][j + 1] == 0) return 1; // front
else if (this.grid[i - 1][j] == 0) return 2; // left
else if (this.grid[i + 1][j] == 0) return 3; // right
else return -1; // back
case 13: //west
if (this.grid[i][j - 1] == 0) return 1; // front
if (this.grid[i][j - 1] == 0) return 1; // front
else if (this.grid[i + 1][j] == 0) return 2; // left
else if (this.grid[i - 1][j] == 0) return 3; // right
else return -1; // back
@ -90,22 +90,22 @@ public class Universe {
case 1: {
switch (d) {
case 10: // north
if (this.grid[i][j - 1] == 0) return 2; // left
if (this.grid[i][j - 1] == 0) return 2; // left
else if (this.grid[i][j + 1] == 0) return 3; // right
else return -1; // back
case 11: // south
if (this.grid[i][j + 1] == 0) return 2; // left
if (this.grid[i][j + 1] == 0) return 2; // left
else if (this.grid[i][j - 1] == 0) return 3; // right
else return -1; // back
case 12: // east
if (this.grid[i - 1][j] == 0) return 2; // left
if (this.grid[i - 1][j] == 0) return 2; // left
else if (this.grid[i + 1][j] == 0) return 3; // right
else return -1; // back
case 13: //west
if (this.grid[i + 1][j] == 0) return 2; // left
if (this.grid[i + 1][j] == 0) return 2; // left
else if (this.grid[i - 1][j] == 0) return 3; // right
else return -1; // back
@ -115,19 +115,19 @@ public class Universe {
case 2: {
switch (d) {
case 10: // north
if (this.grid[i][j + 1] == 0) return 3; // right
if (this.grid[i][j + 1] == 0) return 3; // right
else return -1; // back
case 11: // south
if (this.grid[i][j - 1] == 0) return 3; // right
if (this.grid[i][j - 1] == 0) return 3; // right
else return -1; // back
case 12: // east
if (this.grid[i + 1][j] == 0) return 3; // right
if (this.grid[i + 1][j] == 0) return 3; // right
else return -1; // back
case 13: //west
if (this.grid[i - 1][j] == 0) return 3; // right
if (this.grid[i - 1][j] == 0) return 3; // right
else return -1; // back
@ -154,6 +154,10 @@ public class Universe {
// adding the miror
switch (c) {
case 1:
this.grid[i][j] = 1;
break;
case 2:
this.grid[i][j] = 2;
break;
@ -184,7 +188,7 @@ public class Universe {
d = 13;
}
this.boxes_to_fill++;
this.boxes_to_fill--;
return new Situation(i, j, d, 0);
}
@ -195,7 +199,7 @@ public class Universe {
}
public boolean isSolved() {
return this.boxes_to_fill == 0;
return this.boxes_to_fill - 1 == 0;
}
/*public Situation restore(Situation current, Situation prev) {
@ -211,6 +215,10 @@ public class Universe {
System.out.printf(" X");
break;
case 1:
System.out.printf(" +");
break;
case 10:
System.out.printf(" ^");
break;

View file

@ -28,6 +28,7 @@ Le truc avec la pile:
types de cases:
- 0 case vide
- -1 obstacle
- 1 laser
- 2 miroir gauche
- 3 miroir droite
- 10 départ nord