Hi again,
I'm using JESS with Java objects to define the behaviour of an agent
(well, it's not a very sophisticated thing, but I call it an agent). At
this time I'm describing the movement of a car, but I've got a problem.
When the car finds an obstacle it must turn right/left/back to keep on
driving. This is the rule that does it:
(defrule car-turns
(car (position ?pos)
(OBJECT ?c))
(position (OBJECT ?pos-in-front-of&:(and (call ?c isInFrontOf
?pos-in-front-of)
(not (call ?c isAllowed
?pos-in-front-of)))))
(position (OBJECT ?pos-free&:(and (call ?c isNextTo ?pos-free)
(call ?c isAllowed ?pos-free))))
=>
(call ?c setOrientation (call ?c computeOrientation ?pos ?pos-free))
Where isInFrontOf, isAllowed, isNextTo and setOrientation are Java methods
of the Java class car. isInFrontOf returns a boolean value due to the
position attribute of car, its orientation attribute, and its parameter
?pos-in-front-of.
The problem is that my car turns too many times. When the car turns I
change its orientation attribute and I fire its change (firePropertyChange),
but the activated rules (one activation for each adyacent position) keep on
activated and they shouldn't, because orientation has changed and
pos-in-front-of can't be in front of again.
It seems to be like if the method isInFrontOf was not re-executed each
time the state of the car changes. Surely it's a concept or programming
mistake. I don't know how JESS works in this situations, but I changed the
code to be sure of the "reevaluation" of the conditions to activate the
rule. Now this is the code for the rule:
(defrule car-turns
(car (position ?pos)
(orientation ?o)
(OBJECT ?c))
(position (OBJECT ?pos-in-front-of&:(and (eq ?o (call ?c computeOrientation
?pos ?pos-in-front-of))
(not (call ?c isAllowed ?pos-in-front-of)))))
(position (OBJECT ?pos-free&:(and (call ?c isNextTo ?pos-free)
(call ?c isAllowed ?pos-free))))
=>
(call ?c setOrientation (call ?c computeOrientation ?pos ?pos-free))
And this code works right. I think it's because it must check the value
of the attribute orientation, which changes when a rule is executed.
Am I right? Are there any posibilities to do it in a diferent or more
smart way?
I've got another problem. The car moves right, but it does always the
same movements, and it enters in a loop between two walls. Could the
movement of the car be random?
I will welcome any help!
Cherman.
P.D: I apologize for the extension of the message.
_________________________________________________________________
MSN Photos es la manera m�s sencilla de compartir e imprimir sus fotos:
http://photos.latam.msn.com/Support/WorldWide.aspx
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------