MiniMax
This commit is contained in:
parent
a47a18939c
commit
628263d95b
|
@ -8,7 +8,7 @@
|
|||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
|
@ -5,14 +5,11 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Client.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/MiniMax.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/GameTree.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Player.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.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/MiniMax.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/MiniMax.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -52,6 +49,11 @@
|
|||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"last_opened_file_path": "/home/william/Dev/Projects/Uni/Log320/LOG320_Lab4",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
"node.js.selected.package.eslint": "(autodetect)",
|
||||
"node.js.selected.package.tslint": "(autodetect)",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}]]></component>
|
||||
|
@ -84,6 +86,7 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1679255648701</updated>
|
||||
<workItem from="1679255649975" duration="1223000" />
|
||||
<workItem from="1679261446095" duration="1908000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package laboratoire4;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class GameTree {
|
||||
private Node root;
|
||||
|
||||
public Node getRoot() {
|
||||
return root;
|
||||
}
|
||||
|
||||
static class Node {
|
||||
private final Collection<Node> childs;
|
||||
|
||||
Node(Collection<Node> childs) {
|
||||
this.childs = childs;
|
||||
}
|
||||
|
||||
public Collection<Node> getChilds() {
|
||||
return childs;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,49 @@
|
|||
package laboratoire4;
|
||||
|
||||
public enum Player {
|
||||
MIN,
|
||||
MAX
|
||||
public class MiniMax {
|
||||
private static final int MAX_DEPTH = 4;
|
||||
|
||||
public static int miniMax(GameTree tree) {
|
||||
return miniMax(tree.getRoot(), Player.MAX, 0);
|
||||
}
|
||||
|
||||
public class MiniMax {
|
||||
public static void miniMax(player)
|
||||
private static int miniMax(GameTree.Node node, Player player, int depth) {
|
||||
if (depth == MAX_DEPTH) {
|
||||
return evaluate(node);
|
||||
}
|
||||
|
||||
return player == Player.MAX ?
|
||||
max(node, depth) :
|
||||
min(node, depth);
|
||||
}
|
||||
|
||||
private static int max(GameTree.Node node, int depth) {
|
||||
int maxScore = Integer.MIN_VALUE;
|
||||
|
||||
for (GameTree.Node child : node.getChilds()) {
|
||||
int score = miniMax(child, Player.MIN, depth + 1);
|
||||
if (score > maxScore) {
|
||||
maxScore = score;
|
||||
}
|
||||
}
|
||||
|
||||
return maxScore;
|
||||
}
|
||||
|
||||
private static int min(GameTree.Node node, int depth) {
|
||||
int minScore = Integer.MAX_VALUE;
|
||||
|
||||
for (GameTree.Node child : node.getChilds()) {
|
||||
int score = miniMax(child, Player.MIN, depth + 1);
|
||||
if (score < minScore) {
|
||||
minScore = score;
|
||||
}
|
||||
}
|
||||
|
||||
return minScore;
|
||||
}
|
||||
|
||||
private static int evaluate(GameTree.Node node) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package laboratoire4;
|
||||
|
||||
public enum Player {
|
||||
MIN,
|
||||
MAX
|
||||
}
|
Loading…
Reference in New Issue