Comparing Lists 
Author Message
 Comparing Lists

Hi.

I'm new to Prolog and I think its a fascinating language.  I like it much
better than the others I've written in before.  Unfortunately, being new to
a language leaves me with a learning curve to deal with.  I'm in the middle
of writing a small game program but I'm having a little trouble executing a
function.

This function that will determine if all 4 players are in the first room and
nobody is in the second room

Here is the state I want to check.

[ [alice, mary, john, joe], [] ]

1. I want to check if the input provided is equal to the above state.
2. I'm not sure how to go about checking for the validity.  If I only had
one room, I could use the member function and go through the list one by
one.  But with two lists, I'm a little lost.

If anybody can help me out or point me to a online tutorial, I'd appreciate
it.

Thanks.



Tue, 20 Sep 2005 02:29:54 GMT  
 Comparing Lists
Dear User,

Quote:
> This function that will determine if all 4 players are in the first room and
> nobody is in the second room

> Here is the state I want to check.

> [ [alice, mary, john, joe], [] ]

> 1. I want to check if the input provided is equal to the above state.

There is no one way to do it, of course. It appears that you have only 2
rooms. You may want to represent who is in them by a tuple rather than a
list, such as in_rooms(Room1,Room2), where Room1 and Room2 are lists of
the people in each room. Then if you want to check whether PlayerA is in
Room1, you can use memberchk(PlayerA, Room1). If you want to check that
Room2 is empty, you can use
Room2 == []. You may also be able to use unification. For instance, if
the lists of players are alphabetized, then you can just see if

in_rooms(Room1,Room2) = in_rooms([alice,joe,john,mary],[]).

Of course, you would probably use unification through matching.

Good luck!

Bill



Tue, 20 Sep 2005 04:00:29 GMT  
 Comparing Lists

Quote:
> Hi.

> This function that will determine if all 4 players are in the first room
and
> nobody is in the second room

> If anybody can help me out or point me to a online tutorial, I'd
appreciate
> it.

http://www.amzi.com/AdventureInProlog/advfrtop.htm
This tutorial should be perfect for you, as it actually
discusses rooms and things being in rooms.


Tue, 20 Sep 2005 07:37:28 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. comparing lists

2. NEWBIE QUESTIION: Comparing Lists in Python

3. compare lists

4. comparing lists

5. Comparing list element with 'sant

6. comparing lists

7. comparing lists and/or tuples 'by pointer'

8. How to compare infinite lists?

9. comparing all values of a list to regex

10. How to compare two lists ?

11. newbie: comparing mutually recursive lists

12. Comparing 2 lists

 

 
Powered by phpBB® Forum Software