-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildTryAllRules.clp
42 lines (40 loc) · 1.35 KB
/
buildTryAllRules.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
/*
* Authored by Bennett Liu on October 30th, 2018
* Defines the functions necessary to build the rule to check all remaining possible animals
*/
/*
* Defines the buildTryAllString function, which given a round, generates the rule string
* to ask the user if their animal is any of the animals in that round.
*
* Below is an example when buildTryAllString is given round: 5.
*
* (defrule tryAll
* (animal (name ?n) (round ?r &:(= ?r 5)))
* (not (finished))
* =>
* (if (and (<= ?*QUESTION* ?*QUESTIONCAP*) (= (askAnimal (str-cat \"Question #\" (toString ?*QUESTION*) \": Is it a/n \" ?n \"?\")) Y)) then
* (assert (finished))
* )
* (bind ?*QUESTION* (+ ?*QUESTION* 1))
*)
*/
(deffunction buildTryAllString (?round)
(bind ?ruleString (str-cat "(defrule tryAll
(animal (name ?n) (round ?r &:(= ?r " ?round ")))
(not (finished))
=>
(if (and (<= ?*QUESTION* ?*QUESTIONCAP*) (= (askAnimal (str-cat \"Question #\" (toString ?*QUESTION*) \": Is it a/n \" ?n \"?\")) Y)) then
(assert (finished))
)
(bind ?*QUESTION* (+ ?*QUESTION* 1))
)"))
(return ?ruleString)
)
/*
* Defines the buildTryAllRule function, which given a round, builds the rule
* to ask the user if their animal is any of the remaining possible animals.
*/
(deffunction buildTryAllRule (?round)
(build (buildTryAllString ?round))
(return)
)