Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JESS: exist and test functions

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am building an expert rule engine to play a card game UNO.



Did I write jess wrong? or maybe just my whole concept of it is wrong.
help me.. please...

[ EJFH: Turned off smilies for this post; Added [CODE ][ /CODE] tags to preserve formatting, and HTML escapes. ]
[ March 12, 2006: Message edited by: Ernest Friedman-Hill ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

It's hard for me to tell exactly what you want to do here; there are a lot of things that don't make sense. For example, the value slots of the existing "hand" facts all contain Strings, but your rules seem to be trying to call a "contains" method on those Strings; the String class has no such method.

I can tell you a few things that you're doing that can lead to problems, and maybe this advice will help you clear things up. For example, you seem to be mixing quoted Strings and unquoted symbols very liberally. Note that they're different data types in Jess: "yes" and yes are two different items and one won't match the other.

Another thing is just a silly thing: "not" means something does not exist. "exists" means it does exist, and it's implemented as "not not" -- i.e., something exists if it does not not exist. Writing "not exists" sounds like good english, but in Jess it means "not not not" -- which is just a very ineffificient way of writing "not".

I see some variables of the form ?*v* normally reserved for defglobals, but I don't see their declarations anywhere -- they are defglobals, right? Note that pattern matching is driven by working memory changes; changing the value of a defglobal will not cause matches to be reevaluated later.
 
sandy ngai
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick reply. I am so lost without proper help.

I do have my defglobals declared (just forgot to include it there.) and i admit i really don't have much of a clue in what i'm doing with the "exist".

(not(exists (can-play (type "diff-color")) ))
-- I'm trying to say, where fact (can-play (type)) does not contain any fact "diff-color". So how should i rewrite this?

- (not(can-play (type "diff-color"))) ?


You said that "yes" and yes is different, meaning yes is a symbol and "yes" is a string. so the code above is now checking "can-play" with a string not a symbol?

Well i took all of the conditions out of the two rules "same-color" and "different-color" except for the ?p-(MAIN: hase (isPhase best )). So they have the exact same conditions but only the "different-color" rule is being fired. why is that?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If two rules have the exact same conditions, both will fire, as long as their actions don't invalidate the conditions. I can't explain your observations other than to suggest that you may have a typo of some kind.

Yes, "(not(exists (can-play (type "diff-color")) ))" and " (not(can-play (type "diff-color")))" mean the same thing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic