headline:- wn('% --------------------------------------'), wn('% プロローグによるミニ・クイズシステム'), wn('% --------------------------------------'), wn('% type go and period to start the system. '), nl. me:- wn('% file: quia1.pl'), wn('% created: 16 May 2002'), wn('% edited: 5 Mar 2003'), wn('% edited: 21 Mar 2003'), wn('% edited: 26 Mar 2003'), nl. %-------------------------------- % 問題データベース %-------------------------------- % 問題文章、選択肢、および正解 '質問'(1,'問題文','What is "karasumi" ?',_). '質問'(1,'選択肢'(1),'A kind of cat',no). '質問'(1,'選択肢'(2),'A kind of dog',no). '質問'(1,'選択肢'(3),'A kind of bird',no). '質問'(1,'選択肢'(4),'A kind of machine',no). '質問'(1,'選択肢'(5),'A kind of food',yes). '質問'(2,'問題文','Can it fly?',_). '質問'(2,'選択肢'(1),'No. It can not fly.',yes). '質問'(2,'選択肢'(2),'Yes. It can fly, sometimes. ',no). '質問'(2,'選択肢'(3),'I hope not.',no). '質問'(2,'選択肢'(4),'I do not know. ',no). question(N,problem,Q,Y):- '質問'(N,'問題文',Q,Y). question(N,alternative(NofAlt),S,Ans):- '質問'(N,'選択肢'(NofAlt),S,Ans). %-------------------------------- % クイズ出題・採点プログラム %-------------------------------- quiz(N):- question(N,problem,Text,_), wr_question(Text,60), wr_alternative(N), user_input(User), wr_result(N,User,M), wr_star_and_sentence(M,30). %-------------------------------- % 簡易インタフェース %-------------------------------- % 問題文章の表示 etc. wr_question(B,Y):- wr_star_and_sentence(B,Y). wr_star_and_sentence(B,Y):- wr_star(_,Y), nl,tab(4),write(B),nl, wr_star(_,Y), nl. % '選択肢'の表示 wr_alternative(N):- question(N,alternative(X),Y,_), tab(5),write(X),write('. '),write(Y),nl,fail. wr_alternative(_):-!. % 採点結果表示 wr_result(N,User,M):- question(N,alternative(User),_,yes) -> M = 'right. congratulation!' ; M = 'wrong. good luck!'. % ユーザーによる回答入力 user_input(User):- nl,tab(4),write('Type a number ( 番号を入力)->'), read(User). %-------------------------------- % その他のユーティリティー %-------------------------------- % データの画面表示 wn(Z):- write(Z), nl. '書け'(X):- write(X). % ☆ラインの繰り返し wr_star([],0). wr_star(L,N):- length(L,N), X='*', L=[X|Y], write(X), wr_star(Y,N1), N1 is N - 1. % --------------------- % 実行開始・終了 % --------------------- go:- quiz(_N),fail. % 立ち上げ即実行 %:-go. :- headline. % プログラムの終わり