Question

I am trying to make a program where the user answers questions to find a game, but I couldn't understand how to work with lists and assert. I tried another way with procedure pointsystem. The program is like this:

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. 

When I run the program the result is: ?- yeah. Please answer the questions to find the game which suite you! I guess that the game is : undefined true.

I can't understand why this way is wrong. How can I do this with assert or list so I can find the game with the biggest points and print it?

No correct solution

OTHER TIPS

That's not the right way to use retract.

try like that:

retractall(yes(_))

this will retract all answers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top