diff --git a/AppLaser.java b/AppLaser.java index f2b4e16..fe7df31 100644 --- a/AppLaser.java +++ b/AppLaser.java @@ -1,11 +1,12 @@ // Antoine CRETUAL, Lukian LEIZOUR, 14/02/2024 import java.util.Scanner; +import java.time.Instant; public class AppLaser { public static void main(String [] args) { - boolean cli = false; + boolean cli = false, optimize_duration = false; for (int i = 0; i < args.length; i++) { switch (args[i]) { @@ -13,6 +14,10 @@ public class AppLaser { cli = true; break; + case "--optimize-duration": + optimize_duration = true; + break; + default: System.out.println("Unknown argument " + args[i]); System.exit(0); @@ -159,6 +164,8 @@ public class AppLaser { universe.print(2, 4); + int start_time = (int) Instant.now().getEpochSecond(); + while (!universe.isSolved()) { if (universe.canEvolve(currentState)) { stack.push(currentState.copy(universe.possibleChoices(currentState))); @@ -174,11 +181,21 @@ public class AppLaser { } else { break; } + + if ((int) Instant.now().getEpochSecond() - start_time > 60 && optimize_duration == true) { + display_progress = false; + } + if ((int) Instant.now().getEpochSecond() - start_time > 2 * 60 && optimize_duration == true) { + display_regress = false; + } } System.out.println("\n\n"); + universe.print(universe_height + 6, 4); + System.out.println("\nSolved in " + ((int) Instant.now().getEpochSecond() - start_time) + " secconds"); + System.out.print("\033[?25h"); System.out.print("\nEnter anything to continue...."); scanner.nextInt(); diff --git a/Universe.java b/Universe.java index 967330b..e13590f 100644 --- a/Universe.java +++ b/Universe.java @@ -133,6 +133,16 @@ public class Universe { this.grid = newgrid; this.width = width; this.height = height; + + this.boxes_to_fill = 0; + + for (int i = 1; i < height - 1; i++) { + for (int j = 1; j < width - 1; j++) { + if (this.grid[i][j] == 0) { + this.boxes_to_fill ++; + } + } + } } public void changeUniverseStart(int pos_i, int pos_j, int dir) { diff --git a/makefile b/makefile index 1770321..b2096fa 100644 --- a/makefile +++ b/makefile @@ -4,4 +4,4 @@ build: run: javac --source 1.8 --target 1.8 AppLaser.java - java AppLaser -cli + java AppLaser -cli --optimize-duration