Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Genome Actions Reference

Note

This file was generated using Claude

Detailed breakdown of all genome-driven actions in the CLANS3 simulation, extracted from the Processing source code (Cells.pde, constant.pde).


Overview

Only APEX (Sprout) cells execute genome commands. The genome system has three execution paths depending on cell state:

  1. Growth — when no conditions are defined in the active gene
  2. Body commands — when the APEX has a parent (is part of a multicellular organism)
  3. Lone commands — when the APEX has no parent (is a free-roaming single cell)

Execution Flow (per tick)

APEX evaluates active gene:
  ├─ Check condition 1 (bytes 3-4)
  ├─ Check condition 2 (bytes 5-6)
  │
  ├─ Both conditions unused (gene value > 67)?
  │   └─ GROW using bytes 0-2 → APEX becomes WOOD
  │
  ├─ At least one condition met (none return -1)?
  │   ├─ Has parent? → execute body command (byte 9)
  │   │   └─ success → gene byte 10, failure → gene byte 11
  │   ├─ No parent? → execute lone command (byte 15)
  │   │   └─ success → gene byte 16, failure → gene byte 17
  │   └─ No valid command? → jump to gene byte 7
  │
  └─ At least one condition NOT met?
      ├─ Has parent? → execute body command (byte 12)
      │   └─ success → gene byte 13, failure → gene byte 14
      ├─ No parent? → execute lone command (byte 18)
      │   └─ success → gene byte 19, failure → gene byte 20
      └─ No valid command? → jump to gene byte 8

Growth (No Conditions Active)

Who: APEX cells (both body and lone) When: Both condition slots in the active gene have values > 67 (maxIF) Effect: The APEX creates up to 3 new cells (left/forward/right) based on bytes 0-2, then transforms into WOOD.

Growth Byte Encoding (each of bytes 0, 1, 2)

Value RangeCell CreatedNotes
0-63APEXActive gene = value % 32
64-75LEAF
76-85ANTN
86-95ROOT
96-255NothingNo growth in this direction

Growth Requirements

  • Energy cost: (WORK + ORGANIC_CELL) = 20 energy per new cell
  • Total energy must be >= cell_count * 20 or growth is skipped entirely
  • Target position must be empty (cellsIndx == 0), otherwise that branch is silently skipped
  • The growing APEX becomes WOOD after growth
  • If no branches can be created and cell is alone, active gene resets to 0

Growth Side Effects

  • New APEX children: parent WOOD sets energyTo[] flag toward them (will send energy)
  • New LEAF/ROOT/ANTN children: child sets energyTo[] flag toward parent (will send energy back)
  • Mutation: ~1% chance per new APEX child — copies genome, changes 1 random byte

Body Commands (APEX with parent, gene value 0-14)

These commands are available when the APEX is part of a multicellular organism (has a parent).

CmdNameDescriptionReturnsDetails
0SkipDo nothingtrueNo-op
1Fly SeedTransform into flying seedtrueSets type=SEED, calls destroyAllLinks(), move=true, restTime=8
2Stationary SeedTransform into stationary seedtrueSets type=SEED, move=false, restTime=8
3Delayed Fly SeedTransform into seed that flies latertrueSets type=SEED, move=true, restTime=8. Note: does NOT call destroyAllLinks() — stays attached until detach threshold
4DieVoluntary deathtrueSets energyTo[parent]=1 before dying (tries to send energy to parent), then calls die()
5DetachBreak away from parenttrueCalls destroyAllLinks() — severs all parent/child/energy connections
6Push Energy LeftMove soil energy to lefttrueTransfers all EnergyMap at cell position to the cell one step left (relative to facing)
7Push Energy RightMove soil energy to righttrueSame as above, rightward
8Push Energy AheadMove soil energy forwardtrueSame as above, forward
9Push Organic LeftMove soil organic to lefttrueTransfers all OrganicMap at cell position to cell one step left
10Push Organic RightMove soil organic to righttrueSame, rightward
11Push Organic AheadMove soil organic forwardtrueSame, forward
12FireLaunch bullet projectiletrue/falseCreates a SEED with 30 energy, restTime=30 ticks, move=true. Costs ORGANIC_CELL+WORK+30 = 50 energy. Fails if insufficient energy or target is wall
13SeedCreate reproductive seedtrue/falseCreates SEED with most of parent’s energy, restTime=5+random(40), move=true. Parent keeps 30 energy. Costs ORGANIC_CELL+WORK+30 = 50 minimum
14Scatter OrganicConvert energy to soil organictrueDistributes floor((energy-3)/9) organic to each of 9 surrounding cells. Cell retains 3 energy. Skipped if energy < 12

Fire/Seed Collision Behavior (setNewSEED)

When the target position (one step ahead) is occupied:

  • If occupied by same genome → adds (ORGANIC_CELL+WORK+30) energy to that cell
  • If occupied by different genome → marks that cell for death
  • Either way, costs the creating cell (ORGANIC_CELL+WORK+30) energy
  • If target is a wall (cellsIndx < 0) → fails, returns false

Lone Commands (APEX without parent, gene value 0-17)

