我对 Clips 中的规则匹配有疑问,特别是我无法理解为什么该规则不生效。
(deffunction get-unknow-col (?col)
(bind ?facts (length (find-all-facts ((?a a-cell)) (and (eq ?a:y ?col) (eq ?a:content unk)))))
(return ?facts)
)
(deffunction get-boat-pieces-col (?col)
(bind ?facts (length (find-all-facts ((?a a-cell)) (and (eq ?a:y ?col) (and (neq ?a:content unk) (neq ?a:content water))))))
(return ?facts)
)
(defrule mark-remaining-unk-cells-col (declare (salience 40))
(k-per-col (col ?y) (num ?num))
(test (= (+ (get-unknow-col ?y) (get-boat-pieces-col ?y)) ?num))
=>
(do-for-all-facts ((?cell a-cell)) (and (eq ?cell:y ?y) (eq ?cell:content unk))
(modify ?cell (content boat-piece))
)
)
但是在(事实)中,我有正确的值,实际上是在运行:
(k-per-col (col 9) (num 1))
(get-unknow-col 9)
1
(get-boat-pieces-col 9)
0
CLIPS> (= (+ (get-unknow-col 9) (get-boat-pieces-col 9)) 1)
TRUE
该规则仅在 num 为 0(正确)时才有效:
FIRE 75 mark-remaining-unk-cells-col: f-137
***** Y:8 num: 0 get-unknown-col: 0 get-boat-pieces-col 0
FIRE 76 mark-remaining-unk-cells-col: f-136
***** Y:7 num: 0 get-unknown-col: 0 get-boat-pieces-col 0
为什么当 num=1, get-unknow-col=1, get-boat-pieces-col=0 并且测试为真时它不激活?我哪里错了?