1
votes

Let's say that I have a rule like this:

(defrule get_next_N_poz
    ?id <- (get_next_poz $?)
    (world (limit $?) (ball ?b1 ?b2) (men $? ?x ?y - $?) (id ?))

    (and
    (test (= ?x ?b1))
    (test (= ?y (- ?b2 1))))
        => 
        (printout t "north ready position:" ?x ?y)
        (modify ?id (get_next_poz 1)))

How do I add a new "and"? Thank you.

1

1 Answers

1
votes

It depends on what logic you're trying to implement. The existing and you have is redundant anyway, but if you wanted a second one, you'd just add it after the end of the last:

 (and
    (test (= ?x ?b1))
    (test (= ?y (- ?b2 1))))

 (and
    (test (= ?x ?b2))
    (test (= ?y (+ ?b1 1))))

If you wanted one or the other of these conditions you'd do this:

 (or (and
       (test (= ?x ?b1))
       (test (= ?y (- ?b2 1))))

    (and
       (test (= ?x ?b2))
       (test (= ?y (+ ?b1 1)))))

Rather than using and/or conditional elements, you could use the and/or boolean functions within a single test conditional element:

 (test (or (and (= ?x ?b1)
                (= ?y (- ?b2 1)))
           (and (= ?x ?b2)
                (= ?y (+ ?b1 1)))))