For the planner, we represent possible system states (not including the boat being in transit) with a list of the form [ w g c m ], where the items are 1 if loose on the right bank, -1 if loose on the left bank, and 0 if being carried by the man. The initial state is therefore [ 0 0 0 1 ].

The state representing success has everybody on the left (possibly being carried):

to-report acceptable [ state ] ;; everybody is on the left (possibly being carried)
report ((item 0 state <= 0) and (item 1 state <= 0) and
(item 2 state <= 0) and (item 3 state = -1))
end

On the other hand, a state is bad if the wolf and goat (or goat and cabbage) are loose on the same side of the river:

to-report bad [ state ] ;; wolf and goat loose together, or goat and cabbage loose together
report ((item 0 state = -1 and item 1 state = -1) or
(item 0 state = 1 and item 1 state = 1) or
(item 1 state = -1 and item 2 state = -1) or
(item 1 state = 1 and item 2 state = 1))
end

Our simple planner will keep track of the best goal list so far, with the empty list meaning “not yet.” The best out of two alternatives is therefore the shortest, excluding the case of the empty list:

The main planning function takes a state, a history of past states, a partial solution, and the best solution so far. If the state is illegal, or we are going back to it (i.e. we are looping), or if we cannot compete with the best solution so far, we report the best solution so far. If the state we have reached is an acceptable solution, we report the best of two solutions:

Otherwise, we explore all legal moves from the current state, including all the possible item drops. In each case we calculate a new state and a new partial solution, and update the best solution so far via a recursive call:

A wrapper function calls this planning function with the initial state, and adds some goals to tell the wolf and goat to stop eating after the final solution has been obtained (this ensures termination, with all goals being satisfied).

The final program is available at Modeling Commons. See also here for a video. The diagram below shows the system states explored by the planner, starting at the blue state and ending at the green one (the final “L” or “R” in state names marks the position of the man, lowercase “l” or “r” marks the position of loose items, and uppercase “W,” “G,” or “C” marks carried items). For more complex planning activities, it may be appropriate to interface NetLogo to external Java-based planning software, such as JavaFF.