Prolog Arithmetic Operations within Function?

Click For Summary
SUMMARY

The discussion centers on implementing arithmetic operations in Prolog for the "wumpus world" rules. The user initially faced issues with the predicate pit(X,Y) returning false for all locations despite correctly defining breeze locations. The solution involved asserting the breeze locations and extracting arithmetic operations from within the function. This highlights the importance of proper predicate definition and the handling of arithmetic in Prolog.

PREREQUISITES
  • Understanding of Prolog syntax and predicates
  • Familiarity with the "wumpus world" problem in artificial intelligence
  • Knowledge of asserting facts in Prolog
  • Basic grasp of arithmetic operations in Prolog
NEXT STEPS
  • Study Prolog's assert/1 and retract/1 predicates for dynamic knowledge bases
  • Learn about Prolog's arithmetic operations and their correct usage
  • Explore the implementation of the "wumpus world" in Prolog for deeper understanding
  • Investigate debugging techniques in Prolog to troubleshoot predicate issues
USEFUL FOR

Prolog learners, AI enthusiasts, and developers implementing logic-based systems who seek to understand arithmetic operations within Prolog functions.

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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
31
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 12 ·
Replies
12
Views
2K