Prolog Arithmetic Operations within Function?

AI Thread Summary
The discussion revolves around implementing rules for the "Wumpus World" in Prolog, specifically focusing on the relationship between pits and breezes. The user initially defines a knowledge base where breezes are felt at specific locations surrounding a pit at (2,2). However, they encounter an issue where querying for the pit returns false for all locations. The problem is identified as a need to assert the breeze locations correctly and to adjust the arithmetic operations outside the function. This realization leads to a solution that aligns the Prolog code with the intended logic of the Wumpus World.
tangodirt
Messages
51
Reaction score
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:
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?
 
Technology news on Phys.org
Nevermind, I've figured it out. The breeze locations need to be asserted, and the arithmetic operations should be extracted from within the function.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Back
Top