Prolog Arithmetic Operations within Function?

  • Thread starter tangodirt
  • Start date
  • #1
54
1

Main Question or Discussion Point

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?
 

Answers and Replies

  • #2
54
1
Nevermind, I've figured it out. The breeze locations need to be asserted, and the arithmetic operations should be extracted from within the function.
 

Related Threads on Prolog Arithmetic Operations within Function?

  • Last Post
Replies
6
Views
6K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
9
Views
18K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
2
Views
7K
Replies
12
Views
4K
Replies
6
Views
551
  • Last Post
Replies
7
Views
7K
  • Last Post
Replies
7
Views
677
  • Last Post
Replies
2
Views
631
Top