/* SolveMissCann.java Author: Laura Toma Description: This is the skeleton for the solution to the missionaries and cannibals problem. The idea is to generate all possible next moves from a current state and keep track of all states generated so far using a queue. Initially the queue contains the initial state. The search dequeues the first state from the queue, generates all possible moves state, and adds the resulting legal states to the end of the queue. The search stops when hitting a state that is "final". Comments: Note we do not ever check to see if we encountered a state before. So we can generate loops and possibly an infinite search. Why does this work? What happens if we use a stack instead of a queue? */ import java.util.LinkedList; public class SolveMissCan { public SolveMissCan () { //create queue that will be used for search LinkedList stateQueue = new LinkedList(); //initial state of the world QueueNode current = new QueueNode(3, 0, 3, 0, 1, 0, "Start state "); //put initial state in the queue stateQueue.add(current); while (!stateQueue.isEmpty()) { current = stateQueue.removeFirst(); if (current.isDone()) break; //exit the loop, we found the solution //otherwise, keep testing: generate all possible moves //from the current state, and add the ones that are legal //to the queue //FILL IN THE CODE } } // Main entry point static public void main(String[] args) { new SolveMissCan(); } }