Advertisement
Guest User

Untitled

a guest
Jan 14th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 5.80 KB | None | 0 0
  1. :- consult('getyesno.pl').  
  2.  
  3.  
  4. % Main control procedures
  5.  
  6.  
  7. start :-
  8.    write('Ten program sprobuje zgadnac postac z Dragon Ball, o ktorej pomyslisz.'),nl,
  9.    write('Na pytania odpowiadaj tylko T(Tak) lub N(Nie).'),nl,
  10.    clear_stored_answers,
  11.    try_all_possibilities.
  12.  
  13. try_all_possibilities :-     % Backtrack through all possibilities...
  14.    postac(D),
  15.    explain(D),
  16.    fail.
  17.  
  18. try_all_possibilities.       % ...then succeed with no further action.
  19.  
  20.  
  21.  
  22. % Diagnostic knowledge base
  23. %   (conditions under which to give each diagnosis)
  24.  
  25.  
  26. postac(bulma) :-
  27.     user_says(kobieta, yes),
  28.     user_says(geniusz, yes).
  29.    
  30. postac(c18) :-
  31.     user_says(kobieta, yes),
  32.     user_says(geniusz, no),
  33.     user_says(blondynka, yes).
  34.    
  35. postac(chi) :-
  36.     user_says(kobieta, yes),
  37.     user_says(geniusz, no),
  38.     user_says(blondynka, no),
  39.     user_says(ojciec, no).
  40.  
  41. postac(videl) :-
  42.     user_says(kobieta, yes),
  43.     user_says(geniusz, no),
  44.     user_says(blondynka, no),
  45.     user_says(ojciec, yes).
  46.  
  47. postac(goku) :-
  48.     user_says(kobieta, no),
  49.     user_says(ziemianin, no),
  50.     user_says(lysy, no),
  51.     user_says(blizna, no),
  52.     user_says(wlosy, yes),
  53.     user_says(nerwy, no),
  54.     user_says(madry, no).
  55.  
  56. postac(gohan) :-
  57.     user_says(kobieta, no),
  58.     user_says(ziemianin, no),
  59.     user_says(lysy, no),
  60.     user_says(blizna, no),
  61.     user_says(wlosy, yes),
  62.     user_says(nerwy, no),
  63.     user_says(madry, yes).
  64.  
  65. postac(vegeta) :-
  66.     user_says(kobieta, no),
  67.     user_says(ziemianin, no),
  68.     user_says(lysy, no),
  69.     user_says(blizna, no),
  70.     user_says(wlosy, yes),
  71.     user_says(nerwy, yes).
  72.    
  73. postac(raditz) :-
  74.     user_says(kobieta, no),
  75.     user_says(ziemianin, no),
  76.     user_says(lysy, no),
  77.     user_says(blizna, no),
  78.     user_says(wlosy, no).
  79.    
  80. postac(c17) :-
  81.     user_says(kobieta, no),
  82.     user_says(ziemianin, yes),
  83.     user_says(lysy, no),
  84.     user_says(blizna, no),
  85.     user_says(wlosy, no).
  86.    
  87. postac(yamcha) :-
  88.     user_says(kobieta, no),
  89.     user_says(ziemianin, yes),
  90.     user_says(lysy, no),
  91.     user_says(blizna, yes).
  92.  
  93. postac(tenshinhan) :-
  94.     user_says(kobieta, no),
  95.     user_says(ziemianin, yes),
  96.     user_says(lysy, yes),
  97.     user_says(oko, yes).
  98.    
  99. postac(roshi) :-
  100.     user_says(kobieta, no),
  101.     user_says(ziemianin, yes),
  102.     user_says(lysy, yes),
  103.     user_says(oko, no),
  104.     user_says(okulary, yes).
  105.    
  106. postac(kuririn) :-
  107.     user_says(kobieta, no),
  108.     user_says(ziemianin, yes),
  109.     user_says(lysy, yes),
  110.     user_says(oko, no),
  111.     user_says(okulary, no).
  112.  
  113. postac(freeza) :-
  114.     user_says(kobieta, no),
  115.     user_says(ziemianin, no),
  116.     user_says(lysy, yes),
  117.     user_says(armia, yes).
  118.    
  119. postac(piccolo) :-
  120.     user_says(kobieta, no),
  121.     user_says(ziemianin, no),
  122.     user_says(lysy, yes),
  123.     user_says(armia, no),
  124.     user_says(zielony, yes),
  125.     user_says(ogon, no).
  126.    
  127. postac(cell) :-
  128.     user_says(kobieta, no),
  129.     user_says(ziemianin, no),
  130.     user_says(lysy, yes),
  131.     user_says(armia, no),
  132.     user_says(zielony, yes),
  133.     user_says(ogon, yes).
  134.    
  135. postac(buu) :-
  136.     user_says(kobieta, no),
  137.     user_says(ziemianin, no),
  138.     user_says(lysy, yes),
  139.     user_says(armia, no),
  140.     user_says(zielony, no).
  141.  
  142. %
  143. % Case knowledge base
  144. %   (information supplied by the user during the consultation)
  145. %
  146.  
  147. :- dynamic(stored_answer/2).
  148.  
  149.    % (Clauses get added as user answers questions.)
  150.  
  151.  
  152. %
  153. % Procedure to get rid of the stored answers
  154. % without abolishing the dynamic declaration
  155. %
  156.  
  157. clear_stored_answers :- retract(stored_answer(_,_)),fail.
  158. clear_stored_answers.
  159.  
  160.  
  161. %
  162. % Procedure to retrieve the user's answer to each question when needed,
  163. % or ask the question if it has not already been asked
  164. %
  165.  
  166. user_says(Q,A) :- stored_answer(Q,A).
  167.  
  168. user_says(Q,A) :- \+ stored_answer(Q,_),
  169.                   nl,nl,
  170.                   ask_question(Q),
  171.                   get_yes_or_no(Response),
  172.                   asserta(stored_answer(Q,Response)),
  173.                   Response = A.
  174.  
  175.  
  176. %
  177. % Texts of the questions
  178. %
  179.  
  180. ask_question(kobieta) :-
  181.    write('Czy twoja postac jest kobieta?'),nl.
  182.  
  183. ask_question(geniusz) :-
  184.    write('Czy twoja postac jest geniuszem?'),nl.
  185.  
  186. ask_question(blondynka) :-
  187.    write('Czy twoja postac jest blondynka?'),nl.
  188.  
  189. ask_question(ojciec) :-
  190.    write('Czy twoja postac ma slawnego ojca?'),nl.
  191.  
  192. ask_question(ziemianin) :-
  193.    write('Czy twoja postac jest ziemianinem?'),nl.
  194.  
  195. ask_question(lysy) :-
  196.    write('Czy twoja postac jest lysa?'),nl.
  197.  
  198. ask_question(blizna) :-
  199.    write('Czy twoja postac ma na twarzy blizne?'),nl.
  200.    
  201. ask_question(wlosy) :-
  202.    write('Czy twoja postac potrafi zmieniac kolor swoich wlosow?'),nl.
  203.    
  204. ask_question(nerwy) :-
  205.    write('Czy twoja postac latwo sie denerwuje?'),nl.
  206.    
  207. ask_question(madry) :-
  208.    write('Czy twoja postac jest madra?'),nl.
  209.    
  210. ask_question(oko) :-
  211.    write('Czy twoja postac ma trzecie oko?'),nl.
  212.    
  213. ask_question(okulary) :-
  214.    write('Czy twoja postac nosi okulary?'),nl.
  215.    
  216. ask_question(armia) :-
  217.    write('Czy twoja postac dowodzi armia?'),nl.
  218.    
  219. ask_question(zielony) :-
  220.    write('Czy twoja postac jest zielona?'),nl.
  221.  
  222. ask_question(ogon) :-
  223.    write('Czy twoja postac ma ogon?'),nl.
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231. %
  232. %  Explanations for the various diagnoses
  233. %
  234.  
  235. explain(bulma) :-
  236.     nl,
  237.     write('Bulma'),nl.
  238.  
  239. explain(c18) :-
  240.     nl,
  241.     write('C18'),nl.
  242.    
  243. explain(chi) :-
  244.     nl,
  245.     write('Chi Chi'),nl.
  246.    
  247. explain(videl) :-
  248.     nl,
  249.     write('Videl'),nl.
  250.  
  251. explain(goku) :-
  252.     nl,
  253.     write('Son Goku'),nl.
  254.  
  255. explain(gohan) :-
  256.     nl,
  257.     write('Gohan'),nl.
  258.    
  259. explain(vegeta) :-
  260.     nl,
  261.     write('Vegeta'),nl.
  262.    
  263. explain(raditz) :-
  264.     nl,
  265.     write('Raditz'),nl.
  266.    
  267. explain(c17) :-
  268.     nl,
  269.     write('C17'),nl.
  270.    
  271. explain(yamcha) :-
  272.     nl,
  273.     write('Yamcha'),nl.
  274.  
  275. explain(tenshinhan) :-
  276.     nl,
  277.     write('Tenshinhan'),nl.
  278.    
  279. explain(roshi) :-
  280.     nl,
  281.     write('Muten Roshi').
  282.  
  283. explain(kuririn) :-
  284.     nl,
  285.     write('Kuririn'),nl.
  286.    
  287. explain(freeza) :-
  288.     nl,
  289.     write('Freeza'),nl.
  290.    
  291. explain(piccolo) :-
  292.     nl,
  293.     write('Piccolo'),nl.
  294.  
  295. explain(cell) :-
  296.     nl,
  297.     write('Cell'),nl.
  298.  
  299. explain(buu) :-
  300.     nl,
  301.     write('Majin Buu'),nl.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement