Limite la longueur d'un coup sous les 5 secondes
This commit is contained in:
parent
eb0146f10a
commit
7416df8a17
|
@ -4,22 +4,11 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="Beaucoup de changements">
|
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="Gitignore">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Client.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Main.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/IPawn.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/IPawn.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/Pawn.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/Pawn.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/PawnUtils.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/PawnUtils.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/Pushed.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/Pushed.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/Pusher.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/pawns/Pusher.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/AttackStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/AttackStrategy.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/DefenseStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/DefenseStrategy.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/DefenseStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/DefenseStrategy.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/ImmediateDefenseStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/ImmediateDefenseStrategy.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/MasterStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/MasterStrategy.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/MiniMaxStrategy.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/StartingStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/RandomStrategy.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/Strategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/Strategy.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/WinningStrategy.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/strategies/WinningStrategy.java" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<list id="98b8a79f-2f53-42bf-96da-7af322697a0d" name="Changes by acastonguay" comment="" />
|
<list id="98b8a79f-2f53-42bf-96da-7af322697a0d" name="Changes by acastonguay" comment="" />
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
@ -202,7 +191,14 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1681061194019</updated>
|
<updated>1681061194019</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="8" />
|
<task id="LOCAL-00008" summary="Gitignore">
|
||||||
|
<created>1681237323963</created>
|
||||||
|
<option name="number" value="00008" />
|
||||||
|
<option name="presentableId" value="LOCAL-00008" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1681237323963</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="9" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
@ -215,7 +211,8 @@
|
||||||
<MESSAGE value="Fixes?" />
|
<MESSAGE value="Fixes?" />
|
||||||
<MESSAGE value="Plus d'heuristiques" />
|
<MESSAGE value="Plus d'heuristiques" />
|
||||||
<MESSAGE value="Beaucoup de changements" />
|
<MESSAGE value="Beaucoup de changements" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Beaucoup de changements" />
|
<MESSAGE value="Gitignore" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Gitignore" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
|
|
|
@ -1,9 +1,27 @@
|
||||||
package laboratoire4;
|
package laboratoire4;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) {
|
||||||
new Client("localhost", 8888).listen();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,12 +33,6 @@ public class DefenseStrategy extends MiniMaxStrategy {
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.getNextMove(game);
|
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
|
@Override
|
||||||
|
|
|
@ -13,8 +13,10 @@ import java.util.Collection;
|
||||||
|
|
||||||
public abstract class MiniMaxStrategy implements Strategy {
|
public abstract class MiniMaxStrategy implements Strategy {
|
||||||
private static final int MAX_DEPTH = 6;
|
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 SimulatedGame game;
|
||||||
|
protected long startTimeMs;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EvaluationResult getNextMove(Game game) {
|
public EvaluationResult getNextMove(Game game) {
|
||||||
|
@ -26,6 +28,7 @@ public abstract class MiniMaxStrategy implements Strategy {
|
||||||
|
|
||||||
EvaluationResult maxResult = null;
|
EvaluationResult maxResult = null;
|
||||||
int maxScore = Integer.MIN_VALUE;
|
int maxScore = Integer.MIN_VALUE;
|
||||||
|
startTimeMs = System.currentTimeMillis();
|
||||||
|
|
||||||
for (Action<IPawn> action : getActions(true)) {
|
for (Action<IPawn> action : getActions(true)) {
|
||||||
int score = min(0, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
int score = min(0, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||||
|
@ -44,6 +47,10 @@ public abstract class MiniMaxStrategy implements Strategy {
|
||||||
return evaluate();
|
return evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - startTimeMs > MAX_TIME_MS) {
|
||||||
|
return Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
int maxScore = Integer.MIN_VALUE;
|
int maxScore = Integer.MIN_VALUE;
|
||||||
|
|
||||||
for (Action<IPawn> action : getActions(true)) {
|
for (Action<IPawn> action : getActions(true)) {
|
||||||
|
@ -71,6 +78,10 @@ public abstract class MiniMaxStrategy implements Strategy {
|
||||||
return evaluate();
|
return evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - startTimeMs > MAX_TIME_MS) {
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
int minScore = Integer.MAX_VALUE;
|
int minScore = Integer.MAX_VALUE;
|
||||||
|
|
||||||
for (Action<IPawn> action : getActions(false)) {
|
for (Action<IPawn> action : getActions(false)) {
|
||||||
|
|
Loading…
Reference in New Issue