Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prolog Maze problems

Status
Not open for further replies.

KasperProlog

Programmer
Apr 2, 2009
1
NL
Hi everybody,
I'm an experienced java / C+ programmer and I'm interrested in the very different language prolog. I'm using an online manual for beginners. I found some in depth exercises at the end of the manual, but without any tips or answers.
My problem is this: I have created a maze. The pathing in the maze is represented by moves between positions in the maze. Let's say my maze has the following paths:

a -> b -> c = dead end
-> d -> e -> f -> g = dead end
-> h -> i -> j -> k finish

so you start at position a, you can move only to b. From b you can move 2 directions, you can move to c which is a dead end, of you can move to d, which leads to e. From e you go to f, and at position f you got 2 choices again. You can go to dead end g, or to h, which leads to i, which leads to j, and finally to k. k is the finish.
the moves between the path's are represented by a database of moves.

move(a,b).
move(b,c).
move(b,d).
move(d,e).
move(e,f).
move(f,g).
move(f,h).
move(h,i).
move(i,j).
move(j,k).
start(a).
finish(k).

you can find the way through this maze by using a depth first algorithm, which I have copied from the internet. This all works fine. But what I want to do is to create new statements of move, which shows the direct moves in the maze.

this directmoves are like this:
directmove(P,Q,C).
this has to say, you can move directly from P to Q, with a step count of C.
so in my example a true directmove could be:
directmove(d, e, 2).
or directmove(a,b,1).
directmove(h,k,3).

I wanted to make some recursive formula which finds the direct pathing in this maze. Does anyone has some suggestions?
so a direct move is a move from one position to an other position, without having to make a choice, so it must be a straight line in the maze.
I know this is probably a quit difficult question but maybe there are some very intelligent programmers here around.
Many many thanks if someone has some insight,


tnx, regards
kasper
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top