Skip to main content
GameDev.net gamedev.net
🔒 Locked

Animal behaviour

Started by CProgrammer Jan 23, 2004 at 11:45 PM 12 replies 1.2k views
Original Post
CProgrammer
CProgrammer
I have a group of animals. Each has saved which of the other animals he likes to be in company with. Now I want to calculate a group in which all animals like eachother. I just cant seem to come up with a descent algorithm. Any ideas pointers? -CProgrammer
CProgrammer
CProgrammer
Does somebody perhaps have a small code example in C/C++
for specifieing cycles in a directed graph?
-CProgrammer
CProgrammer
CProgrammer
Wait a sec. If I find out the cycle in a directed graph would that really be correct?
Lets say this example:
We have Animal A,B,C,D,E,F

A->B->C->D->A
is a cycle.
Then it isnt said that C likes A for instance.
-CProgrammer
Captain Nuss
Captain Nuss
To pick up your ABCDEF example...

Take animal A. Check which animals it likes to be with, animals B, D, E and F for instance. You can drop animal C already, as there will be at least one animal that doesn''t like C. So you''ll be left with animals A, B, D, E and F. Now go to the next animal (B) and check which animals in the group it doesn''t like. Eliminate those and go to the next one.

This method has its weaknesses, but it''s a very easy solution. The problem is, that if B doesn''t like E, but the other ones like E, if B gets thrown out by animal C, E isn''t in the list even though no animal is left in the group that doesn''t like E. You can probably work around this somehow by keeping another list of animals that have been thrown out and checking that list when you''ve assembled your basic group.

- Christoph

---
Teamwork Software - Stuff That Does Something
CProgrammer
CProgrammer
quote:
Original post by Captain Nuss
To pick up your ABCDEF example...

Take animal A. Check which animals it likes to be with, animals B, D, E and F for instance. You can drop animal C already, as there will be at least one animal that doesn''t like C. So you''ll be left with animals A, B, D, E and F. Now go to the next animal (B) and check which animals in the group it doesn''t like. Eliminate those and go to the next one.

This method has its weaknesses, but it''s a very easy solution. The problem is, that if B doesn''t like E, but the other ones like E, if B gets thrown out by animal C, E isn''t in the list even though no animal is left in the group that doesn''t like E. You can probably work around this somehow by keeping another list of animals that have been thrown out and checking that list when you''ve assembled your basic group.

- Christoph

---
Teamwork Software - Stuff That Does Something



Thats a way to go yeah, although that problem may get tricky and CPU consuming, but i''ll think it through thanks.
-CProgrammer
emilk
emilk
one word:
boost::graph
CProgrammer
CProgrammer
Hey thanks guys. I think I found an answer now. Kinda a mix of everything.
-CProgrammer
Zahlman
Zahlman
If I understand your question correctly... google for "maximum clique".
Dreamforger
Dreamforger
quote:
Original post by Zahlman
If I understand your question correctly... google for "maximum clique".

... and shortly after that find out that you are trying to solve a NP-complete problem which I doubt you will succeed at. I fact I know you will fail.
I may be getting older, but I refuse to grow up
CProgrammer
CProgrammer
I think you guys are right, an absolutely correct answer requires calculating all possibilities and taking the best one.
Thats a bummer but well...
-CProgrammer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.