These commands are available when the APEX is a free-roaming single cell (no parent).

CmdNameDescriptionReturnsDetails
0Move ForwardStep one cell aheadtrue/falseCosts 1 energy (moveApexPrice). Fails if target occupied (any cell or wall)
1Turn RightRotate 90° clockwisetruedirection += 1 (mod 4)
2Turn LeftRotate 90° counter-clockwisetruedirection -= 1 (mod 4)
3Turn AroundRotate 180°truedirection += 2 (mod 4)
4Turn Right + MoveRotate 90° CW then steptrue/falseTurn always succeeds, move may fail
5Turn Left + MoveRotate 90° CCW then steptrue/falseSame
6Turn Around + MoveRotate 180° then steptrue/falseSame
7ParasiteAttach to adjacent WOOD celltrue/falseChecks cell ahead: if it’s WOOD, sets self.parent to that direction and registers on the WOOD’s energyTo/children arrays. Fails if no WOOD ahead
8Random TurnTurn randomlytrue30% right, 30% left, 40% no turn
9Random Turn + MoveRandom turn then steptrue/falseSame random turn logic, then moveApex()
10Drag Organic from LeftPull organic under selftrue/falseMoves all OrganicMap from left cell to current position. Returns false if source had 0 organic
11Drag Organic from AheadPull organic under selftrue/falseSame, from ahead
12Drag Organic from RightPull organic under selftrue/falseSame, from right
13Drag Energy from LeftPull energy under selftrue/falseMoves all EnergyMap from left cell to current position. Returns false if source had 0 energy
14Drag Energy from AheadPull energy under selftrue/falseSame, from ahead
15Drag Energy from RightPull energy under selftrue/falseSame, from right
16Eat NeighborsKill and absorb adjacent cellstrue/falseCosts 1 energy. Checks all 8 directions (cardinal + diagonal). Kills all cells with type < WOOD (i.e., APEX, LEAF, ANTN, ROOT). Absorbs their energy + engP + engM + org. Returns false if nothing eaten
17Absorb Soil EnergyExtract energy from groundtrue/falseTakes up to ALONE_CAN=6 energy from EnergyMap at current position. Returns false if soil had less than 6 energy (still takes what’s there)

Conditions (68 total, IDs 0-67)

Conditions are checked before commands execute. Each gene has two condition slots (bytes 3-4 and 5-6). A condition slot is “unused” if the gene value > 67 (maxIF).

Return Values

  • 1 — condition met
  • -1 — condition not met
  • 0 — condition slot unused (gene value > maxIF)

Condition Table

IDConditionParameter Usage
Resource at Position
0Organic at cell < thresholdparam * 2
1Organic at cell >= thresholdparam * 2 (NOTE: source code is identical to 0 — likely a bug, SIMULATION.md says >=)
2Cell energy > thresholdparam * 2
3Cell energy < thresholdparam * 2
Level-Based
4param % (level+1) == 0param value directly
5level % (param+1) == 0param value directly
6level > paramparam value directly
7level < paramparam value directly
Energy Trends
8Energy rising (current >= previous)
9Energy falling (current < previous)
Area Resources (9 cells around position)
10Organic(9) > thresholdparam * 18
11Organic(9) < thresholdparam * 18
12Energy(9) > thresholdparam * 18
13Energy(9) < thresholdparam * 18
14Energy(9) > Organic(9)
15Energy(9) < Organic(9)
Spatial Awareness
16Edible cells nearbyChecks 5 directions (left, front-left, front, front-right, right). “Edible” = type < WOOD (APEX, LEAF, ANTN, ROOT)
17Area free (left + center + right)All three relative directions must be empty
18Free left
19Free center (ahead)
20Free right
21Obstacle left
22Obstacle center (ahead)
23Obstacle right
24Has parent
25Randomtrue if random(256) > param
Light Comparisons (organic at 3 cells distance, excluding poisoned)
26Light center > light right
27Light right > light center
28Light center > light left
29Light left > light center
30Light left > light right
31Light right > light left
Energy(9) Directional Comparisons
32Energy(9) center > right
33Energy(9) right > center
34Energy(9) center > left
35Energy(9) left > center
36Energy(9) left > right
37Energy(9) right > left
38Energy(9) right > thresholdparam * 18
39Energy(9) center > thresholdparam * 18
40Energy(9) left > thresholdparam * 18
Organic(9) Directional Comparisons
41Organic(9) center > right
42Organic(9) right > center
43Organic(9) center > left
44Organic(9) left > center
45Organic(9) left > right
46Organic(9) right > left
47Organic(9) center > thresholdparam * 18
48Organic(9) right > thresholdparam * 18
49Organic(9) left > thresholdparam * 18
Free Space(9) Directional Comparisons
50Free(9) center > right
51Free(9) right > center
52Free(9) center > left
53Free(9) left > center
54Free(9) left > right
55Free(9) right > left
56Free(9) center > thresholdparam % 10
57Free(9) right > thresholdparam % 10
58Free(9) left > thresholdparam % 10
Poison Detection
59Organic poison aheadOrganicMap >= 512 one step ahead
60Organic poison leftOrganicMap >= 512 one step left
61Organic poison rightOrganicMap >= 512 one step right
62Energy poison aheadEnergyMap >= 512 one step ahead
63Energy poison leftEnergyMap >= 512 one step left
64Energy poison rightEnergyMap >= 512 one step right
65Any poison aheadEither map >= 512 one step ahead
66Any poison leftEither map >= 512 one step left
67Any poison rightEither map >= 512 one step right

