1.    Visual Prolog example program of Artificial Life   2

2.    Structure of the project   3

2.1.    The food class  4

2.2.    The creatureMotor class  4

2.3.    The creatures class  4

2.4.    The pointsWin class  5

2.5.    StatsTabForm class  5

2.5.1.    Picturespack   5

2.6.    FamilyTreeWin class  5

2.7.    LogReport class  6

2.8.    StatisticReport class  6

2.9.    Tools class  6

3.    Explanation of the “model”  7

3.1.    Food   7

3.2.    Families  8

3.3.    Properties  8

3.4.    Mutations  9

3.5.    Normal creatures  10

3.6.    Predators  10

3.7.    Cannibals  10

4.    The windows and functions  11

4.1.    Alife window    11

4.1.1.    Statistics report  12

4.1.2.    Diary report  12

4.1.3.    Familytree report  13

4.2.    Points and statistic window    14

4.3.    Message window    15



1.                    Visual Prolog example program of Artificial Life


This Artificial Life exercise is more a demonstration how to program, use objects and make animation type interfaces with Visual Prolog than a serious Artificial Life model. Some links to Artificial Life pages



In chapter 2 is explained the structure of the model and in chapter 3 the general idea of the model. Chapter 4 describes the main windows and the available functions.

There are no copyright restrictions with the source code on my side expect with use of the picturesDLL.dll. PictureDLL is only allowed to be used with this project. I hope this example project gives some ideas and hints how to solve some programming problems with Visual Prolog.

If there are some limited and exact questions of this example project, send your question to kari.rastas@welho.com.

2.                    Structure of the project

In the diagram below is an overall view of the structure of the example project. The following documentation is on a rather limited and focuses only to some main points.  

2.1.             The food class

The food class has two constructors. A food machine object which answers of creating the new food objects with a wanted interval. The other constructor is newFood() for new food objects.

The food object informs the creature class of a new food object.


        X = math::random(right-20)+10,

        Y = math::random(down-20)+10,

        P  = math::random(100),



This demo program uses two different foodMotors which create new foods with different shapes and intervals.

The food class inherits drawObject interface which takes care of the actual drawing.

2.2.              The creatureMotor class

The creatureMotor objects function is to listen to the movements of the creatures and inform the AlifeWin of the drawing need. The creatureMotor class inherits drawObject interface which takes care of the actual drawing.

CreatureMotor object has also the knowledge of the bitmaps of the different creature families. In this demo there are three different creature families with different shapes. It would be easy to add more families.

2.3.             The creatures class

In the creatures class handles all the rules and movements relating to the creature objects. The constructor of a creature objects is

        newCreature : (integer Family,
Generation) (i,i,i,i,i,i,i,i,i,i,i,i,i,i).

In this simple model the “genotype” from the mother is delivered through parameters. When the creature is “born” it goes through several mutation possibilities.

Each creature has its own timer (got from the timertool class) and it adds a timerListener to the cretureMotor object.

The creature provides class facts and class predicates to collect and fetch statistical data.

        getStatisticsData:()-> string.


        getLogReportObject: (logReport LogObj).


        getSpeedFigures:() -> integer_list LIST.

        getVisionFigures:() -> unsigned_list LIST.

        getReproductionFigures:() -> unsigned_list LIST.

        getPredatorList:() -> unsigned_list LIST.

        getIntelligencePercent:() -> real.

        setPlayGroundDimensions:(unsigned X,unsigned Y).

        setCreatureSize : (unsigned X,unsigned Y).





2.4.             The pointsWin class

The pointsWin object has three functions

The data for the family points are collected from the creatures class every 1 second using a timer. The statistics of the simulation are updated every 3 second.


2.5.             StatsTabForm class

Statistic class provides a frame and customControl for the statistic charts. The data is got from an external database and then transmitted to the DLL with takes care of the actual chart generating.

2.5.1.               Picturespack

Pictures pack consists of a pictureControl class, a timeseriechart class which provides the predicate links to the PictureDLL. It also has lib file for that dll.

2.6.             FamilyTreeWin class

FamilyTreeWin form uses a custom control modified from the PDC’s TreeControl class.

The tree information is collected in the creatures class using the code.

% Creating family tree ********************************************************

class facts - familytree

    motherChild:(string Mother,string Child).


class predicates





        living(_,Child,_,Mother,_, _,_,_,_,_,_),









