Guest User

Untitled

a guest
Jan 23rd, 2018
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.17 KB | None | 0 0
  1. /* guess.pl
  2. *
  3. * Animal guessing game.
  4. *
  5. * Author:Ryan Maloney
  6. * Date:October 9th 2011
  7. *
  8. * start with ?- go.
  9. */
  10.  
  11. go :- nl,
  12. write('Think of an animal and I will attempt to guess what it is.'),
  13. nl,
  14. write('Please answer yes or no to the following questions:'),
  15. nl, nl,
  16. guess(Animal),
  17. write('The animal is a '),
  18. write(Animal),
  19. nl,
  20. undo.
  21.  
  22. /* hypotheses to be tested */
  23. /*herbivores*/
  24.  
  25. /*lives off grass*/
  26. guess(deer):-deer, !.
  27. guess(reindeer):- reindeer, !.
  28. guess(elk):-elk, !.
  29. guess(chital):-chital, !.
  30.  
  31. guess(yak):-yak, !.
  32. guess(zebra):-zebra, !.
  33. guess(cow):-cow, !.
  34. guess(llama):-llama, !.
  35.  
  36. guess(squirrel):-squirrel, !.
  37. guess(orangutan):-orangutan, !.
  38. guess(chimpanzee):-chimpanzee, !.
  39. guess(chimpmunk):-chimpmunk, !.
  40.  
  41. guess(manetee):-manetee, !.
  42. guess(dugong):-dugong, !.
  43. guess(sea_urchin):-sea_urchin, !.
  44.  
  45. guess(sloth):-sloth,!.
  46. guess(koala):-koala, !.
  47. guess(howler_monkey):-howler_monkey, !.
  48.  
  49. /*carnivores*/
  50.  
  51. /*has fur*/
  52. guess(tiger):-tiger, !.
  53. guess(lion):-lion ,!.
  54. guess(panther):-panther, !.
  55. guess(ocelot):-ocelot, !.
  56.  
  57. /*has fur */
  58. guess(grolar_bear):-grolar_bear, !.
  59. guess(wolverine):-wolverine, !.
  60. guess(wolf):-wolf, !.
  61. guess(dog):-dog, !.
  62.  
  63. guess(shark):-shark, !.
  64. guess(barracuda):-barracuda, !.
  65. guess(piranha):-piranha, !.
  66. guess(salmon):-salmon, !.
  67.  
  68. guess(angler_fish):-angler_fish, !.
  69. guess(lantern_fish):-lantern_fish, !.
  70. guess(viper_fish):-viper_fish, !.
  71.  
  72. guess(chamelon):-chamelon, !.
  73. guess(snake):-snake, !.
  74. guess(turtle):-turtle, !.
  75.  
  76. guess(unknown). /* no diagnosis */
  77.  
  78. /* animal identification rules */
  79. capuchin:-herbivore,
  80. verify(live_in_trees_but_do_not_eat_leaves),
  81. verify(has_black_and_white_fur).
  82.  
  83. chital:- herbivore,
  84. verify(live_off_grass),
  85. verify(live_in_cold),
  86. verify(has_rounded_horns).
  87.  
  88. ocelot:- verify(have_fur),
  89. verify(live_in_warm_areas),
  90. verify(has_black_spots).
  91. bonobo:-herbivore,
  92. verify(have_a_peaceful_nature).
  93. fieldmouse:-herbivore,
  94. verify(lives_underground),
  95. verify(have_a_long_hairless_tail).
  96. rabbit:-herbivore,
  97. verify(lives_underground),
  98. verify(has_big_ears).
  99. minnow:-herbivore,
  100. verify(breathes_water).
  101. elk:-herbivore,
  102. verify(live_off_grass),
  103. verify(live_in_cold),
  104. verify(migrates_yearly).
  105.  
  106. gecko:-
  107. verify(have_adhesion_ability).
  108.  
  109. llama:-herbivore,
  110. verify(live_off_grass),
  111. verify(lives_in_mountains).
  112.  
  113. yak :- herbivore,
  114. verify(live_off_grass),
  115. verify(have_long_horns).
  116.  
  117. orangutan:-herbivore,
  118. verify(live_in_trees_but_do_not_eat_leaves),
  119. verify(has_orange_fur).
  120.  
  121. chimpanzee:-herbivore,
  122. verify(live_in_trees_but_do_not_eat_leaves),
  123. verify(make_and_uses_tools).
  124.  
  125. squirrel:-herbivore,
  126. verify(live_in_trees_but_do_not_eat_leaves),
  127. verify(have_a_bushy_tail).
  128.  
  129. chimpmunk:-herbivore,
  130. verify(live_in_trees_but_do_not_eat_leaves),
  131. verify(eats_nuts).
  132.  
  133. manetee:-herbivore,
  134. verify(live_in_water),
  135. verify(has_whiskers).
  136.  
  137. sea_urchin:-herbivore,
  138. verify(live_in_water),
  139. verify(has_spines).
  140.  
  141. dugong:-herbivore,
  142. verify(live_in_water),
  143. verify(has_downturned_snout).
  144.  
  145. zebra :- herbivore,
  146. verify(live_off_grass),
  147. verify(have_black_stripes).
  148.  
  149. cow :- herbivore,
  150. verify(live_off_grass),
  151. verify(is_domesticated).
  152.  
  153. bison:-herbivore,
  154. verify(live_off_grass),
  155. verify(lives_on_the_grasslands).
  156.  
  157. deer :-herbivore,
  158. verify(live_off_grass),
  159. verify(live_in_cold),
  160. verify(lives_in_america).
  161.  
  162. reindeer:-herbivore,
  163. verify(live_off_grass),
  164. verify(live_in_cold),
  165. verify(has_large_horns).
  166. /*has fur*/
  167. panther :-
  168. verify(have_fur),
  169. verify(live_in_warm_areas),
  170. verify(lives_in_jungle).
  171.  
  172. mountain_lion:-
  173. verify(have_fur),
  174. verify(live_in_america).
  175.  
  176. lion:-
  177. verify(have_fur),
  178. verify(live_in_warm_areas),
  179. verify(has_a_mane).
  180.  
  181. grolar_bear:-
  182. verify(have_fur),
  183. verify(weigh_alot).
  184.  
  185. wolverine:-
  186. verify(have_fur),
  187. verify(not_weigh_much).
  188.  
  189. dog:-
  190. verify(have_fur),
  191. verify(is_domesticated).
  192.  
  193. wolf:-
  194. verify(have_fur),
  195. verify(have_a_keen_nose).
  196.  
  197. tiger:-
  198. verify(have_fur),
  199. verify(live_in_warm_areas),
  200. verify(has_orange_stripes).
  201. /*has_scale*/
  202. shark:-
  203. verify(live_in_water_near_surface),
  204. verify(hunts_in_packs).
  205.  
  206. barracuda:-
  207. verify(live_in_water_near_surface),
  208. verify(hunts_alone).
  209.  
  210. piranha:-
  211. verify(live_in_water_near_surface),
  212. verify(hunts_in_large_schools).
  213.  
  214. salmon:-
  215. verify(live_in_water_near_surface),
  216. verify(has_rainbow_scales).
  217.  
  218. snake:-
  219. verify(poison_glands).
  220.  
  221. chamelon:-
  222. verify(changes_color).
  223. turtle:-
  224. verify(has_hard_shell).
  225. comodo_dragon:-
  226. verify(has_a_long_tail).
  227. angler_fish:-
  228. verify(lives_in_deep_water),
  229. verify(have_a_lantern_on_his_head).
  230. lantern_fish:-
  231. verify(lives_in_deep_water),
  232. verify(glow_in_the_dark).
  233. viper_fish:-
  234. verify(lives_in_deep_water),
  235. verify(have_a_thin_body).
  236. howler_monkey:-
  237. herbivore,
  238. verify(has_long_arms).
  239. sloth:-herbivore,
  240. verify(has_slow_metabolism).
  241. koala:-herbivore,
  242. verify(has_large_ears).
  243. starfish:-verify(lives_in_tide_pools).
  244. /* classification rules */
  245. warm_blooded:- verify(have_warm_blood).
  246.  
  247. cold_blooded:- verify(have_cold_blood).
  248.  
  249. herbivore:- verify(eat_plants).
  250.  
  251. african:-verify(lives_in_africa).
  252.  
  253.  
  254.  
  255. /* how to ask questions */
  256. ask(Question) :-
  257. write('Does the animal '),
  258. write(Question),
  259. write('? '),
  260. read(Response),
  261. nl,
  262. ( (Response == yes ; Response == y)
  263. ->
  264. assert(yes(Question)) ;
  265. assert(no(Question)), fail).
  266.  
  267. :- dynamic yes/1,no/1.
  268.  
  269. /* How to verify something */
  270. verify(S) :-
  271. (yes(S)
  272. ->
  273. true ;
  274. (no(S)
  275. ->
  276. fail ;
  277. ask(S))).
  278.  
  279. /* undo all yes/no assertions */
  280. undo :- retract(yes(_)),fail.
  281. undo :- retract(no(_)),fail.
  282. undo.
Add Comment
Please, Sign In to add comment