CS123, Intro to AI
The ProblemThe SolutionState Representation:Initial StateGoal StateState TransitionsSolution PathState Space and TransitionsExplanation of Steps
Three humans and three zombies are on one side of a river. They all need to get to the other side. There is one rowboat.
The boat can only carry two of them for each crossing.
At least one of them has to be in the boat to row it.
Only the boat can be used to cross the river (no wading or swimming).
If the zombies on either side of the river outnumber the humans, they will kill them.
This solution was generated by ChatGPT using the GPT 4o model on 6/26/2024. There were numerous errors in the notation, which I cleaned up, and I rewrote much of the explanation, but the solution was correct.
Each state can be represented as a tuple (H, Z, B), where:
H is the number of humans on the starting bank.
Z is the number of zombies on the starting bank.
B indicates the position of the boat (1 for starting bank, 0 for the other bank).
We only need to keep track of the number of individuals on the starting bank, since we know that if they are not on the starting bank, they are on the other bank.
(3, 3, 1) All the individuals and the boat are on the starting bank.
(0, 0, 0) All of the individuals and the boat are on the other bank.
Possible transitions are based on moving 1 or 2 individuals across the river. Here are the legal transitions:
(H, Z, 1 ) → (H−1, Z, 0) if one human crosses.
(H, Z, 1) → (H−2, Z, 0) if two humans cross.
(H, Z, 1) → (H, Z−1, 0) if one zombie crosses.
(H, Z, 1) → (H, Z−2, 0) if two zombies cross.
(H, Z, B) → (H−1, Z−1, 0) if one human and one zombie cross.
There are five more legal transitions going in the opposite direction.
All transitions must respect the constraints: at no point should zombies outnumber humans on either bank.
We can use Breadth-First Search (BFS) to find the shortest path from the initial state to the goal state. Here is a step-by-step solution:
Initial state: (3, 3, 1)
Move two zombies: (3, 1, 0)
Move one zombie back: (3, 2, 1)
Move two zombies: (3,0,0)
Move one zombie back: (3, 1, 1)
Move two humans: (1, 1, 0)
Move one zombie and one human back: (2, 2, 1)
Move two humans: (0, 2, 0)
Move one zombie back: (0, 3, 1)
Move two zombies: (0,1,0)
Move one zombie back: (0,2,1)
Move two zombies: (0,0,0)
There are many possible solutions, but the shortest solution requires just eleven one-way trips across the river. Note that there is more than one solution with 11 one-way trips.
xxxxxxxxxx
(3, 3, 1)
-> (3, 1, 0)
-> (3, 2, 1)
-> (3, 0, 0)
-> (3, 1, 1)
-> (1, 1, 0)
-> (2, 2, 1)
-> (0, 2, 0)
-> (0, 3, 1)
-> (0, 1, 0)
-> (0, 2, 1)
-> (0, 0, 0)
Initial state: All humans and zombies are on the starting bank.
Move two zombies: Reduces risk of outnumbering on the other bank.
Move one zombie back: Ensures boat returns without imbalance.
Move two zombies: Ensures safety and moves towards the goal.
Move one zombie back: Prepares boat for next safe crossing.
Move two humans: Starts balancing out humans.
Move one zombie and one human back: Balances both banks.
Move two humans: Nears completion by safely moving humans.
Move one zombie back: Prepares final safe moves.
Move two zombies: Moves towards goal with balance.
Move one zombie back: Ensures safe final state.
Move two zombies: Reaches the goal state with everyone safe.
This step-by-step method ensures that at no point are the humans outnumbered by the zombies on either bank, thus solving the problem.
Intro to AI course materials by Brian Bird, written in , are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.