Commit 9e46c457 authored by jak.moore's avatar jak.moore

Commit

parent 57755e03
...@@ -10,7 +10,7 @@ public class GameState { ...@@ -10,7 +10,7 @@ public class GameState {
public boolean isRaftOnLeftBank; public boolean isRaftOnLeftBank;
// Constructor for GameState class // Constructor for GameState class
public GameState(ArrayList<Integer> left, ArrayList<Integer> right, ArrayList<Integer> raftContents, boolean raftBank) { GameState(ArrayList<Integer> left, ArrayList<Integer> right, ArrayList<Integer> raftContents, boolean raftBank) {
leftBank = left; leftBank = left;
rightBank = right; rightBank = right;
...@@ -20,7 +20,6 @@ public class GameState { ...@@ -20,7 +20,6 @@ public class GameState {
} }
// Return a clone of a Game state object // Return a clone of a Game state object
@SuppressWarnings("unchecked")
public GameState cloneObject() { public GameState cloneObject() {
ArrayList<Integer> lbClone, rbClone, raftClone; ArrayList<Integer> lbClone, rbClone, raftClone;
...@@ -30,10 +29,8 @@ public class GameState { ...@@ -30,10 +29,8 @@ public class GameState {
rbClone = (ArrayList<Integer>) leftBank.clone(); rbClone = (ArrayList<Integer>) leftBank.clone();
raftClone = (ArrayList<Integer>) raft.clone(); raftClone = (ArrayList<Integer>) raft.clone();
// Creating a new, cloned object to return // Returning new cloned game state object
GameState clone = new GameState(lbClone, rbClone, raftClone, isRaftOnLeftBank); return new GameState(lbClone, rbClone, raftClone, isRaftOnLeftBank);
return clone;
} }
......
...@@ -2,37 +2,41 @@ import java.util.ArrayList; ...@@ -2,37 +2,41 @@ import java.util.ArrayList;
public class Main { public class Main {
// Boolean to check whether problem is complete
private static boolean planCompleted = false; private static boolean planCompleted = false;
public static void main(String[] args) { public static void main(String[] args) {
// Starting game state // Starting game state
@SuppressWarnings("unchecked")
ArrayList<Integer> lBank = new ArrayList() { /*
Arrays empty for now, will hold default game state
*/
ArrayList<Integer> lBank = new ArrayList<Integer>() {
}; };
@SuppressWarnings("unchecked")
ArrayList<Integer> rBank = new ArrayList() { ArrayList<Integer> rBank = new ArrayList<Integer>() {
}; };
@SuppressWarnings("unchecked")
ArrayList<Integer> raft = new ArrayList() { ArrayList<Integer> raft = new ArrayList<Integer>() {
}; };
// Instantiating a new Game State object // Instantiating a new Game State object
GameState gs = new GameState(lBank, rBank, raft, true); GameState gs = new GameState(lBank, rBank, raft, true);
// Closed list // Closed list
ArrayList<GameState> closedList = new ArrayList(); ArrayList<GameState> closedList = new ArrayList<>();
// Array list to hold game states // Array list to hold game states
ArrayList<GameState> newStates = new ArrayList<>();
@SuppressWarnings("unchecked") // Defining array list to be the frontier and adding the first node to it
ArrayList<GameState> newStates = new ArrayList(); ArrayList<Node> frontier = new ArrayList<>();
ArrayList<Node> frontier = new ArrayList();
frontier.add(new Node(Actions.VOID, gs)); frontier.add(new Node(Actions.VOID, gs));
for (;;) {
while (true) {
Node firstNode = frontier.get(0); Node firstNode = frontier.get(0);
...@@ -68,7 +72,7 @@ public class Main { ...@@ -68,7 +72,7 @@ public class Main {
private static ArrayList<Actions> getActions(GameState gs) { private static ArrayList<Actions> getActions(GameState gs) {
// Array list to hold possible actions // Array list to hold possible actions
ArrayList<Actions> possibleActions = new ArrayList(); ArrayList<Actions> possibleActions = new ArrayList<>();
// Counters to hold game information // Counters to hold game information
int wolvesOnLBank = 0; int wolvesOnLBank = 0;
...@@ -273,7 +277,7 @@ public class Main { ...@@ -273,7 +277,7 @@ public class Main {
} }
// Goal test method // Goal test method
public static boolean goalTest(GameState gs) { private static boolean goalTest(GameState gs) {
int lengthR = gs.rightBank.size(); int lengthR = gs.rightBank.size();
int lengthL = gs.leftBank.size(); int lengthL = gs.leftBank.size();
......
public class Node { public class Node {
Node parent; public Node parent;
GameState gs; public GameState gs;
// Constructor for class
public Node(Actions actionTaken, GameState gs) { public Node(Actions actionTaken, GameState gs) {
this.gs = gs; this.gs = gs;
} }
// Set parent node
public void setParent(Node parent) { public void setParent(Node parent) {
this.parent = 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