The syntax ?colorOpposite&~?color is not valid in the actions of a rule and the variable ?colorOpposite is not bound anywhere in the rule so both of these issues will generate errors. You also need to add some code that specifies the color opposites. To prevent looping from one opposite to the other, you will need to indicate some way that the color has been changed.
CLIPS (6.31 6/12/19)
CLIPS>
(deftemplate colorTemp
(slot color)
(slot changed (default no)))
CLIPS>
(deffacts opposites
(opposite white black))
CLIPS>
(defrule colour
?col <- (colorTemp (color ?color&white|black)
(changed no))
(or (opposite ?color ?opposite)
(opposite ?opposite ?color))
=>
(modify ?col (color ?opposite)
(changed yes)))
CLIPS> (reset)
CLIPS> (assert (colorTemp (color white)))
<Fact-2>
CLIPS> (facts)
f-0 (initial-fact)
f-1 (opposite white black)
f-2 (colorTemp (color white) (changed no))
For a total of 3 facts.
CLIPS> (agenda)
0 colour: f-2,f-1
For a total of 1 activation.
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (opposite white black)
f-3 (colorTemp (color black) (changed yes))
For a total of 3 facts.
CLIPS>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…