Matrem is a computer program that simulates life. It belongs to the emerging science of "artificial life", which studies evolution and complex systems in general by simulation. Matrem is also a game, where players compete to create the fittest lifeform. Their efforts are the driving force behind the program.
So what does the program do? It creates a little ecosystem, with land and water, trees, grass and rocks. This world is inhabited by creatures, which struggle to survive. They hunt and are hunted, they starve or multiply. All this is governed by simple rules, that say what creature is able to do and how their environment changes. Complexity can emerge from the interaction these animals have, as they try to defeat their rivals in the battle for fitness.
Artificial life uses the process of evolution to create complexity. I
actually don't know anything else besides intelligence that can do that, which makes this a very interesting subject. Evolution exists in many things, but it still very hard to study, because the process of evolution usually takes a long time. With the emergence of computers more became possible, although the time limit keeps pressing. The trick in Matrem is that it does not use spontaneous
mutation as a way to change properties of a creature. It is deliberately modified by humans, which speeds up 'evolution' a whole lot. But Darwin is always the gamemaster, killing those animals that are not adapted well.
'Playing the game' is easy: you create you own creature! This means you give it a few properties, and, what is most important, you decide how it will behave. To do this you have to program a little piece of code in c++, something I will explain about in the chapter 'How to be a Player'. Right now I'll just promise that it's very easy, and does not even cost a lot of time. You don't have to be a computer-wizard, and you don't need large amounts of experience in programming: a basic knowledge of programming is enough.
The source code of Matrem is all open, so you can check out
how it
works. It is also platform-independent: it should work with DOS, Windows,
Linux and Unix. Hardware minimum is minimal: if you have a 386 or better,
with a little bit of memory, you're ready to go! I have done a great deal
of the programming on a machine I bought for $40 in a second-hand
store. If you want to compile the program yourself you can do that with a
compiler and graphics library that are available on the internet for free,
and that I have been using for this program. They're great! Make sure to
follow all the instructions when you install them.
DJGPP, a free 32-bit DOS-compiler:
http://www.delorie.com/djgpp/
Allegro, a game programming library:
http://www.talula.demon.co.uk/allegro/
After this introduction, maybe you want to take a look at the game first, before you read on about the rules. Well, there you go:
For the program Matrem and all it's parts that are available on this page, the gpl licence applies.
I hope to explain all the rules as simply and clearly as possible, all the information about the game should be here on the web, so if you think something is missing, please tell me. This is all there is to it, it is really not all that complicated. I have omitted most of the specific numbers and details, they are described in another chapter: Details of the Program.
VOID (there is nothing on the tile)
WATERPLANT (river, filled with nutritious plants)
WOOD (the forest)
STONE
FIRE
GRASS
ROCK1 (heavy rocks)
ROCK2 (medium rocks)
ROCK3 (light rocks)
RIVER (permanent water)
WATER (temporary water)
SUPERROCK (the Wall)
Besides this, each tile can contain one (dead or living) animal.
This environment changes of course with time: there are fires and plants grow. The rules are:
If a creature stands on a tile, this tile cannot change. The world starts in a certain situation, which is read from a bitmapfile: map.bmp
So now I just have to prove that it is really easy to join the game and start playing. I will give all the information about the inner workings of the program, but now it's time for
Download Matrem for Linux (.tar.gz-file, 91k)
Download Matrem, source only (.zip file) (97k)
Download Matrem for DOS/Windows (255k)
Download Matrem for DOS/Windows, Visual C++
project (1384k), thanks to Abhinav Mathur
Debian package is available on repositories (as "matrem").
Note that you need the Allegro game-library to run or compile the game. For running without compiling you need only the binary version.
Unzip the files in one directory, and run matrem.exe (Dos) or matrem (linux). And there are the creatures, running for their lives already! Use the mouse to scroll around the map, use the right mouse button, or 'm' to get to a menu with options to get another view on the situation, adjust the speed, or do some divine intervention. 'q' quits. More information about how to control the program is in readme.txt.
Well, that was not too hard to get it running, was it? Now to get some insight in the program, take a look at the file "milkacow.cpp", conveniently mirrored here. It starts with some programming declaration rubbish, but then there it is: the milkacow::milkacow procedure. This is called a constructor: it initializes a milkacow. But what is of our interest is that all the properties that were described above are clearly quantified here, and are therefore easy to change. If you have already installed djgpp and allegro you can change something here and recompile the program, and your changes are in direct effect. Make sure to include all the *.cpp files in the project. I prefer to use Rhide, an editor/compiler that comes with djgpp, I open the project "matrem.gpr", and compile.
On to the next function: choosejob(). This function is called repeatedly in the program, and here is where the milkacow decides what to do. This is stored in the variable job. So for a test you can try to replace this function by:
void milkacow::choosejob()
{
job=SLEEP;
}
And you will have cows sleeping all over the place.
classes
An object or class is a way of organizing your variables and functions. It means you bundle some variables together and give that another name. For example:
class vector
{
public:
int x,y,z;
};
"vector" is now a new type of variable. You can make new vectors and use them like this:
vector v1,v2; v1.x=3;v1.y=5;v1.z=10;And use them in function like this:
float magnitude (vector v)
{
return sqrt(v.x*v.x+v.y*v.y+v.z*v.z);
}
The nice thing is that this function can be defined in the class itself, which makes a lot of sense, because it only applies to vectors. So define the class vector as:
class vector
{
public:
int x,y,z;
float magnitude()
{
return sqrt(x*x+y*y+z*z);
}
};
And call this function with:
float m = v.magnitude();Note: this function is usually implemented outside the class with the :: operator like this:
class vector
{
public:
int x,y,z;
float magnitude();
};
float vector::magnitude()
{
return sqrt(x*x+y*y+z*z);
}
Now it is nice that we can make use of existing classes when we want to make a new class. Suppose we want to make a class of vectors that also have a color (I don't know why, but suppose). This new class has only one addition so we can derive it from the old vector class like this:
class cvector : public vector
{
public:
int color;
};
And that's it! We can make variables of types both "vector" and "cvector".
class vector
{
public:
int x,y,z;
vector();
~vector();
float magnitude();
};
vector::vector()
{ etc...
pointers
Now pointers are things that people tend to get confused about, although it is not all that complicated. To refresh your memory: a pointer is a reference to the memory that is used by a variable. The type of the pointer is the type of the variable that occupies the memory, like this:
int *ptr; int i,j; i=1; ptr=&i; j=*ptr; /*j=1*/ *ptr=3; /*i=3*/And there you have all the possible operations with * and &. So ptr is a pointer to an int-variable (first line). Then it is set to point to the memory of i with the & operator. The content of this memory is read by using *ptr, so in this case that is equivalent to the int variable i. Now, when it gets interesting is when you look at classes. A pointer can reference to any type of variable, so also to classes. Let's make a pointer to a vector:
vector v; vector *vptr; v.x=3;v.y=7;v.z=1; vptr=&v; /*vptr points to the variable v*/ (*vptr).x=1; /*v.x=1*/ vptr->x=1; /*v.x=1*/Pay attention to the last line: it is equivalent to the line just above it. The arrow(->) is used to make the program clearer. In matrem it is used a lot.
structures in matrem
All creatures are objects and derived from the base class that is called "creature", and which is defined in the file "creature.h". It is there, where all the function and variables that all the creatures have are defined. An example of a derived class is the "milkacow" class. In the derived class the functions that are declared virtual in the base class can be redefined. An example is the choosejob() function, that is redefined to make the milkacow behave in a certain way. I have worked a lot with pointers to creatures in the program, so to give an example about how to access functions and variables in objects in pointers:
milkacow cow;
creature *cr;
cr=&cow; /*the creaturepointer cr points to cow*/
/*all the base class variables and */
/*functions are now available */
if (cr->food<1000)
cr->job=EAT;
cr->choosejob();
Most of how to use this you can see in the program itself. That was it for the introduction on objects and pointers in Matrem.
r[43][113]->species==MILKACOW.
for (dir=0;dir<3;dir++)
if (p[xcoor+dx[dir]][ycoor+dy[dir]]==GRASS)
{job=TAKE;break;}
Because dx and dy are defined like this:
dx[0]=0; dy[0]=-1; dx[1]=-1;dy[1]=0; dx[2]=0; dy[2]=1; dx[3]=1; dy[3]=0;
creature* newcreature() {return new milkacow(this);}
char shortkey() {return 'c';}
If you want to make more than one creature you have to make one from scratch. With a little bit of copy and paste this is not too hard either. All you
need to do is to take these simple steps:
1.
choose a name for your species, let's call it 'unicorn' for this example,
2. copy the file "milkacow.cpp" and rename the copy to "unicorn.cpp", copy the file "milkacow.h" to "unicorn.h"
3. REPLACE "milkacow" everytime it appears by "unicorn" and "MILKACOW" by
"UNICORN" in unicorn.cpp and in unicorn.h
4. Edit "config.h", and add in the list of all species the line:
#define UNICORN nwhere you have to put the (old) number after N_OF_SPECIES in place of 'n'. This number is the number of the new species. Now increase the number after N_OF_SPECIES by one, so that it becomes n+1, capiche?
if (species==UNICORN) firstcreature[species]=new unicorn;Go to the start of "matrem.cpp" and add after all the #include lines:
#include "unicorn.h"
Now to be a REAL player, send your little invention to me by e-mail, so I can include it in the matrem-version here on the web. Now your creature can truly compete with the ones that other players made, and the struggle for life goes into a climax. This means you don't have to be able to compile the program yourself, if you send me the cpp file and a picture of your species, I compile it and put it in the matrem.exe file.
I want to be as open as possible about all the little rules that are in the game, so here you'll find all the details and numbers that play a role in the game. So you don't have to look up how everything works in the source code.
weight=hitpoints+power+health+speed+
200*{number of items in diet}+200*{number of accessible terrains};
Each time the creature does a job, it loses an amount of food equal to 1/300 of its weight.
There are four creatures in play now, made by me or Remco Veenstra, and
one other:
mightyMouse was made by Harry Maierhofer: our very first external
player!
If you like this game: don't just download it, please play with it, modify
or make a creature and let me know. You might like it.
I know, it is about time to introduce myself. My name is Mathijs Romans,
I'm 21 years old and study physics at the University of Utrecht, the
Netherlands. Currently
I am on an exchange program at the University of Wisconsin-Madison, USA. I live in Madison at Nottingham.
There are two books that generated a lot of interest in complex systems
and artificial life for me. In high school I read "The quark and the
jaguar" by Murray Gell-Mann. This is a very understandable book about
complexity and the ways it emerges in nature. Three years ago, I read
"Artifical life: the quest for a new creation" by Steven Levy, which is
the best introduction one can
have in this subject. I started experimenting on the computer, because I knew a bit about programming.
But one night about a year ago, I was talking to my flatmate Remco, and we got the idea of making a game that is partly programmed by the people that play it. The idea for matrem was born. We used the first three letters of our names for the word matrem. I used parts of a program that I already made to start the first version of matrem. It was very crude, it looked very bad (especially because I started with pictures of creatures that were only 5x5 pixels) but nevertheless my flatmates liked it. Their enthusiasm and ideas made me go on and improve the program. I have always believed that programming is a great way to express creativity, and I know a lot of people don't agree with that. But there is a lot of freedom to make whatever you want, it's very playful. Matrem can be a very entertaining program, and interesting at the same time. Many ideas from ecology and evolutionary biology can be applied to the simulation. I have seen the creatures occupying different niches, how the addition of one species can mess up the entire ecosystem, the importance of mutations, and I hope to see much more. There is freedom to add and invent, to create and play. I hope everybody will enjoy it!
Madison, 12/17/1999 & Madison, 17/12/1999.
If you have any questions, comments, critique, suggestions, or you want to join the game, do not hesitate to contact me at matrem at romansland dot nl
Please copy the program for others and tell them about it.
- Updated the Who's playing new section
Matrem version 1.0 on the web! New improvements:
- Linux version is complete
- Resolution up to 1024x768
- Made a 'results' menu with average populations and biomasses
- Fixed some bugs
- Header files for all the creatures were made
- Yourcreature-example added
- Readme.txt with information about how to use the program added