Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Prolog Arithmetic Operations within Function?

  1. Nov 13, 2011 #1
    So, I'm trying to learn prolog, and since it's used a lot in the AI community, I thought I would try my hand at implementing a few of the simple "wumpus world" rules.

    The rule for a "pit" existing at location (2,2) means that a breeze is felt at locations (1,2), (2,1), (2,3), and (3,2). So, by telling the knowledge base that breezes are felt at those locations, means that querying pit(2,2) should return true, while all other locations should return false.

    My prolog code looks like this:

    Code (Text):

    breeze(1,2).
    breeze(2,1).
    breeze(2,3).
    breeze(3,2).

    pit(X,Y) :- breeze(X + 1,Y) , breeze(X,Y + 1) , breeze(X - 1,Y) , breeze(X,Y - 1) .
     
    However, all locations for pit(X,Y) return false. Any ideas?
     
  2. jcsd
  3. Nov 13, 2011 #2
    Nevermind, I've figured it out. The breeze locations need to be asserted, and the arithmetic operations should be extracted from within the function.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Prolog Arithmetic Operations within Function?
Loading...