Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* guess.pl
- *
- * Animal guessing game.
- *
- * Author:Ryan Maloney
- * Date:October 9th 2011
- *
- * start with ?- go.
- */
- go :- nl,
- write('Think of an animal and I will attempt to guess what it is.'),
- nl,
- write('Please answer yes or no to the following questions:'),
- nl, nl,
- guess(Animal),
- write('The animal is a '),
- write(Animal),
- nl,
- undo.
- /* hypotheses to be tested */
- /*herbivores*/
- /*lives off grass*/
- guess(deer):-deer, !.
- guess(reindeer):- reindeer, !.
- guess(elk):-elk, !.
- guess(chital):-chital, !.
- guess(yak):-yak, !.
- guess(zebra):-zebra, !.
- guess(cow):-cow, !.
- guess(llama):-llama, !.
- guess(squirrel):-squirrel, !.
- guess(orangutan):-orangutan, !.
- guess(chimpanzee):-chimpanzee, !.
- guess(chimpmunk):-chimpmunk, !.
- guess(manetee):-manetee, !.
- guess(dugong):-dugong, !.
- guess(sea_urchin):-sea_urchin, !.
- guess(sloth):-sloth,!.
- guess(koala):-koala, !.
- guess(howler_monkey):-howler_monkey, !.
- /*carnivores*/
- /*has fur*/
- guess(tiger):-tiger, !.
- guess(lion):-lion ,!.
- guess(panther):-panther, !.
- guess(ocelot):-ocelot, !.
- /*has fur */
- guess(grolar_bear):-grolar_bear, !.
- guess(wolverine):-wolverine, !.
- guess(wolf):-wolf, !.
- guess(dog):-dog, !.
- guess(shark):-shark, !.
- guess(barracuda):-barracuda, !.
- guess(piranha):-piranha, !.
- guess(salmon):-salmon, !.
- guess(angler_fish):-angler_fish, !.
- guess(lantern_fish):-lantern_fish, !.
- guess(viper_fish):-viper_fish, !.
- guess(chamelon):-chamelon, !.
- guess(snake):-snake, !.
- guess(turtle):-turtle, !.
- guess(unknown). /* no diagnosis */
- /* animal identification rules */
- capuchin:-herbivore,
- verify(live_in_trees_but_do_not_eat_leaves),
- verify(has_black_and_white_fur).
- chital:- herbivore,
- verify(live_off_grass),
- verify(live_in_cold),
- verify(has_rounded_horns).
- ocelot:- verify(have_fur),
- verify(live_in_warm_areas),
- verify(has_black_spots).
- bonobo:-herbivore,
- verify(have_a_peaceful_nature).
- fieldmouse:-herbivore,
- verify(lives_underground),
- verify(have_a_long_hairless_tail).
- rabbit:-herbivore,
- verify(lives_underground),
- verify(has_big_ears).
- minnow:-herbivore,
- verify(breathes_water).
- elk:-herbivore,
- verify(live_off_grass),
- verify(live_in_cold),
- verify(migrates_yearly).
- gecko:-
- verify(have_adhesion_ability).
- llama:-herbivore,
- verify(live_off_grass),
- verify(lives_in_mountains).
- yak :- herbivore,
- verify(live_off_grass),
- verify(have_long_horns).
- orangutan:-herbivore,
- verify(live_in_trees_but_do_not_eat_leaves),
- verify(has_orange_fur).
- chimpanzee:-herbivore,
- verify(live_in_trees_but_do_not_eat_leaves),
- verify(make_and_uses_tools).
- squirrel:-herbivore,
- verify(live_in_trees_but_do_not_eat_leaves),
- verify(have_a_bushy_tail).
- chimpmunk:-herbivore,
- verify(live_in_trees_but_do_not_eat_leaves),
- verify(eats_nuts).
- manetee:-herbivore,
- verify(live_in_water),
- verify(has_whiskers).
- sea_urchin:-herbivore,
- verify(live_in_water),
- verify(has_spines).
- dugong:-herbivore,
- verify(live_in_water),
- verify(has_downturned_snout).
- zebra :- herbivore,
- verify(live_off_grass),
- verify(have_black_stripes).
- cow :- herbivore,
- verify(live_off_grass),
- verify(is_domesticated).
- bison:-herbivore,
- verify(live_off_grass),
- verify(lives_on_the_grasslands).
- deer :-herbivore,
- verify(live_off_grass),
- verify(live_in_cold),
- verify(lives_in_america).
- reindeer:-herbivore,
- verify(live_off_grass),
- verify(live_in_cold),
- verify(has_large_horns).
- /*has fur*/
- panther :-
- verify(have_fur),
- verify(live_in_warm_areas),
- verify(lives_in_jungle).
- mountain_lion:-
- verify(have_fur),
- verify(live_in_america).
- lion:-
- verify(have_fur),
- verify(live_in_warm_areas),
- verify(has_a_mane).
- grolar_bear:-
- verify(have_fur),
- verify(weigh_alot).
- wolverine:-
- verify(have_fur),
- verify(not_weigh_much).
- dog:-
- verify(have_fur),
- verify(is_domesticated).
- wolf:-
- verify(have_fur),
- verify(have_a_keen_nose).
- tiger:-
- verify(have_fur),
- verify(live_in_warm_areas),
- verify(has_orange_stripes).
- /*has_scale*/
- shark:-
- verify(live_in_water_near_surface),
- verify(hunts_in_packs).
- barracuda:-
- verify(live_in_water_near_surface),
- verify(hunts_alone).
- piranha:-
- verify(live_in_water_near_surface),
- verify(hunts_in_large_schools).
- salmon:-
- verify(live_in_water_near_surface),
- verify(has_rainbow_scales).
- snake:-
- verify(poison_glands).
- chamelon:-
- verify(changes_color).
- turtle:-
- verify(has_hard_shell).
- comodo_dragon:-
- verify(has_a_long_tail).
- angler_fish:-
- verify(lives_in_deep_water),
- verify(have_a_lantern_on_his_head).
- lantern_fish:-
- verify(lives_in_deep_water),
- verify(glow_in_the_dark).
- viper_fish:-
- verify(lives_in_deep_water),
- verify(have_a_thin_body).
- howler_monkey:-
- herbivore,
- verify(has_long_arms).
- sloth:-herbivore,
- verify(has_slow_metabolism).
- koala:-herbivore,
- verify(has_large_ears).
- starfish:-verify(lives_in_tide_pools).
- /* classification rules */
- warm_blooded:- verify(have_warm_blood).
- cold_blooded:- verify(have_cold_blood).
- herbivore:- verify(eat_plants).
- african:-verify(lives_in_africa).
- /* how to ask questions */
- ask(Question) :-
- write('Does the animal '),
- write(Question),
- write('? '),
- read(Response),
- nl,
- ( (Response == yes ; Response == y)
- ->
- assert(yes(Question)) ;
- assert(no(Question)), fail).
- :- dynamic yes/1,no/1.
- /* How to verify something */
- verify(S) :-
- (yes(S)
- ->
- true ;
- (no(S)
- ->
- fail ;
- ask(S))).
- /* undo all yes/no assertions */
- undo :- retract(yes(_)),fail.
- undo :- retract(no(_)),fail.
- undo.
Add Comment
Please, Sign In to add comment