user12092018
user12092018

Reputation:

How to make a maze in Prolog?

For a project, I have to write a basic maze in Prolog. The only problem is that I do not know how to write a KB that represents the maze in the below picture.

This is what I currently have, but I should be able to find pats from letter to letter.

% size of maze, including barriers.
mazeSize(7,7)
barrier(1,6).
barrier(2,2).
barrier(2,3).
barrier(3,2).
barrier(3,6).
barrier(4,1).
barrier(5,4).
barrier(5,6).
barrier(6,1).
barrier(7,4).

And this is what it should look like: Maze with letters

Hopefully someone can help me! Thanks in advance!

Upvotes: 0

Views: 512

Answers (1)

Isabelle Newbie
Isabelle Newbie

Reputation: 9378

Your approach is reasonable, but you would also need facts something like node_name(1, 1, a) to map between node names and coordinates. Also, a 7x7 maze will clearly not correspond to the shown 4x4 maze.

A simpler solution that would not need coordinates at all would be one that only enumerates connected nodes, but not barriers:

connection(a, b).
connection(b, f).

and so on, but not connection(b, c) for example. Note that you will probably need to express that connections are two-way, so b and a are also connected.

Upvotes: 1

Related Questions