← Back

Notes · artificial life and neuroevolution

NEAT0: Evolving Foraging Creatures

Small bilateral creatures forage for food in a 2D world. Each has a brain that evolves NEAT-style and can also learn during its lifetime. Nothing is hand-coded as a strategy: behaviour, brain wiring and body plan come from selection alone.

5 November 2026

1Overview

NEAT0 is a two-dimensional artificial-life simulation. A population of simple creatures forages for a renewable food resource. Two mechanisms shape behaviour:

Reproduction is asexual. NEAT's crossover, speciation and fitness-sharing machinery is not implemented, because it exists to make two-parent recombination safe and is not needed for clonal reproduction with mutation. There is no fitness function: a creature succeeds only by gaining enough energy to grow and divide.

The code has five parts:

See Table 4 for the files.

2Movies

These are screen recordings of the simulation window. The top line of each frame shows the tick, the number of creatures alive, and the population means of size, limb count and brain node count. Green shading is the food field: darker means more food. Creatures are drawn as ovals with stick legs, and the red dots are their two food sensors (antennae).

Figure 1

Forage evolution

Ticks 4131 to 4934, 66 s. Two or three surviving creatures forage on a sparse patch map, with a mean brain size of 7 nodes.

ForageEvolution.mp4 · 0.6 MB
Figure 2

Spinner, patroller, wanderer

Ticks 4857 to 5656, 59 s. Three creatures on the same map, each moving in a different way: the file name labels them spinner, patroller and wanderer.

SpinnerPatrollerWanderer.mp4 · 0.6 MB
Figure 3

Wigglers

Ticks 8784 to 8977, 27 s. A larger population (18 to 22 alive) on a map with many small patches, travelling as a tight group.

Wigglers.mp4 · 0.3 MB

Web versions of the screen recordings: H.264 MP4, 720 pixels wide, 30 frames per second. The full-resolution QuickTime originals are not on this site.

3World and body

Food field

The world is a toroidal grid of food density.

\[ \begin{equation} F_{t+1} = F_t + r\,(C - F_t), \tag{1}\label{eq:regrow} \end{equation} \]

with the rate \(r\) read every tick, so it can be changed while the simulation runs. Creatures sense food at continuous positions by bilinear interpolation, and eat from the nearest grid cell, up to a cap per tick.

Sensing and movement

The brain has five inputs:

There is no long-range sensing and no perception of other creatures. The two outputs set turning and speed:

\[ \begin{equation} \dot\theta = 2(\text{turn}-0.5)\,\theta_{\max}, \qquad v = \text{speed}\cdot v_{\text{limb}}\cdot n_{\text{limbs}}, \tag{2}\label{eq:move} \end{equation} \]

so a turn output of exactly 0.5 means straight ahead, and top speed grows with the evolved limb count.

Metabolism, growth and fission

Each tick a creature does the following:

  1. Eats.
  2. Pays a metabolic cost. The cost has five terms: a flat baseline, a term proportional to its current size, a term proportional to its limb count, a term proportional to its brain size (nodes plus enabled connections), and a movement term proportional to speed times size.
  3. Learns. The net energy change (intake minus cost) is the reward for its in-life learning.
  4. Dies if its energy reaches zero.

4The evolvable brain

The genome holds two kinds of genes:

Every creature starts minimal: 5 inputs, 2 outputs, no hidden nodes, and all 10 input-to-output connections (Figure 4). The turn and speed weights start small, uniform in \(\pm0.05\), so newborn ancestors move nearly straight instead of locking into tight circles.

i₀ i₁ i₂ i₃ i₄ o₀ o₁ left sensor food right sensor food energy (norm.) Δ left sensor Δ right sensor turn speed
Figure 4. The ancestral genome shared by every creature at the start: 5 inputs, 2 outputs, no hidden nodes, 10 connections, and plasticity \(p = 0\) on every connection. Biases are node values and are not drawn. All later structure comes from the mutation operators.

Forward pass

Mutation can create arbitrary depth and loops, so the network is evaluated by relaxation: every non-input node updates from its weighted input sum plus its bias, through a sigmoid, for brain_n_steps iterations. Hidden and output values persist from one tick to the next; only the inputs are overwritten. This matters because loops are common. In simulated lineages at the model's own mutation rates, 199 of 200 developed a real cycle within 500 generations, with a median of 42 generations.

Mutation operators

Seven operators act at each fission, each with its own probability:

The operators do not favour safe targets. Selection judges the outcome.

Learning within a lifetime

Each connection with \(p > 0\) keeps an eligibility trace \(e\) of recent pre- and post-synaptic co-activity:

\[ \begin{align} e &\leftarrow \lambda\,e + (a_{\text{pre}} - 0.5)(a_{\text{post}} - 0.5), \tag{3}\label{eq:trace} \\ \Delta w &= p\,R\,e - d\,(w - w_0), \tag{4}\label{eq:dw} \end{align} \]

where \(R\) is the tick's reward (net energy change), \(\lambda\) = trace_decay and \(d\) = plasticity_decay_rate. Each of the three ingredients fixes a failure that was observed:

The brain cost term (nodes plus enabled connections) is the only force against unbounded growth of the network.

5Parameters

Every tunable value lives in DEFAULT_PARAMS in world.py, and every one appears as a live slider in the GUI. None has been tuned to a target regime: the values are chosen to be plausible and to run.

