📜 ⬆️ ⬇️

Analogue of the game "Life" - Evo

Greetings to you, habrazhiteli!

I recently read an article about the game Life , and I remembered that in May of this year I began to write my own project of a similar orientation. Only now the interest in him for the routine work quickly faded away, although it was written a lot. And now, inspired by this article, I took this project from the dusty shelf and added a few features, which I will discuss later.
In short, my version has the following conditions:
Who are interested in the details, please under the cat!

Short description


I called the program Evo ( git ), since it was originally planned for organisms to evolve there. But nothing prevents the very description of the behavior of living creatures and load it into the program. At the moment, only editing the code (in MainWindow :: MainWindow () ), but loading the living creatures will be implemented soon.
Evo is written in C ++ / Qt . The efficiency has been tested only under Linux , although the program should work on any platform supported by the Qt library.
To get a binary, just run:
git clone git@github.com:icoz/evo.git cd evo qmake make 


So, at the start a window appears with several buttons. We start and observe how the field is filled with colors.

')
I will explain what color has:

At the start, the genetic code of the living creatures is generated using the DSCH. So there is no magic. True, later magic appears ! Something arbitrarily generated begins to crawl, eat each other, and pasture too.
There are a few simple rules:

Logical partitioning is as follows.
The field (class Map) implements the functions of storing and moving objects, as well as the function of scattering a given amount of food.
The world (World class) describes the interaction of living creatures with the outside world.
Animals (instances of the class Animal) are automata, whose program is the “genetic” code (and I remind you that each individual has a memory and the ability to add and subtract in mind). In the process of executing this code, the body makes or other decisions. The world handles these requests (all this is implemented through a system of signals / slots).

In the case of acceptable behavior, animals are rewarded with an increase in the fitness parameter. For the absorption of grass fitness increases by 1 , for eating other animals - +10 , for reproduction - +50 . The higher the value of fitness , the more successful the body. In fact, this parameter describes the vitality of the organism. By the way, I am waiting for your proposals for the introduction of new rules in order to make life difficult for these lovely creatures and force them to invent something new.

Implemented all this mess so:

It should be noted that the work was done to optimize the program so that it does not absorb tons of resources. But in view of the specifics of her work - she loads percent. The slowest is frame rendering, so by default, only every 100th round is drawn.
When saving the living creature, not only the binary code is saved, but a text file with the extension * .code is created , in which the decoding of this code is given.

What else do you want to do


The wish list is:

What will be done soon


The list of upcoming changes is as follows:

At last


While I was starting to write this note, this program was spinning in my background (on the fourth hemp and there was no optimization of work speed). At that time, I reached for the living creature fitness = 3441 . For this, more than 210,000 individuals lived and died, and more than 6,500 rounds passed.
To get really interesting creatures that knew something interesting, you need (according to my estimates) at least 10 ^ 6 rounds. Maybe someone more powerful computer, twist? But it will be more interesting, of course, when genetic algorithms and a more intelligent generator of initial sets will be implemented. Well, with the addition of generated living creatures individuals written by living people. This will give a good start for future generations.
Having driven the program on core i5, I rather quickly got walking herds. Vitality has already reached 10390 units!
It is interesting to watch these cute little creatures. Even you begin to empathize with them.
Finally, here are some interesting "life" pictures. Visible migration routes of populations, the formation of herds.



The most serious result is 36480 (this is after 10 hours of work and 2 * 10 ^ 6 rounds):

Download, run, watch!
Who cares, you can try to write bots and see who is stronger!

That's all. Thanks for attention!

Bug reports and new feature suggestions are welcome.

UPD: the mutation is already implemented at a basic level.
UPD2: Bug Tracker
UPD3: dtf thanks for Windows binaries
UPD4: thanks to dtf for new binaries for windows

Source: https://habr.com/ru/post/156085/


All Articles