Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Assignment 1
- % Ammar Alhashmi & John Ghatas
- % To start the program, type "main."
- % Expert system should be started from here.
- main :-
- intro,
- reset_answers,
- find_sport(Sport),
- describe(Sport), nl.
- % Intro for when the program staretstarts
- intro :-
- write('Which Sports should i practice for the first time?'), nl,
- write('To answer, input the number shown next to each answer, followed by a dot (.)'), nl, nl.
- find_sport(Sport) :-
- sport(Sport), !.
- % Store the answers of the userto track their progress
- :- dynamic(progress/2).
- % Clear stored progress
- % reset_answers must always return true; because retract can return either true
- % or false, we fail the first and succeed with the second.
- reset_answers :-
- retract(progress(_, _)),
- fail.
- reset_answers.
- % Rules for the knowledge base
- % Check people
- sport(fighting) :-
- why(to_become_pro),
- do_you_have_medical_condition(nno),
- context(solo).
- sport(cycling) :-
- why(just_for_fun),
- do_you_have_medical_condition(nno),
- context(team).
- sport(racketSport) :-
- why(to_become_pro),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(noo),
- context(solo).
- sport(pool) :-
- why(to_become_pro),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(yess),
- context(solo).
- sport(football) :-
- why(to_become_pro),
- do_you_have_medical_condition(nno),
- context(team).
- sport(cafeSports) :-
- why(just_for_fun),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(yess),
- context(team).
- sport(weightlifting) :-
- why(just_for_fun),
- do_you_have_medical_condition(nno),
- context(solo).
- sport(cardio) :-
- why(just_for_fun),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(noo),
- context(solo).
- sport(bowling) :-
- why(just_for_fun),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(noo),
- context(team).
- sport(beachBall) :-
- why(to_become_pro),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(noo),
- context(team).
- sport(racewalking) :-
- why(to_become_pro),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(yess),
- context(team).
- sport(golf) :-
- why(just_for_fun),
- do_you_have_medical_condition(yes),
- does_it_limit_your_abilities(yess),
- context(solo).
- % Questions for the knowledge base
- question(why) :-
- write('Why do you want to play Sports?'), nl.
- question(context) :-
- write('In which context do you want to practice sports?'), nl.
- question(do_you_have_medical_condition) :-
- write('Do you have a Medical condition?'), nl.
- question(does_it_limit_your_abilities) :-
- write('Does it limit your abilities?'), nl.
- % Answers for the knowledge base
- answer(to_become_pro) :-
- write('To become pro').
- answer(just_for_fun) :-
- write('Just for fun').
- answer(yes) :-
- write('Yes').
- answer(nno) :-
- write('No').
- answer(yess) :-
- write('Yes').
- answer(noo) :-
- write('NO').
- answer(solo) :-
- write('Solo').
- answer(team) :-
- write('Team').
- % Sport descriptions for the knowledge base
- describe(fighting) :-
- write('Fighting'), nl,
- write('One of the most famous sports when playing solo and becoming a pro'), nl,
- write('You should not have medical conditions at all').
- describe(racketSport) :-
- write('Racket sport'), nl,
- write('One of the most famous sports when playing solo and becoming a pro'), nl,
- write('You can still play those types of sports even if you have a medical condition but it should not limitate you physical abilities').
- describe(pool) :-
- write('Pool'), nl,
- write('One of the most famous sports when playing solo and becoming a pro'), nl,
- write('You can still play this sport even if you have a medical condition and it limitates your physical abilities').
- describe(football) :-
- write('Football'), nl,
- write('One of the most famous sports when playing in a team and becoming a pro'), nl,
- write('You should not have medical conditions at all').
- describe(cardio) :-
- write('Cardio'), nl,
- write('One of the most famous sports when playing solo and for fun'), nl,
- write('You can still play those types of sports even if you have a medical condition but it should not limitate you physical abilities').
- describe(weightlifting) :-
- write('Weightlifting'), nl,
- write('One of the most famous sports when playing Solo and for fun'), nl,
- write('You should not have medical conditions at all').
- describe(cafeSports) :-
- write('Cafe sports'), nl,
- write('One of the most famous sports when playing in a team and for fun'), nl,
- write('You can still play this sport even if you have a medical condition and it limitates your physical abilities').
- describe(bowling) :-
- write('Bowling'), nl,
- write('One of the most famous sports when playing in a team and for fun'), nl,
- write('You can still play those types of sports even if you have a medical condition but it should not limitate you physical abilities').
- describe(beachBall) :-
- write('Beach Ball'), nl,
- write('One of the most famous sports when playing in a team and to become pro'), nl,
- write('You can still play those types of sports even if you have a medical condition but it should not limitate you physical abilities').
- describe(racewalking) :-
- write('Racewalking'), nl,
- write('One of the most famous sports when playing in a team and to become pro'), nl,
- write('You can still play those types of sports even if you have a medical condition and it limitates you physical abilities').
- describe(cycling) :-
- write('Cycling'), nl,
- write('One of the most famous sports when playing in a team and for fun'), nl,
- write('You should not have medical conditions at all').
- describe(golf) :-
- write('Golf'), nl,
- write('One of the most famous sports when playing solo and for fun'), nl,
- write('You can still play this sport even if you have a medical condition and it limitates your physical abilities').
- % Assign answers to questions from the knowledge base
- % (Queries)
- why(Answer) :-
- progress(why, Answer).
- why(Answer) :-
- \+ progress(why, _),
- ask(why, Answer, [to_become_pro, just_for_fun]).
- do_you_have_medical_condition(Answer) :-
- progress(do_you_have_medical_condition, Answer).
- do_you_have_medical_condition(Answer) :-
- \+ progress(do_you_have_medical_condition, _),
- ask(do_you_have_medical_condition, Answer, [nno, yes]).
- does_it_limit_your_abilities(Answer) :-
- progress(does_it_limit_your_abilities, Answer).
- does_it_limit_your_abilities(Answer) :-
- \+ progress(does_it_limit_your_abilities, _),
- ask(does_it_limit_your_abilities, Answer, [noo, yess]).
- context(Answer) :-
- progress(context, Answer).
- context(Answer) :-
- \+ progress(context, _),
- ask(context, Answer, [solo, team]).
- % Outputs a nicely formatted list of answers
- % [First|Rest] is the Choices list, Index is the index of First in Choices
- answers([], _).
- answers([First|Rest], Index) :-
- write(Index), write(' '), answer(First), nl,
- NextIndex is Index + 1,
- answers(Rest, NextIndex).
- % Parses an Index and returns a Response representing the "Indexth" element in
- % Choices (the [First|Rest] list)
- parse(0, [First|_], First).
- parse(Index, [First|Rest], Response) :-
- Index > 0,
- NextIndex is Index - 1,
- parse(NextIndex, Rest, Response).
- % Asks the Question to the user and saves the Answer
- ask(Question, Answer, Choices) :-
- question(Question),
- answers(Choices, 0),
- read(Index),
- parse(Index, Choices, Response),
- asserta(progress(Question, Response)),
- Response = Answer.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement