【问题标题】:Guess the right game for a user with prolog用 prolog 为用户猜出正确的游戏
【发布时间】:2012-05-26 16:19:45
【问题描述】:

我正在尝试制作一个程序,让用户回答问题以查找游戏,但我不明白如何使用列表和断言。我用过程点系统尝试了另一种方法。程序是这样的:

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。

我不明白为什么这种方式是错误的。如何使用 assert 或 list 执行此操作,以便找到得分最高的游戏并打印出来?

【问题讨论】:

    标签: list prolog prolog-assert


    【解决方案1】:

    这不是使用收回的正确方法。

    这样试试:

    retractall(yes(_))
    

    这将撤回所有答案

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多