class predicates

    collect_tree:(string NODE,integer N,treeControl::tree TREE) procedure (i,i,o).

    collect_tree1:(string NODE,integer N,treeControl::tree TREE) nondeterm (i,i,o).




    collect_tree(NODE,N,treeControl::tree(string::format("%1%",NODE, getType(toTerm(NODE))),treeControl::unmarked,TREEL,4)):-








    makeTree() = TREE:-







2.7.             LogReport class

The logReport object saves all the main events of creatures’ life. It also saves the log report in a file


2.8.             StatisticReport class

This class creates a report of main properties of each living and dead creature.


2.9.             Tools class

Tools class is a collection of tool predicates used in the project. Predicates like index, member, mean etc.


3.                    Explanation of the “model”

The basic idea is to see how some features of the creatures develop during time. In the pictures below is development of speed of living creatures and the population’s size. In the beginning when there are no predators the speed is not very essential. When the amount of predators increases only the fastest normal creatures survive.


3.1.             Food

Food appears in a random point of the playground every 400 ms (foodCreationInterval : integer := 400). The point value of the food is between 0 -100 points.

The food rules in this model are simple. It could be made more complex for example by adding a seasonal “flow” of food. In winter food supply is smaller than in summer.


3.2.             Families


In this example there are 3 different families or species. The start values are the same for each family.


3.3.             Properties

Each creature moves by its capabilities and by the impulses it gets from the other creatures.

() ->integer.

() = N:-
S= tools::randomNormalDistribution(),!,
N1 = averageLifeTime + math::sqrt(varianceLifeTime)*S ,
N = convert(integer,N1).

decideBiologicalAge() = averageLifeTime.



When a family is very dominant the predators are not “effective” because they can not mutate to cannibals in lack of food. In that case if one member of the other remaining families mutates to a predator, they have much food and can a relative short time change the situation.



A creature dies when it


3.4.             Mutations

Mutations of each property happen randomly when a new creature is born. The probability of a mutation in each property is 10 percent. The mutations can happen in both directions, expect that the children of predators can mutate only to cannibals. The children of cannibals are always cannibals.

The mutation increase in speed is +10 or -10 percent of the mother’s value. In Vision +20 or -10 percent and in reproduction limit +10 or -10 percent.

Which mutations survive and became dominant depends in which direction the “society” develops. In a highly competitive environment the next creature generations became faster. The predators create a long vision range. In “peaceful” society with only one family, the predator mutations have no food, so speed is not essential for surviving.


3.5.             Normal creatures

Normal creatures hunt for the food in their vision range. If a predator occurs in the vision range they try to flee.


When the points of a creature are less or equal than zero it dies.

3.6.             Predators

The new creatures can mutate to a predator when it is born. It means that they do not anymore eat normal food. They eat members of other families. After catching a prey the predator spends 30 time intervals eating.

When there is no prey in the vision range the predators walk slowly to the centre of the playground. 


3.7.             Cannibals

Predators can mutate to cannibals. It means that they eat also own family members (except their mother or a mother its last child).


4.                    The windows and functions

There are three windows.

4.1.             Alife window





By placing the cursor on the wanted creature and pressing the left mouse button you get the data of the creature in question.









By clicking the right button of the mouse in the Alife window you get a report in sight.

4.1.1.                     Statistics report



The report window has in the top left corner a button. By pressing it you can change from statistics report to a diary report. Family tree button shows the FamilyTree report.

4.1.2.                     Diary report


4.1.3.                       Familytree report

Familytree shows the development of the creatures in a tree form. Familytree is a modification of PDC’s treeControl. It shows with colour the development of the wanted feature in each generation. The lighter the colour is the smaller the value is compared to the start value.


4.2.             Points and statistic window

The Points window shows the points of each family and what is the present average of the main properties.


The Points window acts also as a link to the statistic charts. In the bottom of the window are buttons for creating the charts of the main properties. The button is enabled after 30 seconds from starting. This is because before the charts can be presented they need a minimum data.

The statTabForm form has the PDC’s tabControl. Each six different charts use a pictureControl in which the actual picture is drawn. The statistical data from the external database is transported to the PictureDLL with some picture formatting commands.


4.3.             Message window

In the message window are listed the happenings in the Alife simulation. In the pointsWin is a checkbox for disabling showing messages in the Message window.