Non-Genome Cell Behaviors (Automatic, Every Tick)

These are not genome-driven — they happen automatically based on cell type.

SEED

  • Costs 0.5 energy/tick
  • Dies if energy < 0
  • If energy > 512 while attached → detaches (destroyAllLinks())
  • If detached and restTime > 0: counts down, moves 1 cell/tick if move=true
    • Collision: kills the hit cell, seed stops moving (move=false, returns false → seed dies)
    • Movement costs 1 energy/step
  • When restTime reaches 0: transforms into APEX at gene 0, level=0, age=AGE

WOOD (Transport)

  • Costs 0.04 energy/tick
  • If energy > 0: transmits energy to all cells marked in energyTo[], split evenly
  • If energy <= 0: loses 1 age tick (starts at AGE=3)
  • Dies when age reaches 0
  • If detached (no parent) and has no children → dies immediately

LEAF (Green)

  • Photosynthesis: OrganicMap[x][y] * free_neighbor_count * 0.0008
    • free_neighbor_count starts at LIGHTENERGY=10
    • Each occupied neighbor (8 checked): -1 from count
    • If ANY adjacent cell is LEAF: returns 0 (mutual shading — complete shutdown)
  • Costs 0.04 energy/tick
  • Transmits surplus energy toward parent
  • Dies when age reaches 0 OR if parent == -1 (detached)

ROOT (Red)

  • Extracts up to ROOT_CAN=1 organic/tick from OrganicMap at position
  • Immune to organic poisoning (can survive OrganicMap >= 512)
  • Costs 0.04 energy/tick
  • Transmits surplus energy toward parent
  • Dies when age reaches 0 OR if detached

ANTN (Blue)

  • Extracts up to ANTN_CAN=1 energy/tick from EnergyMap at position
  • Immune to energy poisoning (can survive EnergyMap >= 512)
  • Costs 0.04 energy/tick
  • Transmits surplus energy toward parent
  • Dies when age reaches 0 OR if detached

APEX (Sprout)

  • Costs 1 energy/tick
  • Dies if energy + engP + engM < 0
  • If energy > 1024 while attached → detaches and resets to gene 0
  • If detached → level resets to 0

Energy Transfer System

  • Uses double-buffer (engP/engM) with alternating phase (EnergyTransportPeriod flips between +1/-1 each tick)
  • Cells receive buffered energy at start of tick
  • transmitEnergy(): splits cell’s energy evenly among all flagged energyTo[] directions
  • If nowhere to send and has parent: redirects to parent, also tells parent to stop sending energy back
  • If nowhere to send and no parent: dumps energy into EnergyMap, loses 1 age tick

Key Constants

ConstantValueUsed By
ROOT_CAN1ROOT extraction rate
ANTN_CAN1ANTN extraction rate
ALONE_CAN6Lone APEX soil energy absorption
ORGANIC_EXCESS512Poison threshold (organic)
ENERGY_EXCESS512Poison threshold (energy)
AGE3Base lifespan ticks (when no energy)
Energy4Life0.04LEAF/ROOT/ANTN/WOOD living cost
SeedEnergy4Life0.5SEED living cost
ApexEnergy4Life1APEX living cost
moveApexPrice1APEX movement cost
LIGHTENERGY10Base free-neighbor count for photosynthesis
LIGHTCOEF0.0008Photosynthesis coefficient
ORGANIC_CELL15Organic deposited into soil on death; organic cost per new cell
WORK5Energy cost of creating a cell
MAX_APEX_ENERGY1024APEX detach threshold
MAX_SEED_ENERGY512SEED detach threshold

Source Code Notes

  • Bug in condition 1: The code for conditions 0 and 1 is identical (< param*2). SIMULATION.md describes condition 1 as >=, so this appears to be a copy-paste bug in the original Processing source.
  • “Light” conditions (26-31): “Light” actually measures organic matter at 3 cells distance in the given direction, excluding poisoned cells (organic >= 512 counts as 0). This is because photosynthesis depends on soil organic.
  • Directional (9) scans (32-58): These sample a 3x3 grid offset 2 cells in the given direction, not the 3x3 around the cell itself.
  • Eat (lone cmd 16): Checks all 8 neighbors (4 cardinal + 4 diagonal via 0.5-step increments). Only eats types < WOOD (APEX=0, LEAF=1, ANTN=2, ROOT=3). WOOD and SEED are spared.
  • Command 3 vs Command 1: Both set move=true and restTime=8, but only command 1 calls destroyAllLinks(). Command 3 stays attached, meaning it won’t actually fly until either energy exceeds MAX_SEED_ENERGY (512) causing auto-detach, or it dies.