Information Technology Reference
In-Depth Information
In this variant, a state can be represented using a list [ b , m , l , o , h , s , c ] , which
has two more components than the list in section 9.2.4: s stands for the current
location of the stick, and c is y or n according to whether or not the monkey
is carrying the stick. The actions available are climb_on , climb_off , go (
)
x
, and
push (
, as before, and three new actions involving the stick: pick_up_stick ,
drop_stick , and swing_stick . (The grab action is omitted, since it no longer
accomplishes anything.)
Formulate this version of the problem in Prolog and use the plan predicate to
find a seven-step sequence of actions the monkey can do to get the bananas.
You will need to write clauses for the initial state and goal state, as well as
legal_move clauses for each of the actions. For the first four actions, you can
adapt the solution presented in section 9.2.4, but note that you now have to
worry about the state of the stick. For example, going to a location changes the
location of the stick if the monkey happens to be carrying it.
)
x
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 (
)
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.
loc
)
or go_with (
item , loc
Define a predicate safe_state (
)
a.
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.
s
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.
 
Search WWH ::




Custom Search