Three cannibals and three missionaries must cross a river. Their boat can only hold two people. If the cannibals outnumber the missionaries, on either side of the river, the missionaries are in trouble (I won't describe the results). Each missionary and each cannibal can row the boat. How can all six get across the river?
I can't find an algorithm for solving this problem using IDDFS (Iterative deepening depth-first search) and GreedyBFS (greedy best-first search). An idea on how to solve this would make me happy as well.
Edited:
I found an algorithm for IDDFS on wiki:
IDDFS(root, goal)
{
depth = 0
repeat
{
result = DLS(root, goal, depth)
if (result is a solution)
return result
depth = depth + 1
}
}
DLS(node, goal, depth)
{
if (depth == 0 and node == goal)
return node
else if (depth > 0)
for each child in expand(node)
DLS(child, goal, depth-1)
else
return no-solution
}
But I can't figure out what expand(node) in DLS() is supposed to accomplish in my problem. This is my Node class:
public class Node{
//x-no of missionaries
//y-no of cannibals
//z-position of boat
int x,y;
boolean z;
Node(int x,int y,boolean z){
this.x=x;
this.y=y;
this.z=z;
}
public int getM(){
return this.x;
}
public int getC(){
return this.y;
}
public boolean getB(){
return this.z;
}
public void setM(int x){
this.x=x;
}
public void setC(int y){
this.y=y;
}
public void setB(boolean z){
this.z=z;
}
}
I would appreciate any help.