Complex behaviour from simple scripts
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
05-27-2005 03:53
When I first set out to create scripted AI fish the main aim was to simply make them look good. I had no interest in the actual result as long as it did as intended.
I wanted to make a shoal of fish that would swim around in my pond in Freelon and look pretty, nothing more. I thought this would be achieved with a big complex script to reproduce the apperent complex behaviour of a shoal of fish. How would I make 30 fish all turn at the same time?
A year and several hundred code revisions later I realise that the script which has evolved is smaller than the initial top down script I first wrote. It only has three main functions, just one Sensor 'ping' per script cycle, no timers, no listens, no comunication with other fish. IT IS SO SIMPLE. Why had I not thought of this a year ago?? I wish I had...
In the real world a single fish on it's own actually does NOT do anything complex. This is the magic trick that I missed at first. By trying to 'code in' the complex activity I was coding out all the other possibilities. A single fish swims, it turns left/right, it looks for other fish. That is it. Nothing more. Putting this simplistic concept into my fish I found that all I had to do was make the fish follow a few simple rules.
1) If I see a fish like me I will swim towards it. 2) If I get too close to another fish I will back away. 3) If I can't see any fish I'll look further. 4) If I see lots of fish I'll reduce visual range.
There is a small bit of code to calculate the center of activity for a group of fish, so rule 1) above is not dealing with a single fish, but the percieved center of a group.
There is no comunication between fish. All decisions are made based on what the fish 'sees' with it's sensor ping.
To be continued.
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
Life and death
05-31-2005 07:58
The fish are feeding.
I left the shoaling script alone and added a second script to the fish. This has two timer functions.
Timer one triggers a sensor ping to look for food prims, if 'seen' an impulse is applied to the fish in the direction of the food. If the fish collides with the food prim it 'eats' it. (The food prim performs llDie(), the fish increases its health rate by 5 points). The trigger rate for timer one is the health level in seconds, so the weaker the fish, the faster it senses for food.
Timer two provides a 60 second 'heartbeat'. With each timer 2 event the health is reduced by 1 point. If health reaches Zero, the fish performs llDie().
The food dispencers create a new food prim every 30 seconds, the number of dispencers is limited and less than the number of fish, so population is controled by availability of food.
Observed results. By the time health reaches 1, the fish is doing a sensor ping every second in order to find food. This will result in overriding the shoaling instinct and the fish will break away from a shoal if it sees food. However, other shoal members will see the fish making a run for it and turn to follow... often another fish arrives at the food first, eats it, leaving the original fish still hungry...
Coming soon, Alien v's Predator, or how I got the fish to flee...
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Moopf Murray
Moopfmerising
Join date: 7 Jan 2004
Posts: 2,448
|
05-31-2005 08:27
This really is an amazingly interesting project Surina. I love watching your fish, observing their behaviour. Putting the camera over the water so I can see a whole area without having to move the camera again, it's interesting to watch how the swimming patterns alter. You'll see them circling, or swimming in figure of eights, then see one break free from the shoal and swim away only to eventually be followed by another couple of fish who meet it, then they all turn back and swim back to the shoal. And the more you watch the more interesting behvaiour you'll see. It's mesmerising watching their emergent behaviour. I eagerly wait each new change you make 
|
Laukosargas Svarog
Angel ?
Join date: 18 Aug 2004
Posts: 1,304
|
05-31-2005 09:35
From: someone The fish are feeding. hooray ! so they're not so bored now then  From: someone Coming soon, Alien v's Predator, or how I got the fish to flee... That should be fun. I look forward to seeing that.
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
Predation and evasion.
06-02-2005 03:48
This is the simplest instinct I've added so far and probably the most effective visually.
The shoaling code uses the object name field for the sensor search, but by (currently) hard coding the name to search for, the fish will shoal with anything. So to create a predator I took a random fish from the shoal, renamed it so the other fish would not see it with their shoaling instinct, and hard coded the 'standard' fish name for the sensor to restore the normal shoaling (for the predator). So we now have a predator fish that will try to seek out other fish, but due to the name change, other fish can not see the predator and hence won't shoal with it. (I also changed the texture so you can tell which is the predator...)
Now the fancy bit. For every other fish I added an evasion instinct. A simple script with one basic function. Using a llSensorRepeat, the fish look for the 'predator' every few seconds. The repeat delay can be quite long as there will always be other fish scanning during the gaps. If predator is sensed an impulse is applied in a direction directly away from the predator. The size of the impulse being inverse proportional to distance from predator.
So that is it, one llSensorRepeat one llApplyImpulse. The rest is all down to the emergent behavior of the shoal. As one fish senses the predator and swims away, the other fish sense the swimming away and turn to follow... The more fish that sense the predator at one time, the faster the entire shoal turns and runs.
Of course, the predator is using the exact same shoaling instinct and so it too tries to follow...
Coming next Fish Wars part II : Attack of the clones...
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Red Mars
What?
Join date: 5 Feb 2004
Posts: 469
|
06-02-2005 11:57
Where are your fish? I'd love to see them
|
Moopf Murray
Moopfmerising
Join date: 7 Jan 2004
Posts: 2,448
|
06-02-2005 14:22
From: Red Mars Where are your fish? I'd love to see them Red, Surina's fish are in Themiskyra mainly and swim into Aretias and Hypatia as well (it's a group of 3 private sims that are visible on the map).
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
Fish Wars episode II : Attack of the clones...
06-06-2005 09:21
Stage one of the Breeding program is to get the fish to somehow reproduce. Coupled with this, they also need to die of natural causes as opposed to starvation.
So the feeding instinct has been modified. If the health rating goes above 15, the fish clones itself. Each fish carries in inventry a copy of the fish object along with it's own scripts. On cloning, the base object is rezzed from inventry and the scripts passed with llRemoteLoadScriptPin(). The base object is also given, else the new fish would not have a copy itself in order to clone.
This also gives the opportunity to pass a form of DNA to the new born fish. Each fish holds it's generation number in the object description. On cloning this is read, incremented and passed as the startup parameter with the scripts. For future use, each script can be passed it's own data in this way, but for now it is just generation number. When the script starts in the newborn, the startup param is read and stored in the object description.
Theoretically this could mean that as long as a fish from generation 0 keeps feeding (and cloning) there would always be generation 1, generation 2 etc... so to force the evolutionary process along the lines of RL I added a termination period. (Thoughts of Blade Runner come to mind). Each fish, regardless of its success, has a predetermined life span. It is in the order of a few hours, so it doesn't interfere with the natural selection of feeding, cloning, starving, but prevents 'outdated' generations from resource hogging. The only difference between generations at this stage is the Generation Number displayed above each fish.
Observed Results
A very minor upgrade was made to a single fish. The upgraded fish was added to an existing shoal. Within 3 hours the upgraded version had taken control of the shoal in numbers. Maximum life span has passed for the first upgrades, however none actually reached 'old age'. Subsequent generations are thriving.
Coming soon :- StarFish: TNG
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Olympia Rebus
Muse of Chaos
Join date: 22 Feb 2004
Posts: 1,831
|
06-08-2005 08:36
Amazing, Surina! I'm way impressed. I make fish too, but like I mentioned before, they're limited to swiming until they smack into something. Then they turn and swim elsewhere. (yawn) Then I read about your fish shoaling, eating, reacting and maybe someday breeding...! Wow! Keep up the good work 
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
Tng
06-09-2005 07:05
The Next Generation has started... again.. There was a minor hiccup that resulted in 3 sims grinding to a halt when the fish got out of control. More on that at a later date.
But the big news for now is that simple DNA is being passed from fish to clone. Only one gene for now, as a starter to see what happens. So what gene would you pass as a first test? Speed? Good looks? I chose Greed.
Why Greed? Well mainly because it is the main influence on feeding, and hence reproduction. As a fish eats it's health level is increased, then over time the health level reduces untill it either feeds again or dies of starvation. If the health level goes above a magic but arbitrary number, the fish reproduces. So it is in the best interest of the fish (and the spieces) to eat.
The first generations of eating fish all had the same hunger level. Every time their sensor scan saw food, they produced a fixed impulse towards the food. This is fine, but does not favour any one fish over another, so the health level was used as a modifier to the impulse size, ie, as their health level dropped, the urge to feed increased in proportion. So feed_Impulse = 3/health;
1/health would also work, but it would not produce a strong enough impulse to break the shoaling instinct. So a fixed 'greed' factor of 3 was found to work just nicely. Recognising that the '3' scaling factor is 'greed' we get Feed_Impulse = Greed/Health, The fish now pass the greed value as a startup param when cloning, adding in a random mutation plus or minus 1. So a fish with a greed level of 8 would produce offspring with levels of 7,8 or 9.
I initially fixed the greed level at 3 because I found it worked, and with every fish the same it really didn't matter. But now every fish could be different.. so what will they decide that the best greed level is?
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Rhysling Greenacre
Registered User
Join date: 15 Nov 2003
Posts: 132
|
06-09-2005 12:04
here's some ways to keep alife under control:
#1: add a prim that yells out "fishy fishy" every 30 seconds on some private channel. if the fish doesn't hear that every minute it dies. put the prim where your fish live. that gives your fish a large area to live in, but when they leave that area they derez.
#2: make a script that when it hears "all fishes die", then all the fishes call llDie(). this is a failsafe against explosive population growth.
#3: it's possible to detect the sim's fps. when fps drops below 300 don't allow reproduction. when enough fish die to raise fps to acceptable levels the fish will start reproducing again.
|
Laukosargas Svarog
Angel ?
Join date: 18 Aug 2004
Posts: 1,304
|
06-09-2005 19:09
From: Rhysling Greenacre here's some ways to keep alife under control:
#2: make a script that when it hears "all fishes die", then all the fishes call llDie(). this is a failsafe against explosive population growth.
That is exactly what I did with my birds and it is a very good failsafe. Basically I have an object that follows me around, if the birds detect it they die. Subsequently my birds have been developed to be temp-on-rez and that can also help limit population expansion. Not so good for long term projects that rely on spawning new generations though.
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
Emergent behaviours
06-10-2005 02:06
In my last post I asked the question "What would the Fish deem to be the best Greed level?" Well, it turns out that its dependent on other factors... specificly predation.
I have two seperate shoals, seperate by their own choice I must add. They tend to stay in the vacinity of the food source, so keeping the feeders well spaced (at least a sim apart) will keep shoals seperate. This allows for seperate evolution. So one shoal is left alone, while the other shoal has a single predator fish constantly hunting them down.
The greed level in the predated (sp) shoal is rising at twice the rate (if not more) than the 'safe' shoal...
My conclusion for this is that increased greed allows faster swiming while targeting the food, hence a dirived ability to out run the predator. Thus the predator is eating the lower greed level fish leaving the higher level to breed.
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Olympia Rebus
Muse of Chaos
Join date: 22 Feb 2004
Posts: 1,831
|
06-10-2005 12:15
Quick question, Surina,
If visitors "greif" the fish (sitting on them, following them, getting in their way), will this screw up the ongoing expiriment? They seem so lifelike it's tempting to play with them, but I fear botching things.
|
Trep Cosmo
Registered User
Join date: 3 Mar 2005
Posts: 101
|
06-10-2005 12:36
From: someone If visitors "greif" the fish (sitting on them, following them, getting in their way), will this screw up the ongoing expiriment? They seem so lifelike it's tempting to play with them, but I fear botching things. I was hangingout and discussing the fish with Surina the other night when an idea hit me (yes it kinda hurt). I'm a huge fan of the show Mythbusters on the Discovery channel. And in one episode Adam and Jamie experimented on goldfish. What they did was they divided their fish tanks and had little holes in the dividers that the fish had to find in order to reach the food at the other side of the tank. So what Surina did when I mentioned this was she sort of put up a fence with a hole on each side around the food sources. The fish are able to find the food, it just takes longer because they have to find the hole by touch. And once inside the fence they had some difficulty getting out because again they can't see the hole they have to feel it. Interestingly enough, the fish inside the fence were not getting the food faster. The reason being that the fish outside the barrier were still shoaling around the fish inside. So what would happen is a speedy fish would end up aligned just right when it saw the food and would be able to dive in and out of the barrier very quickly while grabbing the food. I'm not sure how sitting on them affects them, Surina would have to answer that. I know I've sat on them for very short periods just to be silly, but I'm too afraid to break something if I sat on the for very long. I think the only way to really grief these little guys...would probably be to completely fence them in or block the food source so they can't get through to it. And that would just be mean! So don't do it! hehe
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
06-10-2005 14:56
From: Olympia Rebus Quick question, Surina,
If visitors "greif" the fish (sitting on them, following them, getting in their way), will this screw up the ongoing expiriment? They seem so lifelike it's tempting to play with them, but I fear botching things. There's no specific experiment going on other than seeing what happens. If playing with fish floats your boat then who am I to judge... *grin* Seriously though, I don't think there's much you can do that would 'break' them.
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Rhysling Greenacre
Registered User
Join date: 15 Nov 2003
Posts: 132
|
06-11-2005 01:57
You cannot go against nature, because when you do, its part of nature too.
|
Olympia Rebus
Muse of Chaos
Join date: 22 Feb 2004
Posts: 1,831
|
06-12-2005 16:53
From: Rhysling Greenacre You cannot go against nature, because when you do, its part of nature too. Still, the fishies seem depressed when I try to sit on them... 
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
06-14-2005 06:36
From: Trep Cosmo So what Surina did when I mentioned this was she sort of put up a fence with a hole on each side around the food sources. As a foot note to this, the 'fence with a hole' was simply a prim with a hole in it. I discovered one of the drawbacks of the Havok engine in that it managed to crash the sim 4 or 5 times in less than an hour... so the fence has been removed. For future use I'm working on proper obstacle avoidance, so a 'fence' constructed of several parts leaving a hole would be seeable by the fish and they should be able to work out how to get through other than random chance. (and it shouldn't crash the sim...)
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
06-14-2005 07:00
A quick update on the first genetic experiment. As I half expected, the greed gene steadily climbed in value as the greediest got to the food first. This ultimately resulted in gently swiming shoals where a handfull of fish would suddenly shoot off at warp speed whenever food was sensed. With no cap on the final greed value, and no negative effect from having a high greed value this would have just got worse over time.
So a few negative effects have been introduced for greed. Mainly a reduction in sensing range as greed increases, an extra reduction in health proportional to speed and finaly a reduction in nutrition from the food eaten.
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Johnny Noir
Registered User
Join date: 5 Jan 2004
Posts: 28
|
06-14-2005 08:10
From: Surina Skallagrimson A quick update on the first genetic experiment. As I half expected, the greed gene steadily climbed in value as the greediest got to the food first. This ultimately resulted in gently swiming shoals where a handfull of fish would suddenly shoot off at warp speed whenever food was sensed. With no cap on the final greed value, and no negative effect from having a high greed value this would have just got worse over time.
So a few negative effects have been introduced for greed. Mainly a reduction in sensing range as greed increases, an extra reduction in health proportional to speed and finaly a reduction in nutrition from the food eaten. Careful. One of the things to consider when designing intentionally emergent systems is that - just like a neural network - you only get surprising results if you don't make predetermined judgments. By predetermining that it's bad to have high greed, i.e. manually tying increased greed to a specific loss in some other area, you're limiting the possible outcomes significantly. In my system (which I made significant work on last night, leading me to believe I'll have a running version late this weekend to display), I take a different route: because you're working with DNA, some alleles (i.e. bits in the DNA) have multiple effects. I'm working on increasing the ability to mutate this characteristic (so some critters will have highly independent alleles, some have highly dependent, etc.) but the basic point is that you don't hard-code the 'weakness'. I'd suggest doing something broader: for example, have a cap on the amount of "thoughts" a critter can have in a cycle. This would mean that a highly greedy critter may never get around to being horny (i.e. reproducing), and thus it's genes would disapear. Alternately you could create a food cost for movement (I don't recall you having this yet), i.e. that the more you move (and the faster you do so), the more 'calories' are burned. This would mean that those highly aggressive critters NEED more food, and thus they aren't automatically benefited. The idea is to keep out our preconceptions about what our critters should do, and let them find their own natures.
|
Surina Skallagrimson
Queen of Amazon Nations
Join date: 19 Jun 2003
Posts: 941
|
06-14-2005 08:54
From: Johnny Noir Alternately you could create a food cost for movement (I don't recall you having this yet), i.e. that the more you move (and the faster you do so), the more 'calories' are burned. This would mean that those highly aggressive critters NEED more food, and thus they aren't automatically benefited.. From: Surina Skallagrimson So a few negative effects have been introduced for greed. Mainly a reduction in sensing range as greed increases, an extra reduction in health proportional to speed and finaly a reduction in nutrition from the food eaten. So, as greed increases their speed increases, but their ability to find food is reduced AND they burn more food by going faster AND the food they eat gives them less benefit... You have to remember that my main aim here is to breed realistic fish, not super mutated fish that evolve plasma cannons... Scripting a single fish is relatively easy, making a shoal of 50 fish move together is a little harder, making them look natural is harder still. Making 10 or 20 different spieces of fish that each shoal (or not) and behave different to the others and look natural is 10 or 20 times the work... I've chosen to work on a single fish and get it to evolve itself to produce more fish that work similar, but not quiet the same. Hence producing a spieces. Allowing the evolution to continue while keeping previous versions seperate 'should' evolve new spieces... So the only work done is always on the orriginal single fish.. not on 20 speices of 50 fish... When it comes to AI and AL I'm a total amateur. I'm guessing most of the time and most of my 'experiments' are just that, experiments. It's taken over a year to get the fish to the stage they are now, though I must admit to a long period of inactivity last summer/fall/winter... but I'm learning from my experiments and so even my own knowledge on the subject is evolving as I discover new 'tricks'.
_____________________
-------------------------------------------------------- Surina Skallagrimson Queen of Amazon Nation Rizal Sports Mentor
-------------------------------------------------------- Philip Linden: "we are not in the game business." Adam Savage: "I reject your reality and substitue my own."
|
Matthew Mondrian
What a square
Join date: 8 Jun 2005
Posts: 20
|
06-14-2005 09:53
From: Surina Skallagrimson You have to remember that my main aim here is to breed realistic fish, not super mutated fish that evolve plasma cannons... Maybe so, but do you think you could maybe put laser beams on their heads? From: Surina Skallagrimson I've chosen to work on a single fish and get it to evolve itself to produce more fish that work similar, but not quiet the same. Hence producing a spieces. Allowing the evolution to continue while keeping previous versions seperate 'should' evolve new spieces... The work you've already done is amazing. I think you'll find that, like the original experiments with simple scripts creating complex behavior, it will only take a few inherited/mutatable traits to create amazingly complex species of fish. Right now, your fish are inheriting only "greed". For simplicity, I'd suggest a total of three traits and a total of three "costs" for those traits. Something like this - Trait Cost Greed Higher speed = less health Size Larger = lower speed (larger/smaller offspring) Faster Reproduction Increased hunger (health rate x2) (twinning/lower repro value) With just these three traits, there are a wide range of possible "species" that could succeed. Small, greedy fish that reproduce quickly. Slower fish that live longer. And so on. (Some other things come to mind as well to tie these together a little better - make health a variable that matches size, so a bigger fish can go longer without food; make the ability to "defend" against a predator depend on the relative size; things like that.)
|
Red Mars
What?
Join date: 5 Feb 2004
Posts: 469
|
06-30-2005 12:33
From: Surina Skallagrimson A quick update on the first genetic experiment. As I half expected, the greed gene steadily climbed in value as the greediest got to the food first. This ultimately resulted in gently swiming shoals where a handfull of fish would suddenly shoot off at warp speed whenever food was sensed. With no cap on the final greed value, and no negative effect from having a high greed value this would have just got worse over time.
So a few negative effects have been introduced for greed. Mainly a reduction in sensing range as greed increases, an extra reduction in health proportional to speed and finaly a reduction in nutrition from the food eaten. Pardon me for butting in rudely, but some predators are drawn to sudden motions, such as sharks drawn to an injured fish wildly struggling. Would a second predator that's more attracted to fish swimming quickly than fish swimming slowly put a more natural barrier to this?
|
Johnny Noir
Registered User
Join date: 5 Jan 2004
Posts: 28
|
06-30-2005 12:49
From: Red Mars Pardon me for butting in rudely, but some predators are drawn to sudden motions, such as sharks drawn to an injured fish wildly struggling. Would a second predator that's more attracted to fish swimming quickly than fish swimming slowly put a more natural barrier to this? That's a good suggestion. Since the sensor() event passes the object's velocity, it's entirely possible to design a predator that would only respond to high speed (in fact, it sounds somewhat interesting). At the very least, it should make for some interesting interactions.
|