下面的代码应该输出:
A solution is:
The farmer takes the Goat from west of the river to east
The farmer crosses the river from east to west
The farmer takes the cabbage from west of the river to east
The farmer takes the Goat from east of the river to west
The farmer takes the Wolf from west of the river to east
The farmer crosses the river from east to west
The farmer takes the Goat from west of the river to east
No
但我收到以下错误,我似乎无法修复它。如果有人能引导我朝着正确的方向前进,我将不胜感激。
?- solve.
A solution is:
ERROR: write_move/2: Undefined procedure: write/4
ERROR: However, there are definitions for:
ERROR: write/1
ERROR: writeq/1
ERROR: write/2
ERROR: writeq/2
Exception: (10) write('The farmer takes the Goat from ', west, ' of the river to ', east) ?
代码:(部分)
write_move(state(X,W,G,C),state(Y,W,G,C)):- !,
write('The farmer crosses the river from ',X,' to ',Y), nl.
write_move(state(X,X,G,C),state(Y,Y,G,C)):- !,
write('The farmer takes the Wolf from ',X,' of the river to ',Y), nl.
write_move(state(X,W,X,C),state(Y,W,Y,C)):- !,
write('The farmer takes the Goat from ',X,' of the river to ',Y),nl.
write_move(state(X,W,G,X),state(Y,W,G,Y)):- !,
write('The farmer takes the cabbage from ',X,' of the river to ',Y),nl.
如果有人有兴趣,此代码的提示是:
描述:一个农民带着他的山羊、狼和卷心菜来到一条他们想渡过的河边。有一条船,但只能坐两个人,只有农夫会划船。如果山羊和卷心菜同时上船,卷心菜就会被吃掉。同样,如果没有农夫,狼和山羊在一起,山羊就会被吃掉。设计一系列的河流过境点,以便所有相关人员安全过河。