ParameterDefaultRole
energy_ref10.0Scale that normalizes the energy input
eat_rate0.15Max food eaten from one cell per tick
base_cost0.02Flat cost per tick
size_coef0.01Cost per unit of current size
limb_coef0.005Cost per limb
brain_coef0.001Cost per node or enabled connection
move_cost_coef0.02Movement cost = this × speed × size
energy_capacity_coef25.0Energy cap = this × size
background_hazard0.0Random death probability per tick (off)
max_growth_rate0.001Heritable. Cap on energy per tick that growth can absorb
growth_cost_coef1.0Energy per unit of size gained
fission_cost0.0One-time energy cost at fission
mut_weight_rate / _scale0.3 / 0.4Weight mutation: probability per connection / std. dev.
mut_bias_rate / _scale0.3 / 0.4Bias mutation: probability per node / std. dev.
mut_plasticity_rate / _scale0.1 / 0.2Plasticity mutation: probability per connection / std. dev.
plasticity_decay_rate0.5\(d\) in Eq. \eqref{eq:dw}
trace_decay0.9\(\lambda\) in Eq. \eqref{eq:trace}
mut_add_conn_rate0.05Add-connection probability
mut_add_node_rate0.03Add-node probability
mut_prune_conn_rate0.05Prune-connection probability
mut_prune_node_rate0.03Prune-node probability
mut_body_scale0.15Std. dev. of max_size and limb_count mutation
mut_growth_rate_scale0.0005Std. dev. of max_growth_rate mutation
turn_init_scale / speed_init_scale0.05 / 0.05Ancestors only: range of the initial output weights and biases
max_turn_rate0.5\(\theta_{\max}\) in Eq. \eqref{eq:move}, rad per tick
speed_per_limb0.15\(v_{\text{limb}}\) in Eq. \eqref{eq:move}
sensor_angleπ/4Sensor offset from the heading
sensor_dist3.0Sensor distance ahead
brain_n_steps3Relaxation iterations per forward pass
max_population500Hard population cap
regrow_rate0.05\(r\) in Eq. \eqref{eq:regrow}
patch_density1/150Patches per unit area (set at Reset)
patch_radius2.0Radius of each food patch (set at Reset)
capacity_peak5.0Peak capacity at a patch centre (set at Reset)
Table 1. The parameters in DEFAULT_PARAMS, from the model summary. Rows below the heavier rule take effect only when the world is built or reset.

6Findings: two foraging strategies

One run produced two distinct evolved foraging strategies. Both survived a severe bottleneck, and both went on to fill the population together. Run settings:

Population on a log scale over 91,500 ticks
Figure 5. Population over the first 91,500 ticks (log scale).
  • By tick ~2,000 the 40 ancestors have collapsed to 2 survivors.
  • Two recovery attempts near ticks 25,000–27,000 fall back to one survivor.
  • A partial recovery starts near tick 48,000.
  • A lasting breakout starts near tick 70,000 and reaches the cap of 300 by about tick 85,000.
The population lived on a single creature for about 45,000 of the first 70,000 ticks.
Paths of the orbit and patrol strategies over the food capacity field, and x, y against time
Figure 6. Two evolved strategies, observed around ticks 3,400–4,800. Top: a tight, regular elliptical orbit on one rich patch. Bottom: a patrol circuit across most of the sandbox. Left: path over the food capacity field. Right: \(x\) and \(y\) against time.

Neither strategy displaced the other. At tick 91,500 the population was full (\(n = 300\)). Classified by which turn weights dominate:

Each strategy began with one mutation

While the simulation was running, a parent was seen producing one daughter that kept its strategy and one that did not. To find out why, every fission was instrumented to record the parent's and both daughters' turn weights at the moment of birth. Both strategies trace back to the same ancestor, creature 31 (Figure 7).

31 40 41 47 46 44 45 raw-dominated (ancestor) tick 1724 raw-dom. (unchanged) delta-dom. (mutated) tick 3705 tick 3418 orbit raw-dom. delta-dom. patrol
Figure 7. Genealogy of the two strategies of Figure 6. Bold circles mark the two plotted creatures.
left foodright foodenergyΔ leftΔ right
Parent 310.0279−0.02240.0347−0.0048−0.0099
Daughter 400.0279−0.02240.0347−0.0048−0.0099
Daughter 410.0279−0.02240.0347−0.3056−0.0099
Table 2. Turn weights at the tick-1724 fission. Daughter 41 differs from its parent on one connection only, which founds the patrol lineage.
left foodright foodenergyΔ leftΔ right
Parent 400.0279−0.02240.0347−0.0048−0.0099
Daughter 460.0236−0.8495−0.6202−0.0048−0.0099
Daughter 47 (orbit)−0.14620.05190.04570.0902−0.0099
Table 3. Turn weights at the tick-3705 fission, on the branch that did not mutate at tick 1724. Daughter 47's weights were unchanged from birth to tick 4,800.

Both strategies are therefore founding mutations, not learned behaviour.

No single mechanism here is new. What defines NEAT0 is the combination, and what it leaves out:

The closest ecological precedent is Yaeger's PolyWorld (1994): evolved Hebbian brains in a 2D world with shared food. It differs in having sexual reproduction, vision and predation. Other related work:

Running it

python3 creature_gui.py --n-orgs 1

This opens two windows:

Other flags: --width, --height, --max-population, --seed.

FileVersionRole
neat_brain.py1.6d0Genome, forward pass, seven mutation operators, eligibility-trace learning
environment.py—Patchy, regrowing food field; bilinear sensing and eating
creature.py1.8Body, sensing, metabolism, growth and fission; heritable antenna length with a breakage risk
world.py1.9Tick loop; DEFAULT_PARAMS, the single source of every parameter
draw_creature.py1.1Rendering: oval body, stick legs, red antenna dots
creature_gui.py1.14The two-window GUI
Table 4. Source files, in order of dependency, with versions from the README.