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

Commit

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