bug resolutions
This commit is contained in:
parent
665498f98b
commit
561069b074
3 changed files with 36 additions and 21 deletions
|
@ -5,7 +5,7 @@ public class AppLaser {
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
int start_i = 3;
|
int start_i = 3;
|
||||||
int start_j = 1;
|
int start_j = 1;
|
||||||
int start_dir = 12;
|
int start_dir = 10;
|
||||||
int firstState_i = 0;
|
int firstState_i = 0;
|
||||||
int firstState_j = 0;
|
int firstState_j = 0;
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ public class AppLaser {
|
||||||
|
|
||||||
Stack <Situation> stack = new Stack <Situation>();
|
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);
|
Situation previousState, currentState = new Situation(firstState_i, firstState_j, start_dir, 0);
|
||||||
|
|
||||||
|
@ -39,19 +39,25 @@ public class AppLaser {
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (!universe.isSolved()) {
|
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)) {
|
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 if (stack.size() > 0) {
|
||||||
currentState = stack.pop();
|
currentState = stack.pop();
|
||||||
universe.reset(currentState);
|
universe.reset(currentState);
|
||||||
|
|
||||||
System.out.println("\n\n");
|
//System.out.println("\n\n");
|
||||||
universe.print();
|
//universe.print();
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println("\n\n");
|
||||||
|
|
||||||
|
universe.print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public class Universe {
|
||||||
this.grid = new int[height][length];
|
this.grid = new int[height][length];
|
||||||
this.height = height;
|
this.height = height;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
for (i = 1; i < this.height - 1; i++) {
|
for (i = 1; i < this.height - 1; i++) {
|
||||||
for (j = 1; j < this.length - 1; j++) {
|
for (j = 1; j < this.length - 1; j++) {
|
||||||
|
@ -61,25 +61,25 @@ public class Universe {
|
||||||
case 0: {
|
case 0: {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case 10: // north
|
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 2; // left
|
||||||
else if (this.grid[i][j + 1] == 0) return 3; // right
|
else if (this.grid[i][j + 1] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
case 11: // south
|
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 2; // left
|
||||||
else if (this.grid[i][j - 1] == 0) return 3; // right
|
else if (this.grid[i][j - 1] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
case 12: // east
|
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 2; // left
|
||||||
else if (this.grid[i + 1][j] == 0) return 3; // right
|
else if (this.grid[i + 1][j] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
case 13: //west
|
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 2; // left
|
||||||
else if (this.grid[i - 1][j] == 0) return 3; // right
|
else if (this.grid[i - 1][j] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
@ -90,22 +90,22 @@ public class Universe {
|
||||||
case 1: {
|
case 1: {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case 10: // north
|
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 if (this.grid[i][j + 1] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
case 11: // south
|
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 if (this.grid[i][j - 1] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
case 12: // east
|
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 if (this.grid[i + 1][j] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
case 13: //west
|
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 if (this.grid[i - 1][j] == 0) return 3; // right
|
||||||
else return -1; // back
|
else return -1; // back
|
||||||
|
|
||||||
|
@ -115,19 +115,19 @@ public class Universe {
|
||||||
case 2: {
|
case 2: {
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case 10: // north
|
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
|
else return -1; // back
|
||||||
|
|
||||||
case 11: // south
|
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
|
else return -1; // back
|
||||||
|
|
||||||
case 12: // east
|
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
|
else return -1; // back
|
||||||
|
|
||||||
case 13: //west
|
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
|
else return -1; // back
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,6 +154,10 @@ public class Universe {
|
||||||
// adding the miror
|
// adding the miror
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case 1:
|
||||||
|
this.grid[i][j] = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
this.grid[i][j] = 2;
|
this.grid[i][j] = 2;
|
||||||
break;
|
break;
|
||||||
|
@ -184,7 +188,7 @@ public class Universe {
|
||||||
d = 13;
|
d = 13;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.boxes_to_fill++;
|
this.boxes_to_fill--;
|
||||||
|
|
||||||
return new Situation(i, j, d, 0);
|
return new Situation(i, j, d, 0);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +199,7 @@ public class Universe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSolved() {
|
public boolean isSolved() {
|
||||||
return this.boxes_to_fill == 0;
|
return this.boxes_to_fill - 1 == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*public Situation restore(Situation current, Situation prev) {
|
/*public Situation restore(Situation current, Situation prev) {
|
||||||
|
@ -211,6 +215,10 @@ public class Universe {
|
||||||
System.out.printf(" X");
|
System.out.printf(" X");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
System.out.printf(" +");
|
||||||
|
break;
|
||||||
|
|
||||||
case 10:
|
case 10:
|
||||||
System.out.printf(" ^");
|
System.out.printf(" ^");
|
||||||
break;
|
break;
|
||||||
|
|
1
algo.txt
1
algo.txt
|
@ -28,6 +28,7 @@ Le truc avec la pile:
|
||||||
types de cases:
|
types de cases:
|
||||||
- 0 case vide
|
- 0 case vide
|
||||||
- -1 obstacle
|
- -1 obstacle
|
||||||
|
- 1 laser
|
||||||
- 2 miroir gauche
|
- 2 miroir gauche
|
||||||
- 3 miroir droite
|
- 3 miroir droite
|
||||||
- 10 départ nord
|
- 10 départ nord
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue