The rule is somewhat overengineered. Let's look at it, blow by blow.

    ?cell <- (cell ... (row-number ?row-num))
    ?cell2 <- (cell ... (row-number ?row-num2))
;   (test (= ?row-num ?row-num2))
You can simply use
   ?cell <- (cell ... (row-number ?row-num))
    ?cell2 <- (cell ... (row-number ?row-num))
to ascertain equal row numbers.

   ?cell <- (cell ... (value nil) ...)
   ?cell2 <- (cell ... (value ?number&~nil) ...)
This doesn't detect two equal values in two cells - it ascertains one
cell being nil and another one not nil.

Now this here:
    ?cell <- (cell ... (value ?number&~nil) (row-number ?row-num))
    ?cell2 <- (cell ... (value ?number) (row-number ?row-num))
matches if we have a cell, and another one, with the same number, and
the same row-number, BUT it also matches for any single cell with a
value != nil. You can use the name to ensure they're different:
   ?cell <- (cell (name ?n) (value ?number&~nil) (row-number ?row-num))
    ?cell2 <- (cell  (name ?n2&~?n) (value ?number) (row-number ?row-num))
But this has the unpleasant effect to fire twice. But we can use the
row fact to ensure two different cells in a row:

    ?row <- (row (cells $? ?cell1 $? ?cell2 $?))
    ?cell1 <- (cell (value ?number&~nil))
    ?cell2 <- (cell (value ?number))

That's about all you need, and it should work for any row.


On 20/12/2013, northparkjamie <> wrote:
> My apologies for the lousy formatting of my original message. Please see
> properly formatted version below.
> northparkjamie wrote
>> Hi, can you please help me?
>> I'm relatively new to Jess (and using it with
>> CTAT <>
>> , so my question may need to be redirected to them).
>> I am trying to build a sudoku tutor (just to improve my skills) and I'm
>> having a problem with my very first rule (below). This rule fires if one
>> cell is empty and another in the same row is not. On the RHS, the predict
>> function (from CTAT) checks whether the number entered by the user into
>> the first cell is the same as the number in the second cell. If it is the
>> same, the construct-message function displays the given message. If it is
>> different, anything that has happened on the RHS is or remains undone.
>> For
>> example, if the row is {nil nil 6 nil nil nil 2 3 nil} and the user
>> enters
>> 6 in any of the nil cells, the rule should fire and the predict should
>> match and the message should be shown. But, if the user enters 8, the
>> rule
>> should still fire, but the predict function should fail, so nothing
>> should
>> happen.
>> If I test this rule on the first row of the 9x9 grid, it behaves as
>> expected. But if I test it on any other row, the engine only tries it 20
>> times and never finds the cell in which the input was placed.
>> Is there something in Jess that is limiting the number of trials or
>> should
>> I be talking to the CTAT people? If it is Jess, is there a way I can
>> modify this limitation?
>> Thanks in advance for your time and wisdom,
>> Jamie
>> (defrule bug-num-is-in-row
>> &nbsp;&nbsp;&nbsp;&nbsp;?prob <- (problem
>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(interface-elements $?
>> ?grid $?))
>> &nbsp;&nbsp;&nbsp;&nbsp;?grid <- (grid (rows $? ?row $?))
>> &nbsp;&nbsp;&nbsp;&nbsp;?row <- (row (cells $? ?cell $?))
>> &nbsp;&nbsp;&nbsp;&nbsp;?cell <- (cell
>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(name ?name)
>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(value nil)
>> &nbsp;&nbsp;&nbsp;&nbsp;(row-number ?row-num))
>> &nbsp;&nbsp;&nbsp;&nbsp;?cell2 <- (cell
>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(value ?number&~nil)
>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(row-number ?row-num2))
>> &nbsp;&nbsp;&nbsp;&nbsp;(test (= ?row-num ?row-num2))
>> &nbsp;&nbsp;&nbsp;&nbsp;=>
>> &nbsp;&nbsp;&nbsp;&nbsp;(predict ?name UpdateTextField ?number)
>> &nbsp;&nbsp;&nbsp;&nbsp;(construct-message
>> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"[The row already has a
>> "?number".]")
>> &nbsp;&nbsp;&nbsp;&nbsp;)
> --
> View this message in context:
> Sent from the Jess mailing list archive at
To unsubscribe, send the words 'unsubscribe jess-users'
in the BODY of a message to, NOT to the list
(use your own address!) List problems? Notify

Reply via email to