This commit is contained in:
FyloZ 2023-03-19 18:02:45 -04:00
parent a47a18939c
commit 628263d95b
Signed by: william
GPG Key ID: 835378AE9AF4AE97
5 changed files with 86 additions and 15 deletions

View File

@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -5,14 +5,11 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment=""> <list default="true" id="41395b4b-3252-492c-a869-5f4dab107186" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/GameTree.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/encodings.xml" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/main/java/laboratoire4/Player.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change 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" />
<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" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -52,6 +49,11 @@
"RunOnceActivity.OpenProjectViewOnStart": "true", "RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true", "RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "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" "vue.rearranger.settings.migration": "true"
} }
}]]></component> }]]></component>
@ -84,6 +86,7 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1679255648701</updated> <updated>1679255648701</updated>
<workItem from="1679255649975" duration="1223000" /> <workItem from="1679255649975" duration="1223000" />
<workItem from="1679261446095" duration="1908000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -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;
}
}
}

View File

@ -1,10 +1,49 @@
package laboratoire4; package laboratoire4;
public enum Player {
MIN,
MAX
}
public class MiniMax { public class MiniMax {
public static void miniMax(player) private static final int MAX_DEPTH = 4;
public static int miniMax(GameTree tree) {
return miniMax(tree.getRoot(), Player.MAX, 0);
}
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) {
}
} }

View File

@ -0,0 +1,6 @@
package laboratoire4;
public enum Player {
MIN,
MAX
}