I am using SWI-Prolog to create a Wumpus World project. I am supposed to read the locations of the gold, pits, and the Wumpus from a .txt file that looks like this:
GOLD 3 2
WUMPUS 3 3
PIT 2 1
PIT 3 4
Where the words identify the object, the first number identifies the x position of the object, and the second number identifies the y position of the object. I know how to open a file and read from it, I just don't know how to tell my program that GOLD 3 2 means that the gold needs to be located at (3, 2).
You need to open the file, read its lines, and for each one, split the line into the terms you want to use. Then, you can can place the terms in some variable or
assert/1
them into the dynamic db. In the example below I assert them into the database using dynamic predicatelocation/3
:Supposing your input were in wumpus.txt, then this gives you: