
I was lying last week in the hospital. And since discussing with the grandfathers in the lobby a recipe for apples, stewed in cabbage, and how good it was to walk around the floodplain meadows on Pokrov, there was no particular desire, I had to invent entertainment for myself.
I thought about the game
"Life" , which was recently recalled at Habré. I felt sorry for the unfortunate cells that live and die, depending on the initial conditions alone, and cannot do anything for their own survival. As a result, I came up with an extension for the rules of the game, with which you can simulate not only the change in population size, but also natural selection within it.
The most impatient can immediately
see what happened , and the rest I ask under the cat for the story.
')
Just in case, let me remind the rules of the classic "Life."There is a "universe", presented in the form of a square, divided into square fields. The field can be empty, or a cell can live on it. Each "day" of the game is calculated by a new generation of cells according to the following rules:
- on an empty field, next to which there are exactly 3 living cells, a new cell is emerging;
- if a living cell has 2 or 3 living neighbors, that cell continues to live;
- if the neighbors are less than 2 or more than 3, the cell dies (from “loneliness” or from “overcrowding”, respectively).
The “toroidal” universe: if you go beyond its right edge, you find yourself on the left, with the top and the bottom the same.
To give cells the opportunity to fight for life, I introduced additional rules.Before a new generation is calculated, each cell tries to find a more attractive position in its surrounding fields and moves into it. The attractiveness of the field depends on the number of neighbors and is determined by the genome of the cell in which it is recorded, how many neighbors she considers comfortable.
The genome is represented by an array of 9 genes, each of which can take the value 0 (the gene is silent) or 1 (the gene is active). The first (zero element) determines the attractiveness of a point with 0 neighbors, the second - from 1 neighbors, and so on to 8. If the gene is active, a field with an appropriate number of neighbors is considered a cell as attractive to move. If it is silent, the cell will not move to such a point.
For example, if a cell has a genome [0,1,1,0,0,0,0,0,0], it will try to move to a point that has 1 or 2 neighbors. And if not, it will remain in place. From points with the same attractiveness, a random one is chosen.
The genome is reflected in the color of the cells. The more red the cell, the more she likes loneliness. The bluer, the more likes the company. The more green, the closer it is to the "golden mean" - the preference of 2 or 3 neighbors.
When a new cell is born, it receives the same genome as that of the one of its 3 neighbors who went last (“who
last completed the combination, he and the dad”).
The order of the cells is random.
At the same time, the classic Conway's Game of Life is a limiting case when all cells have the genome [0,0,0,0,0,0,0,0,0].
After that I wrote the implementation of this whole idea in JavaScript:
http://widgetok.ru/life/For comparison, the calculation is carried out immediately for the two "universes." On the left - according to my rules, on the right - according to Conway’s classical rules. At startup, universes are filled randomly. You can adjust the size, the number of cells at the start and the number of genes that will be active in each cell.
If you click on a cell, below you can see its genome.
Immediately I warn you that I tested only in Google Chrome on a small screen netbook, lying on a hospital bed, so bugs are not only possible, but will be.
Here is an example of how a population of cells with 2 active genes usually develops.
First we have a variety of genomes. The “blue” cell becomes lighter (4 genes out of 8 are responsible for this), so the blue color prevails.

The first to die are “misanthropes” - red, then “friendly” blue, there are 3 groups, each of which has useful genes.
[0,0,1,1,0,0,0,0,0]
[0,0,0,1,0,0,0,1,0]
[1,0,0,1,0,0,0,0,0]

But lettuce has 2 useful genes, and the others have one, so they end up winning, filling the whole space.
In the Conway universe at this point, the population was very thin, and stable islands took shape.
What I expected to see, and what happened in reality.The cells that “grasped the rules of life” and aspire to occupy a position with 2 or 3 neighbors, obviously, should have had the advantage and multiplied more quickly than their counterparts, who were less fortunate with the genes. But in the end, due to overpopulation, there must have been a certain balance of numbers. I hoped that, as in the classic “Life”, stable geometric or genetic combinations would be distinguished, and it might be possible to observe the symbiosis of cells with different genes.
The reality was easier.
The population either grows to the limit and stops at some quasistable number, or dies. First of all, it depends on the number of cells at the start (too few die from loneliness, too many from overpopulation) and on the number of active genes, which is lower.
When a population dies, small stable figures can remain, as in classical Life. But only the most simple and, as a rule, with the same genome: the squares of their 4 neighboring cells, "flashers". Once I saw a figure from cells of different genomes, but also static and small. I think this leads to an element of chance in choosing the direction and sequence of moving cells.
The more genes are activated, the more “garbage” in the genome, forcing the cell to make wrong decisions about the direction of movement.
Name 4 active gene, you can get 2 fairly long coexisting populations
[0,0,1,1,0,0,0,1,1]
[1,0,1,1,0,0,0,1,0]

8 active genes - the population is balancing on the verge of degeneration.

9 active genes - alas, too many. The population is dying.
That turned out such a model. You can also
play : maybe you will have some more interesting conclusions.
What else could be done.At first I thought to include all genes, and make their value a number from 0 to 9, defining the “size” of the attractiveness of the field. But at the same time, the selection results are not so visual, it is difficult to determine why a particular genome won.
You can also make the cells mutate, changing their genome or crossing at the origin. But, it seems to me, with the current rules, the “green” ones will still win. Is that to make the rules change with time, as in real life ...;)