This is the Cannibals and Missionaries AI problem.

Here's the design document. The Source