James Ewen's AI Project
S.P.A.M.: Simulated Predatory/Prey Artifical Model

Contents
Domain
Illustration
Methods
Conclusions

Domain

S.P.A.M. - Simulated Predatory/Prey Artificial Model is a self-contained program designed to simulate the behavior and patterns of a synthetic world, which contains a group of flocking agents, considered prey, and the "intelligent" agents that hunt them down. It was designed to run independently off of some initial settings - and create a history of events in the world, which can then be interpreted into a visual form for entertainment and study. Currently, while progressed enough to exhibit behavioral results, this system is still young and will be refined dramatically over time. Right now it is in a state of two separate worlds - one created for the flocking agents and one for the thinking predators. While open for a number of initial parameters - the basic scenario will consist of cast communicating hunters attempting to track and kill, for survival, a herd of evasive prey.


Illustration

S.P.A.M. is a young program that will soon grow to include all sorts of features - including a dynamic interface that will visually render the program as it is running. Currently, the data that is returned by S.P.A.M. for both separate worlds is text that tells the user where each agent is at each instance of time or state. Currently, only coordinates are given back from the flocks and the hunters - but with simple editing, it can also return to you important aspects as it runs - such as whether a sheep or wolf is dead in a state, or if a wolf is hungry or eating, and even who the wolf is trying to attack. While right now the code for S.P.A.M. is facing minor optimization problems (i.e. IT RUNS REALLY SLOW AND USES ALL YOUR MEMORY) these issues will be resolved and updated over time (as well as this web page). In order to run the program, you need to have a SICStus Prolog development environment. Simply load the file and ask prolog to run it the number of times you wish to cycle by typing
?| execute(N).
with N being the number of cycles you want. (In the code for the flocking sheep - executesec(N). will run the cycle that many seconds - each cycle equivalent to 1/60 a second). You can view copies of the code here:

hunters(from video 1)

and here:

flockers and the files contaning the characters to be used

It should be noted that these are simplifed versions of the code and if you want the more complicated version (though that one will run even longer) you can just email me and I'll be more than willing to share - heck i'd appreciate the help. look below to see a few movies created by this data along with an example


Methods

How the program actually works is such:

FOR THE HUNTERS:

Currently they are placed in a rather dull environment - their prey doesn't attempt to allude and there are no obstacles to avoid. This is how they think - wolves will start off in a certain location of the world: is_at(wolf1,pos(10.0,10.0),init).

and what is desired is it's next pos in the next cycle. This is computed on many factors - is it alive?, is it hungry? , is it attacking a sheep? all of these are represented as specific queries:

health(wolf1,40,init).
alive(W,S).
hungry(W,S).
go_attack(W,A,S).

and for each simulated cycle, these factors are calculated. Some results are - if it's dead - it won't move anywhere. If it isn't hungry - it'll just hang around its home position. If it is hungry - then it will hunt. Now this is when it gets interesting.
Unlike automatic systems that mimic behavior by simple rules (which is what the flocking sheep really are) - the wolves think about this one. First the wolf will consult its point of view - does it see anything worth looking at? And from this, the wolf will choose a target from its possible choices - which sheep is it best for me to hunt? Following the basic guidelines of nature - the wolf will attempt to hunt down the sheep with the lowest health value, i.e. the sickest. But not only will it consider it's personal best target - the wolf will actually communicate with any other hunting wolves and ask for THIER best target. Collectively, this group will decide exactly which sheep to attack!
From this point on - that's just what it does, with one interesting side effect - these wolves exhibit selfish behavior - if one eats a target before the others get to it - it will actually ignore them and walk away satisfied, thus the other hunters will have no idea where that meal is unless they stumble upon it - or they have to go get another one themselves! This was an unforeseen result (seen in video 2 briefly), which turned out to be quite amusing.
If you are interested in viewing the results of S.P.A.M. in action - below are posted two different videos of the same wolves in different environments. In video one - coincidentally there doesn't seem to be much action going on -a result of ill initial points, and possible corrupt interpolation. However, in video two - the results are more interesting. Right away a wolf makes a kill - and then ignores the others. If you follow the attached data (as the info screen was cut off in processing) - you will see the wolves have to search and make a new target, until they luckily stumble upon the body of the previously killed sheep.

The first video is here and the corresponding data sheet is here.
The second video is here and the corresponding data sheet is here.

** a word to note - the data given has been edited for content and cleaned up for ease of view! the actual can sometimes be crude and needs refinement!**

FOR THE PREY:

The flocking agents act quite differently from the thinking agents. They don't actually "think" at all - they behave. Their entire system of movement and perception is based off of a series of acceleration forces between object - some attract some repel, and these are mathematically used to calculate the agent's velocity and then position based on the next stage (which have to be viewed as a change in time to correctly work) They simply follow 3 rules (directly or indirectly):

1. The attraction of the agents to each other - FLOCK CENTERING.

2.The adjustment of each individual agent's velocity to match up with the rest of the flock's velocity - VELOCITY MATCHING.

3.The avoidance of any direct collisions with any other agents or objects - COLLISION AVOIDANCE.

These three "rules" were first proposed by Craig Reynolds in his "Flock, Herds, and Schools: A Distributive Behavioral Model"(1987). While the rules are easy to understand - correct implementation is a little tricky - which Reynolds on vaguely mentions an answer to. For the sake of simplicity, and also due to only a novice grasp of Prolog, I circumvented the Flock Centering problem by introducing a 3rd agent - a butterfly - that moves along at it's own pace, but which the agents are attracted towards. With the addition of a velocity-averaging predicate - this helps keep the flocks together, but also serves to satisfy the following two criteria. Obviously Velocity matching is done this way, however this also helps to prevent collisions within the flock by having an agent speed up and slow down when a collision may happen (occasionally collisions will happen, but that is also common in real world herds). With these rules applied, along with a repulsive force to the wolves and an attraction to the center of the scene (to avoid wandering) - the flocking behavior is evident. Unfortunately, given the operational limitations of the code in it's current state, to clearly see this behavior is quite difficult. These rules were proven in another program that was implemented in Java - the same one that will be used in the future to help further this project.
Along with fluctuating health meters - which indicate when a sheep is dead and when it is tired/hungry, an key element when it actually comes down to hunting - that is all that there is to the flocks. Clearly much more mechanical than the thinking agent hunters (a reason as to why more emphasis was on their development). If you are interested to see these rules in action or study them yourself - I've provide links below that will help you gather more information.


Conclusions

In closing, I found this project to be worth the effort put in. I wish I had more time to refine it - and to sleep- but I know that this is not something that will be ignored, and when the opportunity rises, I will definitely work on it again. I found that this particular field of artificial intelligence in modeling behavior creatures (also know as Artificial Life) is very fun; it's amazing to see the results that can be accomplished with just a few short rules. With this combination of an AL flocking system and an actual thinking system - I see the opportunities for development to be both challenging and fun.

My final paper can be read here.

For those of you that might be interested in this field of AI, here are several links that I found to be invaluable in my research for this project:

Craig Reynolds - the guy that started it all
This is a very interesting paper from Harry Brignull about Reynold's boids
Floys!
Java Flies - really cool
An A-Life Database
Java Applets for Neural Networks and Artificial Life
Artifical Life - FISH!
A swarming applet
Jonathan's 8th Grade Project - 8th GRADE?!?!
Terzopoulos - this guy is awesome
Funge - these guys from Toronto know their stuff