Commit 57755e03 authored by jak.moore's avatar jak.moore

New updates from home

parents 0fe4a9e0 70e39fec
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/artificial-intelligence.iml" filepath="$PROJECT_DIR$/artificial-intelligence.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
......@@ -6,6 +6,7 @@ public enum Actions {
WOLF_LEFT_TO_BOAT, WOLF_RIGHT_TO_BOAT,
WOLF_BOAT_TO_LEFT, WOLF_BOAT_TO_RIGHT,
CHICKEN_RIGHT_TO_BOAT, CHICKEN_LEFT_TO_BOAT,
CHICKEN_BOAT_TO_RIGHT, CHICKEN_BOAT_TO_LEFT
CHICKEN_BOAT_TO_RIGHT, CHICKEN_BOAT_TO_LEFT, VOID
}
......@@ -2,7 +2,7 @@ import java.util.ArrayList;
public class Main {
private boolean planCompleted = false;
private static boolean planCompleted = false;
public static void main(String[] args) {
......@@ -20,20 +20,45 @@ public class Main {
// Instantiating a new Game State object
GameState gs = new GameState(lBank, rBank, raft, true);
// Invoking get actions method and storing the results in an array list
ArrayList<Actions> validActions = getActions(gs);
// Closed list
ArrayList<GameState> closedList = new ArrayList();
// Array list to hold game states
@SuppressWarnings("unchecked")
ArrayList<GameState> newStates = new ArrayList();
// Iterate through valid actions simulating their game state
for (Actions a : validActions) {
ArrayList<Node> frontier = new ArrayList();
frontier.add(new Node(Actions.VOID, gs));
while (true) {
Node firstNode = frontier.get(0);
if (goalTest(firstNode.gs)) {
System.out.print("COMPLETE");
planCompleted = true;
}
ArrayList<Actions> validActions = getActions(firstNode.gs);
// Iterate through valid actions simulating their game state
for (Actions a : validActions) {
gs = Simulate(gs, a);
gs = Simulate(firstNode.gs, a);
// Storing possible game states in array list
newStates.add(gs);
if (!closedList.contains(gs)) {
// Storing possible game states in frontier
frontier.add(new Node(a, gs));
}
}
closedList.add(firstNode.gs);
}
......@@ -43,7 +68,7 @@ public class Main {
private static ArrayList<Actions> getActions(GameState gs) {
// Array list to hold possible actions
ArrayList<Actions> possibleActions = new ArrayList<>();
ArrayList<Actions> possibleActions = new ArrayList();
// Counters to hold game information
int wolvesOnLBank = 0;
......@@ -57,7 +82,9 @@ public class Main {
// Getting current state of game
if (gs.raft.size() > 1) {
raftFull = true;
}
for (int i : gs.leftBank) {
......@@ -242,10 +269,11 @@ public class Main {
}
return gs;
}
// Goal test method
public boolean goalTest(GameState gs) {
public static boolean goalTest(GameState gs) {
int lengthR = gs.rightBank.size();
int lengthL = gs.leftBank.size();
......@@ -297,7 +325,7 @@ public class Main {
}
// Check final counts
private boolean completed(int wolves, int chickens) {
private static boolean completed(int wolves, int chickens) {
if ((wolves == 3) && (chickens == 3)) {
......@@ -307,7 +335,9 @@ public class Main {
} else {
return false;
}
}
}
\ No newline at end of file
public class Node {
Node parent;
GameState gs;
public Node(Actions actionTaken, GameState gs) {
this.gs = gs;
}
public void setParent(Node parent) {
this.parent = parent;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment