-
Notifications
You must be signed in to change notification settings - Fork 1
/
animals.clp
1534 lines (1470 loc) · 49.9 KB
/
animals.clp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Russell Yang
* 3/15/2019
* Plays a game of twenty questions (or a custom number of questions) with the user, trying
* to guess an animal that the user has chosen.
*/
; Remove all rules, etc.
(clear)
; Remove all facts from working memory
(reset)
; Define a global variable ?*q* to be 1. This will be used to count the question number
(defglobal ?*q* = 1)
/*
* Define a threshold for the max number of questions that will be asked before the program terminates
* NOTE: with a threshold of 20, an example of a chosen animal that will cause the system to ask
* more than 20 questions and be forced to terminate is the chameleon. T is a constant so it's capitalized.
*/
(defglobal ?*T* = 20)
/*
* The following lines of code mark each characteristic as being eligible for
* backward chaining. The characteristics are explained on the inline comments.
*/
(do-backward-chaining mam) ; Whether it's a mammal
(do-backward-chaining threetall) ; Whether it's taller/longer than 3 feet on average
(do-backward-chaining fourlegs) ; Whether it has four legs
(do-backward-chaining fur) ; Whether it has fur
(do-backward-chaining egg) ; Whether it lays eggs
(do-backward-chaining dom) ; Whether it's domesticated
(do-backward-chaining flies) ; Whether it can fly
(do-backward-chaining rep) ; Whether it's a reptile
(do-backward-chaining fish) ; Whether it's a fish
(do-backward-chaining mars) ; Whether it's a marsupial
(do-backward-chaining ins) ; Whether it's an insect
(do-backward-chaining legs) ; Whether it has legs
(do-backward-chaining land) ; Whether it lives on land
(do-backward-chaining tail) ; Whether it has a tail
(do-backward-chaining vert) ; Whether it is a vertebrate
(do-backward-chaining bilat) ; Whether it has bilateral symmetry
(do-backward-chaining spotted) ; Whether it is spotted
(do-backward-chaining carnivore) ; Whether it's a carnivore
(do-backward-chaining venomous) ; Whether it's venomous
(do-backward-chaining horns) ; Whether it has horns
(do-backward-chaining shell) ; Whether it lives in a shell
(do-backward-chaining whiskers) ; Whether it has whiskers
(do-backward-chaining slithers) ; Whether it slithers
/*
* This function prints the instructions to the user, and then runs the file
* to start the game.
*/
(deffunction animals ()
; Ask the user to think of an animal.
(printout t "Choose an animal." crlf)
; Tell the user that anything starting with y/Y counts as yes.
(printout t "Any word that starts with y or Y is interpreted as yes." crlf)
; Tell the user than anything starting with n/N counts as no.
(printout t "Any word that starts with n or N is interpreted as no." crlf)
; Tell the user to hit enter after they enter then answers.
(printout t "Hit enter after entering your response." crlf)
; Start the game!
(run)
; All functions end with a return.
(return)
)
/*
* This function is a very basic function to ask the user a question, and read
* back their input.
* Parameters:
* ?question - the question to be asked to the user
*/
(deffunction ask (?question)
(printout t ?question) ; Printout the given question
(return (read)) ; Return what the user inputs
)
/*
* This function, which uses the ask function as a helper
* function, will keep prompting a user with a given ?question until they answer
* something that can be interpreted as either yes or no. The function also
* prints out the question number before each question, and increments the
* question number on each call.
*
* The helper function
* check is used to determine if the user's response to the question starts
* with y/Y or n/N. If the user's response starts with y/Y, then the check function
* will convert that to yes. If the user's response starts with n/N, then the check
* function will convert that to no. If the user's response is not a symbol (ex: 5),
* the check function will convert that to nil. This makes it easy for the
* validatedAsk function to understand the user's response and tell if it is valid.
*
* While the user's response is not valid, the user is prompted to re-enter
* a response.
*
* At the end of the function, the ?result variable, which is guaranteed to be
* either yes or no, is returned.
*
* Parameters:
* ?question - the question to be asked to the user (ex: "Is it a mammal?")
*/
(deffunction validatedAsk (?question)
(printout t ?*q*) ; Printout the question number
(printout t ". ") ; Printout a period and a space
/*
* Use the ask function to ask the
* question ?question, and bind that to the ?answer variable.
*/
(bind ?answer (ask ?question))
/*
* Pass ?answer to the check function, so that it can be converted to
* either yes, no, or nil. Bind the output to ?result.
*/
(bind ?result (check ?answer))
; While the result is equal to nil (which means it isn't yes or no)
(while (= ?result nil) do
; Tell the user that the input was not valid.
(printout t "Input not valid. Please try again." crlf)
; Ask the user again
(bind ?answer (ask ?question))
; Pass ?answer to check function again
(bind ?result (check ?answer))
)
(bind ?*q* (+ 1 ?*q*)) ; Increment the question number ?*q* by 1
; If the question number is greater than the threshold, call the exceedThreshold function
(if (> ?*q* ?*T*) then
(exceedThreshold)
)
; At this point, ?result is guaranteed to be yes or no. Return it.
(return ?result)
)
/*
* The check function takes an input, and returns yes if the input starts with
* y or Y, returns no if the input starts with n or N, and returns nil otherwise.
* Returning nil could mean that the input was not a symbol (ex: 5), or that
* it didn't start with y/Y/n/N (ex: go).
*
* Parameters:
* ?in - an user input to be processed
*/
(deffunction check (?in)
; If ?in is a symbol
(if (symbolp ?in) then
/*
* Use the sub-string method to find if the first character in the string
* is y or Y. If so, change ?in to yes.
*/
(if (or (= "y" (sub-string 1 1 ?in)) (= "Y" (sub-string 1 1 ?in))) then
(bind ?in yes)
/*
* Use the sub-string method to find if the first character in the string
* is n or N. If so, change ?in to no.
*/
elif (or (= "n" (sub-string 1 1 ?in)) (= "N" (sub-string 1 1 ?in))) then
(bind ?in no)
else
(bind ?in nil)
)
; Otherwise, the input was not valid, so bind nil to ?in.
else
(bind ?in nil)
)
; Return ?in
(return ?in)
)
/*
* The noneFound rule is intended to fire if no animals can be found that
* are consistent with what the user inputs. Therefore, the rule is given
* a low salience, or priority. The pattern to be matched is (not (done))
* since when a match is found, done is asserted. Thus, if
* at the end, the pattern (not (done)) is found, no match has been found.
*/
(defrule noneFound "Finish up if no animals can be found"
; Declare a relatively low value for salience so the rule only might fire at the end
(declare (salience -100))
; This is the pattern we are looking for.
(not (done))
=>
; Tell the user that no animals matched.
(printout t "GAME OVER" crlf)
(printout t "Couldn't find any animals that matched." crlf)
)
/*
* The exceedThreshold function is called when the question number exceeds the threshold
* number. (halt) is called to stop rule execution. Then, "GAME OVER" is printed out.
* On a new line, the number of questions that have been asked (the threshold number)
* is printed out.
*/
(deffunction exceedThreshold ()
(halt)
(printout t "GAME OVER" crlf)
(printout t ?*T*)
(printout t " questions have been asked." crlf)
(return)
)
/*
* This rule will fire if the characteristics of a human
* are all met. The LHS contains all the characteristics
* of the human, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule human "Matches for a human"
(mam yes)
(threetall yes)
(fourlegs no)
(fur no)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail no)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a human." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a chameleon
* are all met. The LHS contains all the characteristics
* of the chameleon, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule chameleon "Matches for a chameleon"
(mam no)
(threetall no)
(fourlegs yes)
(fur no)
(egg yes)
(dom no) ; While chameleons can be captive-bred, they are not considered domesticated
(flies no)
(rep yes)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns yes)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a chameleon" crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a flamingo
* are all met. The LHS contains all the characteristics
* of the flamingo, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule flamingo "Matches for a flamingo"
(mam no)
(threetall yes)
(fourlegs no)
(fur no)
(egg yes)
(dom no)
(flies yes)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land no) ; The habitat of flamingos is usually lakes
(tail yes) ; Short tail, but still one
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a flamingo." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a toucan
* are all met. The LHS contains all the characteristics
* of the toucan, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule toucan "Matches for a toucan"
(mam no)
(threetall no) ; The largest toucan is about 25 inches, so on average toucans are < 3 feet tall
(fourlegs no)
(fur no)
(egg yes)
(dom no)
(flies yes)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a toucan." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of an eel
* are all met. The LHS contains all the characteristics
* of the eel, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule eel "Matches for a eel"
(mam no)
(threetall no) ; While some eels can be longer than 3 feet, they are < 3 feet on AVERAGE.
(fourlegs no)
(fur no)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs no)
(land no)
(tail no)
(vert yes)
(bilat yes)
(spotted no)
(carnivore yes)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers yes)
=>
(printout t "I think your animal was an eel." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a salmon
* are all met. The LHS contains all the characteristics
* of the salmon, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule salmon "Matches for a salmon"
(mam no)
(threetall yes)
(fourlegs no)
(fur no)
(egg yes)
(dom no)
(flies no)
(rep no)
(fish yes)
(mars no)
(ins no)
(legs no)
(land no)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a salmon." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a jaguar
* are all met. The LHS contains all the characteristics
* of the jaguar, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule jaguar "Matches for a jaguar"
(mam yes)
(threetall yes)
(fourlegs yes)
(fur yes)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted yes)
(carnivore yes)
(venomous no)
(horns no)
(shell no)
(whiskers yes)
(slithers no)
=>
(printout t "I think your animal was a jaguar." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a kangaroo
* are all met. The LHS contains all the characteristics
* of the kangaroo, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule kangaroo "Matches for a kangaroo"
(mam yes)
(threetall yes)
(fourlegs no)
(fur yes)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars yes)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a kangaroo." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a jellyfish
* are all met. The LHS contains all the characteristics
* of the jellyfish, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule jellyfish "Matches for a jellyfish"
(mam no)
(threetall no)
(fourlegs no)
(fur no)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no) ; Jellyfish are not actually fish!
(mars no)
(ins no)
(legs no)
(land no)
(tail no)
(vert no)
(bilat no)
(spotted no)
(carnivore yes)
(venomous yes)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a jellyfish." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a monkey
* are all met. The LHS contains all the characteristics
* of the monkey, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule monkey "Matches for a monkey"
(mam yes)
(threetall no) ; While some monkeys can be taller than 3 feet, on AVERAGE they are < 3 feet.
(fourlegs no) ; Monkeys are considered to have 2 feet and 2 arms
(fur yes)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a monkey." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a panda
* are all met. The LHS contains all the characteristics
* of the panda, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule panda "Matches for a panda"
(mam yes)
(threetall yes)
(fourlegs yes) ; Pandas walk on all fours so they are considered to have 4 legs
(fur yes)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted yes)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a panda." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a ray
* are all met. The LHS contains all the characteristics
* of the ray, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule ray "Matches for a ray"
(mam no)
(threetall yes)
(fourlegs no)
(fur no)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no) ; Rays are actually not fish
(mars no)
(ins no)
(legs no)
(land no)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore yes)
(venomous yes)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a ray." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a snake
* are all met. The LHS contains all the characteristics
* of the snake, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule snake "Matches for a snake"
(mam no)
(threetall no)
(fourlegs no)
(fur no)
(egg yes)
(dom no)
(flies no)
(rep yes)
(fish no)
(mars no)
(ins no)
(legs no)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore yes)
(venomous yes)
(horns no)
(shell no)
(whiskers no)
(slithers yes)
=>
(printout t "I think your animal was a snake." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a cow
* are all met. The LHS contains all the characteristics
* of the cow, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule cow "Matches for a cow"
(mam yes)
(threetall yes)
(fourlegs yes)
(fur no)
(egg no)
(dom yes)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers yes) ; Cows actually do have whiskers!
(slithers no)
=>
(printout t "I think your animal was a cow." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a poodle
* are all met. The LHS contains all the characteristics
* of the poodle, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule poodle "Matches for a poodle"
(mam yes)
(threetall no)
(fourlegs yes)
(fur yes)
(egg no)
(dom yes)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no) ; Poodles actually vegetables and meat
(venomous no)
(horns no)
(shell no)
(whiskers no) ; Very short or no whiskers
(slithers no)
=>
(printout t "I think your animal was a poodle." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a butterfly
* are all met. The LHS contains all the characteristics
* of the butterfly, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule butterfly "Matches for a butterfly"
(mam no)
(threetall no)
(fourlegs no)
(fur no)
(egg yes)
(dom no)
(flies yes)
(rep no)
(fish no)
(mars no)
(ins yes)
(legs yes)
(land yes)
(tail no)
(vert no)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a butterfly." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a dolphin
* are all met. The LHS contains all the characteristics
* of the dolphin, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule dolphin "Matches for a dolphin"
(mam yes)
(threetall yes)
(fourlegs no)
(fur no)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no) ; Dolphins are not fish.
(mars no)
(ins no)
(legs no)
(land no)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore yes)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a dolphin." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a parakeet
* are all met. The LHS contains all the characteristics
* of the parakeet, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule parakeet "Matches for a parakeet"
(mam no)
(threetall no)
(fourlegs no)
(fur no)
(egg yes)
(dom yes)
(flies yes)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers no)
(slithers no)
=>
(printout t "I think your animal was a parakeet." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a tarantula
* are all met. The LHS contains all the characteristics
* of the tarantula, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule tarantula "Matches for a tarantula"
(mam no)
(threetall no)
(fourlegs no)
(fur yes)
(egg yes)
(dom yes)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail no)
(vert no)
(bilat yes)
(spotted no)
(carnivore yes)
(venomous yes)
(horns no)
(shell no)
(whiskers on)
(slithers no)
=>
(printout t "I think your animal was a tarantula." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a squirrel
* are all met. The LHS contains all the characteristics
* of the squirrel, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule squirrel "Matches for a squirrel"
(mam yes)
(threetall no)
(fourlegs yes)
(fur yes)
(egg no)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes)
(land yes)
(tail yes)
(vert yes)
(bilat yes)
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell no)
(whiskers yes)
(slithers no)
=>
(printout t "I think your animal was a squirrel." crlf)
(assert (done))
)
/*
* This rule will fire if the characteristics of a garden snail
* are all met. The LHS contains all the characteristics
* of the garden snail, and the RHS prints out that the animal
* was found if all the characteristics were met.
* Also, the statement (assert (done)) will cause the
* finish rule to not fire, since it tells the system
* that an animal has been found.
*/
(defrule gardensnail "Matches for a garden snail"
(mam no)
(threetall no)
(fourlegs no)
(fur no)
(egg yes)
(dom no)
(flies no)
(rep no)
(fish no)
(mars no)
(ins no)
(legs yes) ; NO legs, but snails do have one flat foot
(land yes)
(tail no)
(vert no)
(bilat no) ; Sides are mirror-images, coil opposite ways
(spotted no)
(carnivore no)
(venomous no)
(horns no)
(shell yes)