Skip to content

xsalonx/GameOfLifeAnimals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Game of Life: Animals

The world in this simulation is very simple. It consists of a regular, rectangular grid where the edges wrap around to the opposite side. Most of the world is covered by steppes with sparse plants that serve as food for animals. At the center lies a small jungle zone where plants grow much faster[web:1].

Game World Overview

  • The map is a toroidal (wrapping) rectangle.
  • The majority of the area is steppe; the jungle is located in the center.
  • Plants are more plentiful and grow faster in the jungle.

Plants appear at random locations, with a higher concentration in the jungle than the steppe. Each day, two new plants appear: one in each region.

Animal Anatomy

Each animal in the simulation has several key attributes:

  • Coordinates (x, y): Indicating its position on the map, relevant for both plants and animals.
  • Energy: Decreases each day. If an animal does not obtain enough food, it will starve and die. This represents how many days remain before the animal must find more food.
  • Orientation: The direction the animal is facing; there are eight possible directions. Animals move to an adjacent tile each day.
    • Rotation 0 = no change; 1 = 45° turn; 2 = 90° turn, etc.
    • For example, if initially facing north, applying rotation 1 means facing northeast.
  • Genes: Each animal has 32 genes, each an integer from 0 to 7, representing the animal's rotational preferences. Each day, an animal will (probabilistically, according to its genes) decide whether to continue in the same direction or change orientation. The probability for each rotation is proportional to the gene counts.
    • Example: Genes: 0 0 0 0 0 0 0 0 1 1 2 2 2 2 2 2 3 3 4 4 4 4 4 4 5 5 6 6 7 7 7 7
    • This example animal most prefers no rotation (p=0.25), with secondary preferences for right-turn (2), and backward (4) rotations (p=0.1875), and so on.

Eating & Reproduction

  • Eating: If an animal steps on a tile with a plant, it eats the plant and its energy increases by a defined value.
  • Reproduction: Only animals with enough energy can reproduce. Each parent loses one quarter of its energy to the offspring.
    • The newborn’s genome is a crossover of the parents’ genomes. The gene list is split into three segments at two random indexes (the splits are the same for both parents). The offspring receives two segments from one parent, one from the other. If any gene value (0–7) is missing in the result, it is randomly filled to ensure all rotations are represented.

Daily Simulation Cycle

Each simulation day consists of the following actions:

  1. Remove dead animals from the map.
  2. Each animal rotates and moves forward.
  3. Eating: A plant is consumed by the animal(s) with the highest energy on a tile. If multiple animals are tied, the plant’s energy is divided equally.
  4. Reproduction: The two animals with the most energy on a tile reproduce. If multiple candidates, two are chosen randomly.
  5. Two new plants are added — one for each biome.

Initially, one or more animals (e.g., "Adam" and/or "Eve") are placed in the center of the world.

Detailed Requirements

  • The program must display an animation showing animal positions, their energy (e.g., with color), and plant locations.
  • Animation display can use any method, including text, but simply printing consecutive lines of text as animation is not allowed (you can, however, overwrite text in-place using a suitable library).
  • The program must allow pausing and resuming the animation at any time (separately for each map, see below).
  • The program must track and allow viewing the following simulation statistics:
    • Total animals
    • Total plants
    • Dominant genotypes
    • Average energy of living animals
    • Average lifetime of deceased animals
    • Average number of offspring for living animals
  • When paused, users must be able to:
    • Select a single animal and view its genome.
    • Select an animal to track its history:
      • Total children after n epochs
      • Total descendants after n epochs
      • Epoch of death
    • Highlight all animals with the dominant genotype.
  • The program must allow displaying two simulations side-by-side with identical initial parameters but independent random decisions.
  • The program should allow exporting statistics (as above) after a set number of epochs as a text file. These statistics should be averages over the simulation epochs.

Frequently Asked Questions

Example Implementations

Note: The following implementations may not fulfill all requirements listed above.

Game of Life: Animals Example (YouTube)[web:1]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages