bug resolution

This commit is contained in:
Lukian LEIZOUR 2024-03-28 23:33:35 +01:00
parent 42746ad5b0
commit bb09c5afca
6 changed files with 22 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 424 B

After

Width:  |  Height:  |  Size: 428 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 456 B

After

Width:  |  Height:  |  Size: 428 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 B

After

Width:  |  Height:  |  Size: 393 B

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 475 B

After

Width:  |  Height:  |  Size: 374 B

Before After
Before After

View file

@ -403,7 +403,15 @@ public class Universe {
}
public int[][] copyGrid() {
return this.grid.clone();
int [][] newGrid = new int[this.height][this.width];
for (int i = 0; i < this.height; i++) {
for (int j = 0; j < this.width; j++) {
newGrid[i][j] = this.grid[i][j];
}
}
return newGrid;
}
public int getWidth() {

View file

@ -216,6 +216,7 @@ public class Grid extends JPanel {
this.solving = true;
Thread computeThread = new Thread(new Runnable() {
int [][] bestGrid;
@Override
public void run() {
int [] startCoords = universe.getStartCoords();
@ -232,11 +233,13 @@ public class Grid extends JPanel {
Stack <Situation> stack = new Stack <Situation>();
Situation currentState = new Situation(firstState_i, firstState_j, start_dir, 0);
int [][] bestGrid = universe.copyGrid();
this.bestGrid = universe.copyGrid();
System.out.println(this.bestGrid[2][3] + " " + this.bestGrid + " " + universe.getGrid());
int best_filled_boxes = 0;
int best_nb_mirrors = 0;
long start = Instant.now().toEpochMilli();
long lastRefresh = start;
do {
if (universe.canEvolve(currentState)) {
@ -244,10 +247,10 @@ public class Grid extends JPanel {
currentState = universe.evolve(currentState);
if ((universe.getFilledBoxes() > best_filled_boxes) || (universe.getFilledBoxes() == best_filled_boxes && universe.getNbMirrors() < best_nb_mirrors)) {
bestGrid = universe.copyGrid();
this.bestGrid = universe.copyGrid();
best_filled_boxes = universe.getFilledBoxes();
best_nb_mirrors = universe.getNbMirrors();
printUniverseGrid(bestGrid);
//printUniverseGrid(this.bestGrid);
}
}
else if (stack.size() > 0) {
@ -256,8 +259,15 @@ public class Grid extends JPanel {
} else {
break;
}
if (Instant.now().toEpochMilli() - lastRefresh > refreshRate) {
lastRefresh = Instant.now().toEpochMilli();
printUniverseGrid(this.bestGrid);
}
} while (stack.size() != 0 && solving == true);
printUniverseGrid(bestGrid);
solving = false;
String message = "Solved in " + ((Instant.now().toEpochMilli() - start)/1000) + "s and " + ((Instant.now().toEpochMilli() - start)%1000) + "ms \nMirrors : " + best_nb_mirrors + "\nLaser length : " + best_filled_boxes;
alert(message);