Neural Ants (NAnts)

Authors

Iliya Zhechev · ERA

NAnts are to Langton's ant what NCAs are to cellular automata: the rule is learned rather than written by hand.

Presented at the ERA Journal Club🛝 Slides🎥 RecordingNAnts Lab interactive sandbox

The field

step 0 ants 0

Controls

pointer
what to stamp

Erase part of the drawing and the colony repairs it. Pick a creature and stamp another one anywhere; they all share the one field, and each colony is drawn in its own colour.

Inside every cell

3 channels are the picture · 13 are the hidden grid state

    What one ant does, every step

    1. Look

      The ant applies the same fixed filters an NCA does to its 3×3 patch: identity, and a pair of sobel gradients. The gradients are rotated into the direction it faces, so its senses turn with it.

    2. Add its own position

      It also knows how far it has walked from the cell it started on. It has no other sense of where it is.

    3. Run the network

      Those 93 numbers go through one small network of 14,483 weights, which returns 19 numbers.

    4. Write and turn

      16 of them are added to the cell underneath. The other 3 pick a turn — left, straight, or right — and the ant steps forward.

    Repeat six thousand times and a gecko is on the grid.

    Worth knowing

    Repair was never trained
    The colony was only ever shown a blank grid. Nobody taught it to fix damage, yet erase part of the drawing and it fills the gap back in.
    No memory
    An ant keeps a position and a heading between steps, and nothing else. Every decision starts over.
    No talking
    Ants never signal one another. They share a grid, and that is the only thing that connects them.
    One network, any number of ants
    The same 14,483 weights run every ant. One ant draws the gecko slowly; nine draw it quickly.
    Everything is relative
    What an ant senses is measured from the way it faces, so turning it at the start turns the whole drawing.
    Two kinds of learning
    Backprop teaches it what to write. A turn is a discrete choice, so no gradient passes through it; those are learned with REINFORCE, the policy gradient method from reinforcement learning.

    Train your own

    Pick any emoji and grow that instead. A run takes a couple of hours on a gpu, and you can watch the picture improve while it goes.

    It writes a folder under out/ holding the drawing as it stands, the error curve, and the best network so far. Stop it whenever you like — the best one is already saved.

    Code and full write-up on GitHub →

    Starter code for the EmergANT hackathon at ALIFE 2026.

    # install
    git clone https://github.com/ichko/nants
    cd nants && uv sync
    
    # change the emoji at the top, then run it
    uv run python starter/my_nants.py
    
    # render what it learned
    uv run nants-crowd out/<datetime>

    Cite this

    @misc{zhechev2026nants,
      author       = {Zhechev, Iliya},
      title        = {Neural Ants: a learned Langton's ant},
      year         = {2026},
      howpublished = {https://github.com/ichko/nants},
    }