Prolog - Searching within a list of lists - how to do it


I'm working on a program that lacks this one thing to be complete. :(
It's about a simple robot that cleans a room; the room is represented through a 10x10 map divided into squares, each square having it's own unique pair of x,y coordinates. I'm representing the coordinates via a list that contains two elements: [Xcoord,Ycoord], and a path through the room is represented via a sequence of squares in a list: [[0,0],[0,1][1,1]], for example. The robot doesn't move diagonally.
Now I need to find out how to get to a certain square being on another square; for example, I'm on [5,4] and I need to get to [0,0] - I need a predicate that returns me a list with a possible path through these squares, and I just can't do it :((( The closest I got didn't even work correctly. :(((( I know I could just subtract/sum the coordinates of the original position to get the result I want, but that's not what I need :(

Can someone please post some ideas, links and/or code examples on this?

Thanx in advance :)
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Might be that you find the answer that here:

I've had use of this site before when it came to mathematical problems, maybe it will help you as well?
Good luck,
bass20Author Commented:
No Prolog there...
lets say that your command would work like this

the best way to get the correct path would be to move horizontaly at first till you reach the spot and then vertically towards it (or vice versa if you like)...
so you could create a recursive command that gives u all the horizontal coordinates and then the vertical (you may have to rearrange your coordinates list to
more lists). I'll post the code a.s.a.p.
What you want is a recursive algorithm,
This is what it would do:

mark current location as "been here"
if can go north go north if at destination return true
if can go south go south if at destination return true
if can go east go east if at destination return true
if can go west go west if at destination return true
if no move available return false
unmark location

if you want I'll find the algorithm, I have it somewhere

Because you want a list of every posible solution you will need to find the number of possible solutions and call this recursive function that many times.

However you will get list of moves that are unnecessary such as
east, north, east, south
east, east
east, south, east, north

(all bring robot to same location)
Is this what you want?

take a look at this one: it's a bit different than your type of map&pathfinding but it'll give you some ideas...

you can also see if u can grasp anything out of this sourcecode i found in a book....
:- [pmeters].
graph :-

path([H|T], Y, [H|T]) :-
      H = Y.

path([H|T], Y, Path) :-
      \+ member(Next,[H|T]),
      path([Next,H|T],Y, Path).

adjacent(H,Next) :- d(H,Next);d(Next,H).

If you combine this algorithm with the horizontal/vertical movement you can get it to work pretty easily...

You may also want to check this link:
Or this one:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.