diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index c42e22d..f51e524 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,22 +4,11 @@
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
@@ -202,7 +191,14 @@
1681061194019
-
+
+ 1681237323963
+
+
+
+ 1681237323963
+
+
@@ -215,7 +211,8 @@
-
+
+
diff --git a/src/main/java/laboratoire4/Main.java b/src/main/java/laboratoire4/Main.java
index b27a322..73d1728 100644
--- a/src/main/java/laboratoire4/Main.java
+++ b/src/main/java/laboratoire4/Main.java
@@ -1,9 +1,27 @@
package laboratoire4;
-import java.io.IOException;
+import java.util.Scanner;
public class Main {
- public static void main(String[] args) throws IOException {
- new Client("localhost", 8888).listen();
+ public static void main(String[] args) {
+ Scanner scanner = new Scanner(System.in);
+
+ while (true) {
+ try {
+ new Client("localhost", 8888).listen();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ System.out.print("Recommencer? (Y/n) ");
+
+ if (scanner.hasNextLine()) {
+ String nextLine = scanner.nextLine();
+
+ if (nextLine.equals("n")) {
+ System.exit(0);
+ }
+ }
+ }
}
}
diff --git a/src/main/java/laboratoire4/strategies/DefenseStrategy.java b/src/main/java/laboratoire4/strategies/DefenseStrategy.java
index ddd656c..88d7e2e 100644
--- a/src/main/java/laboratoire4/strategies/DefenseStrategy.java
+++ b/src/main/java/laboratoire4/strategies/DefenseStrategy.java
@@ -33,12 +33,6 @@ public class DefenseStrategy extends MiniMaxStrategy {
}
return super.getNextMove(game);
-// EvaluationResult result = super.getNextMove(game);
-// if (Math.abs(result.getRow() - game.getPlayer().getHome()) > DEFENSE_DISTANCE_FROM_HOME) {
-// return null;
-// }
-//
-// return result;
}
@Override
diff --git a/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java b/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java
index 7dfe213..fb40606 100644
--- a/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java
+++ b/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java
@@ -13,8 +13,10 @@ import java.util.Collection;
public abstract class MiniMaxStrategy implements Strategy {
private static final int MAX_DEPTH = 6;
+ private static final long MAX_TIME_MS = 4500; // Moins de 5 secondes, car le tour n'est pas complètement fini
protected SimulatedGame game;
+ protected long startTimeMs;
@Override
public EvaluationResult getNextMove(Game game) {
@@ -26,6 +28,7 @@ public abstract class MiniMaxStrategy implements Strategy {
EvaluationResult maxResult = null;
int maxScore = Integer.MIN_VALUE;
+ startTimeMs = System.currentTimeMillis();
for (Action action : getActions(true)) {
int score = min(0, Integer.MIN_VALUE, Integer.MAX_VALUE);
@@ -44,6 +47,10 @@ public abstract class MiniMaxStrategy implements Strategy {
return evaluate();
}
+ if (System.currentTimeMillis() - startTimeMs > MAX_TIME_MS) {
+ return Integer.MIN_VALUE;
+ }
+
int maxScore = Integer.MIN_VALUE;
for (Action action : getActions(true)) {
@@ -71,6 +78,10 @@ public abstract class MiniMaxStrategy implements Strategy {
return evaluate();
}
+ if (System.currentTimeMillis() - startTimeMs > MAX_TIME_MS) {
+ return Integer.MAX_VALUE;
+ }
+
int minScore = Integer.MAX_VALUE;
for (Action action : getActions(false)) {