Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.85 KB | None | 0 0
  1. go :- hypothesize(Animal),
  2. write('I guess that the animal is: '),
  3. write(Animal),
  4. nl,
  5. undo.
  6. hypothesize(jaguar)   :- jaguar, !.
  7. hypothesize(tiger)     :- tiger, !.
  8. hypothesize(dinosaur)   :- dinosaur, !.
  9. hypothesize(zebra)     :- zebra, !.
  10. hypothesize(ostrich)   :- ostrich, !.
  11. hypothesize(penguin)   :- penguin, !.
  12. hypothesize(falcon) :- falcon, !.
  13. hypothesize(unknown).
  14. jaguar :- mammal,
  15.          carnivore,
  16.          verify(has_tawny_color),
  17.          verify(has_dark_spots).
  18. tiger :- mammal,  
  19.        carnivore,
  20.        verify(has_tawny_color),
  21.        verify(has_black_stripes).
  22. dinosaur :- ungulate,
  23.          verify(has_long_neck),
  24.          verify(has_long_legs).
  25. zebra :- ungulate,  
  26.        verify(has_black_stripes).
  27. ostrich :- bird,  
  28.          verify(does_not_fly),
  29.          verify(has_long_neck).
  30. penguin :- bird,
  31.          verify(does_not_fly),
  32.          verify(swims),
  33.          verify(is_black_and_white).
  34. falcon :- bird,
  35.            verify(appears_in_desert),
  36.            verify(flys_well).
  37. mammal    :- verify(has_hair), !.
  38. mammal    :- verify(gives_milk).
  39. bird      :- verify(has_feathers), !.
  40. bird      :- verify(flys),
  41.            verify(lays_eggs).
  42. carnivore :- verify(eats_meat), !.
  43. carnivore :- verify(has_pointed_teeth),
  44.            verify(has_claws),
  45.            verify(has_forward_eyes).
  46. ungulate :- mammal,
  47.           verify(has_hooves), !.
  48. ungulate :- mammal,
  49.           verify(chews_cud).
  50. ask(Question) :-
  51.   write('Does the animal have the following attribute: '),
  52.   write(Question),
  53.   write('? '),
  54.   read(Response),
  55.   nl,
  56.   ( (Response == yes ; Response == y)
  57.     ->
  58.      assert(yes(Question)) ;
  59.      assert(no(Question)), fail).
  60.  
  61. :- dynamic yes/1,no/1.
  62. verify(S) :-
  63.  (yes(S)
  64.   ->
  65.   true ;
  66.   (no(S)
  67.    ->
  68.    fail ;
  69.    ask(S))).
  70. undo :- retract(yes(_)),fail.
  71. undo :- retract(no(_)),fail.
  72. undo.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement