4. Consider the following well-known problem: In his yard, a farmer has a fox, a hen, and...
Question:
4. Consider the following well-known problem:
In his yard, a farmer has a fox, a hen, and a bushel of grain. The farmer must transfer all these things to a stall at the market, using only a cart which can carry at most one of them (plus himself) at a time. The problem is that if the farmer leaves the fox unattended with the hen, it will eat the hen. Similarly, if the hen is left unattended with the grain, it will eat the grain.
Is there a way for the farmer (without helpers) to transfer all three items to market without any of them getting eaten?
Use Prolog to solve this as a planning problem using the plan predicate. A state can be represented by a list with four elements, [fox, hen, grain, cart], where each of these elements is a location: either yard or market. (Assume that the farmer is always with the cart.) A move is either go_alone(loc) or go_with(item, loc)
where loc is a location and item is one of fox, hen, or grain. A move should not be legal if something will get eaten in the resulting state.
a. Define a predicate safe_state(s) that holds whenever s is a state where nothing will be eaten. So [yard,yard,market,yard] is considered to be a safe state, but [yard,market,market,yard] is not because the hen is with the grain unattended.
b. Define the predicate legal_move using the safe_state predicate.
c. Define initial_state and goal_state, and use the plan predicate to find a seven-step solution.
Step by Step Answer: