Wednesday, 31 December 2025

Cellular Automata and Digital Slime Mold - Stage 1

Physarum polycephalum - Scott Camazine Science Source

Cellular Automata (CA) is typically a table / grid based program, where each cell in the grid follows exactly the same set of programmed instructions. One of the most famous programs in this genre is called "Game of Life", which was written by late John Conway, with homage over, I am not going to talk about that program much as it is covered extremely well in the public domain.

So why am I writing about this slightly esoteric topic? Well, CA gives way to emergence. In this case, emergence is where something that you have not directly programmed happens through data and cell interaction. That, in my opinion, is really fascinating, as your program takes life on its own.

In normal day to day coding experience you typically come across two type of programming behaviours:
  • Type 1 - Explicitly programmed, if this, then that, literal rules. Programmed rules lead towards very predictable output.
  • Type 2 - Implicitly programmed, you did not say it literally, but this is how instructions flow. Indirectly programmed rules lead towards mostly predictable output, in imperative programming it is a complement of Type 1. 
However there is another one:
  • Type 3 - Initial data state interacts with other data through rules leading towards output in the form of emergence. Typically the initial author of the code or data would not be able to predict the program outputs, it is only by running it that you start to see output emerging, hence emergence. Think of Conway’s Game of Life producing Gliders, I bet that Conway did not have Gliders in mind when he made that program.

Conway's Game Of Life "Glider"
Wiki Image

> Above Type 1, 2 and 3 programming behaviours are not official, they have been stated here to help with understanding of emergence only. 

I have been thinking about emergence and complexity theory for about 3 years, here and there in the background of course. I was wondering about it in the context of slime mold in particular Physarum polycephalum type, I will refer to it simply as slime mold. This type of slime mold is a single cell organism and through emergence it gives way to "intelligent" behaviour. It is intriguing that slime mold natively finds "shortest path" between food sources. In Computer Science there are lots of shortest path algorithms (Type 1 and 2), however these cells are not programmed directly to achieve this, instead cells find shortest path through some internal emergent behaviour. Is it possible to try and find similar shortest path emergence by implementing some version of CA?

Slime mold spreads across the map to eventually settle on the optimal network. 
Wogan T. “Ride the Slime Mold Express” Science 21 January 2010.

Some basic observations:
  • Slime mold spreads across the surface trying to find food sources 
  • As it goes further from rich food origin it:
    • Consolidates its spread into the tube like structures
    • It creates tube like structures so that it can travel further
  • As it finishes exploring available food sources it consolidates leaving shortest paths only
I have decided to build a React web app, to see if I could build some kind of digital slime mold using CA. I have not used React framework before (I am sure my code will show it), I wanted to slightly refresh my HTML/CSS/JS skills and I wanted something very visual to observe so that I could run some "experiments".

Initial Rules

Each cell abides by the following (abridged):
  1. Start new epoch, in this epoch only already existing living cells will get a chance to take a turn
  2. Each cell at random will take a turn, during that cell's turn it will perform a single action only, actions in order:
    1. If a living cell has more resource than 1 and there is empty space around it, pick a random empty adjacent spot and create a new living cell
    2. If a living cell is adjacent to a food source that still has resource, eat from that food source
    3. If a living cell is adjacent to a cell that has more resource than you have, take some of the resource from that cell
  3. End epoch, go back to 1.
Please note that the above rules are not supposed to be "it", they are initial rules to start the thinking process and to kick off experiments. 


Experiment 1 - Clash

Black cells represent food, numbers in the cells provide information about the amount of food resource. In this experiment there are lots of resources on the grid, there are 5 cells with 90,000 food points each in top left and 4 cells with 90,000 food points bottom right. There is a single slime cell flashing green top left and there a single slime cell flashing bottom right. Here is what happens:

Above and all gifs end the moment map is fully covered. 


Experiment 2 - Repeater

There are two 90,000 food point cells in the middle of the grid without any slime mold. There are four 90,000 food point cells in the bottom right with a single slime mold next to it. Here is what happens:



Experiment 3 - Repeater Low Resource

There are two 200 food point cells in the middle of the grid without any slime mold. There are four 1,000 food point cells in the bottom right with a single slime mold next to it. Here is what happens:


Grid Explained 

The reason that you see colours is because I have added animation to each table cell, each cell flashes going from light green to green then to brown when it turns into slime mold cell. What happens in the aggregate is that you see a form of "wave motion". This wave shows you the direction of the slime mold, which ended up being very useful. 

Numbers in the slime mold cell show you the amount of resources that particular cell contains at that point in time. 

This digital slime mold is not supposed to replicate biology of the slime mold i.e. it is not supposed to be a digital twin. Rather, the biological version is used purely for inspiration. 

Initial Conclusion 

  1. While the initial food source is rich, digital slime mold travels in a wave covering the entire map before it hits the edge (Experiment 1 and 2). 
  2. If the initial food source is not rich and as a result originating slime mold runs out of food, slime mold goes from wave to "random" map covering, introducing entropy.
  3. Even if the food source is rich as per point 1, the moment slime mold hits the wall, wave travel stops and entropy is introduced as per point 2 (need to confirm this). 

What Needs Work

  1. I have tried to introduce a positive feedback loop by introducing a volume metric for each cell and by exponentially increasing volume in each cell. Thought was that this can create "tube" like structures, which would create natural consolidation of resources, however this has not worked well at the time, this needs to be revisited. 
  2. Ultimately digital slime mold needs to expand and contract (explore and exploit), expansion seems to work, however cellular contraction rules are less obvious and to be programmed in.  

Adjacent Thought 

Stephen Wolfram has written a book called "A New Kind Of Science" (I have not read this entire book, it is sitting here on my desk 1,197 pages full), in NKS Wolfram argues that our universe is CA and what we are seeing is emergence. If this is the case the actual program that is running a lot of what we see might be somewhat simple, but the emergence that it creates is complex. His experiments and arguments are very compelling and over the next decade or so I would like to explore this more.

Browse "Digital Slime Mold" Repository On Github. (Coming Soon)