0

I'm trying to write a game in which the program reads through a database, grabs attributes and asks the player if the Movie that the player is thinking of will have that attribute. The user will answer either yes or no and if yes, the game will ask about the next attribute until either the user has said yes to every attribute, at that point the program will output the name of the movie. Or if the user says no, the game will then move along to the next movie in the database and start asking about those attributes.

The game ends when either it finds a movie with all the attributes or there are no more movies in the database in which the program could ask about.

Here is the database file.

object_properties(crocodile_dundee,[comedy,australian,paul_hogan_movie]).
object_properties(flipper,[action_movie,australian, paul_hogan_movie,
-comedy]).
object_properties(jackass,[comedy,-australian]).
object_properties(the_godfather,[drama,crime,-character_batman]).
object_properties(the_dark_knight,[drama,crime,character_batman]).
object_properties(the_living_planet, [documentary,director_attenborough]).
object_properties(the_code, [documentary,nerds_love_it]).
object_properties(the_russian_revolution, [documentary,about_history]).

Here is my game file.

go():-  

guess_object(0,[]).
guess_object(Obj,[A|As]) :- 
    object_categories(Obj,A).

guess_object(1).
guess_object(2).
guess_object(3).
guess_object(4).
guess_object(5).  %how do i do this specifically for the current Obj attributes?

guess(X) :- guess_object(_, X), 
    writeln('Does your object have the attribute '(X)'?'), 
    read(Input), Input=('yes') -> assert(object(X)) ; retractall(X), guess(X).

writeln('I guess that the film is: 'guess_object(Obj,_).

The main questions I have:

  1. How do I split the object attributes in to a list like I'm trying to do on guess_object(1) through to guess_object(5) depending on whether the object has 2 attributes or 4 attributes, etc.

  2. How do I make my guess(A) predicate recursive so once the user says no it will then go to the next object in the database file?

I'm not too great at prolog but any advice or pointers would be greatly appreciated, even if it's just pointing out a stupid mistake I may have made. I will also answer any questions anyone has to the best of my ability.

janisz
  • 6,292
  • 4
  • 37
  • 70
Herblore
  • 1
  • 3
  • No one can help me? :( – Herblore Nov 10 '13 at 02:55
  • I'm not sure I undestand what are you trying to do in your code. Could you please provide sample input and output of predicates that you created and of the whole program? I don't undestand what you're trying to achieve in 1) and about 2) you can use `repeat/0` or other loop constructs. – Grzegorz Adam Kowalski Apr 27 '14 at 09:26
  • possible duplicate of [Splitting list and iterating in prolog](http://stackoverflow.com/questions/19886637/splitting-list-and-iterating-in-prolog) – janisz Jan 08 '15 at 20:33

0 Answers0