我正在尝试创建一个用户回答问题以找到游戏的程序,但我无法理解如何使用列表和断言。我用程序点系统尝试了另一种方法。该计划是这样的:
yeah:-
write('Please answer the questions to find the game which suite you!'),
nl,
find(Game),
nl,
write('I guess that the game is :'),
nl,
write(Game),
undo.
find(assassinsCreedII ) :-
assassinsCreedII(assassins).
find(sims3) :-
sims3.
find(undefined).
points(G) :-
X=0,
( (G == assassins) ->
(( X = X + 1),
print(X));
Y=0,
(G == sims3) ->
(Y = Y + 1)).
assassinsCreedII(assassins) :-
actionGame(assassins),
adventureGame(assassins).
sims3 :-
simulationGame(sims).
actionGame(name) :-
test(do_you_like_action_games,name ).
adventureGame(name) :-
test(do_you_like_adventure_games,name).
simulationGame(N) :-
test(do_you_like_simulation_games,N ).
requisition(Question,Name) :-
write(Question),
write('?'),
read(Answer),
nl,
( (Answer==yes ; Answer==y )
->
assert(yes(Question))
;
assert(no(Question)),
fail
),
points(Name).
:- dynamic yes/1,no/1.
test(Q,Name) :-
( yes(Q) ->
true;
( no(Q)
-> fail
; requisition(Q,Name)
)
).
undo :-
retract(yes()),fail.
undo :-
retract(no()), fail.
undo.
当我运行程序时,结果是: ? - 是的 请回答问题,找到适合你的游戏!我猜游戏是:undefined true。
我无法理解为什么这种方式是错误的。如何使用断言或列表来执行此操作,以便找到具有最高分的游戏并打印出来?
答案 0 :(得分:0)
这不是使用缩进的正确方法。
尝试:
retractall(yes(_))
这将收回所有答案