Kindlewild

Client payload sizes

By Rosedo Devs · 6 months ago

Tranferring state from backend to client has been very greedy so far, passing payloads of over 1MB per evolutionary update, ~60 frames per second. Fine for development, but slow and costly to put into production, where egress costs accumulate and data has to travel over the wire across long physical distances to each client.

Typically you want a single payload to be no more than 1kb, and ideally less than 10kb per second.

A simulation of evolutions

By Robin Dowling · 6 months ago

I'm building an evolution simulation where observers can watch as species evolve, thrive, and establish themselves in different regions of their world, only to eventually be displaced by other emerging species.

Species

The simulation models the process of evolution through emergent behavior and randomness. There are no predefined organisms, species, or events. Instead, all life forms are generated based on randomly assigned genetics, and evolution unfolds through the cumulative effects of interaction and adaptation.

Organisms in the simulation are not categorized as plants or animals. Their genetics determine their role: some remain stationary, effectively resembling plants, while others move and interact with others, resembling animals. Regardless of their behavior, all organisms share the same core objectives: to survive and reproduce.

Species are not static or predefined but form dynamically. Organisms with similar genetics are grouped into species through a process that reduces and transforms genetic data into clusters. Over time, mutations and genetic drift ensure that species composition evolves continually.

Energy

Energy is central to survival. Organisms lose energy over time and must replenish it by consuming other organisms or environmental elements. Organisms reproduce with suitable mates, and after pregnancy completes, the genetic material of the two mating organisms are combined into an average of both, with mutations introducing variation in their offspring. The success of reproduction depends on both environmental conditions and the ability of organisms to survive long enough to reproduce.

Conflict

Conflict naturally arises as organisms compete for limited resources, access to suitable habitats, and opportunities to reproduce. These conflicts may result in threats, or direct confrontations, sometimes leading to the death of one or more organisms.

Diseases

Diseases add an additional layer of complexity. Like organisms, diseases have genetic profiles and spread based on compatibility with host genetics. Transmission occurs through proximity or specific interactions, and the severity of their effects depends on the genetic match between the disease and the host as well as the character of the specific disease.

Knowledge

Organisms are capable of learning from their experiences. They learn whether a particular energy source, location, or interaction was beneficial or harmful, and they adapt their behavior accordingly. This knowledge can be shared with others, enabling the spread of adaptive strategies within populations.

Simple and complex

The simulation is built around a few core elements: Energy, Organisms, Elements, Conditions, and Diseases. These components interact in a complex system, where survival and evolution emerge from the interplay of randomness, competition, and adaptation.

Observers will see different species moving about, sometimes scattered and sometimes in groups. When all life is extinguished, a new evolution begins, with yet another set of randomly created organisms and species.

The energy cycle

By Kindlewild · 7 months ago

In the simulation, energy is never created or destroyed, but constantly changes form and location as it moves through the ecosystem. The way organisms interact with their environment and each other is fundamentally shaped by this cycle.

Sessile and motile feeding

Sessile organisms—those that remain fixed in place—draw their energy from elements in the soil. These elements are distributed throughout the world and act as the primary food source for sessile life. Motile organisms, on the other hand, are more opportunistic. They feed on other organisms, including both sessile and other motile types. This predation and consumption is the main way energy moves up the food chain.

Death and recycling

When any organism dies, its internal composition is not simply lost. Instead, a portion of its elemental makeup is returned to the environment. These elements are released back into the soil, becoming available once again for sessile organisms to absorb. This recycling is not total—only a fraction of the organism’s elements are returned, which means energy is always in flux, but never static.

The cycle

This system creates a closed loop: elements in the soil feed sessile organisms, which in turn become food for motile organisms. When motile organisms die, their elements are recycled back into the soil. The same is true for sessile organisms. Over time, energy and matter circulate endlessly through the world, passing from soil to plant to animal and back again.

Code and configuration

The rates at which energy is consumed, transferred, and recycled are all configurable. The amount of energy sessile and motile organisms consume, and the rate at which elements regenerate in the environment, are also controlled by parameters. This design ensures that the world never runs out of energy entirely, but also that energy is never so abundant that populations can grow without limit. The balance between consumption and recycling is what allows the simulation to sustain itself over many generations, with populations rising and falling as energy flows through the system.

At least that is the goal. Balance is very tricky.

Everything depends on everything

By Robin Dowling · 8 months ago

Complexity in setting the weight variables for everything affects the evolution massively. All weights influence each other, and changing one value ever so slightly can have enormous effects. Sometimes you need to weigh two or more values against each other, since they can have clashing effects.

Currently, with about 15–20 values, and each value able to vary independently across a wide range, the number of possible combinations is incredibly large — effectively limitless. The space of evolutionary paths grows exponentially with each added value. Add to that all the genetic compositions, each individually affected by the weights.

One problem with this is finding an equilibrium — a stable environment where life can be sustained continuously, but not overflow. It needs to be resilient to big changes, but also fluent enough to follow them into unexpected new evolutionary directions. Like, whoever thought that dinosaurs wouldn't be a thing after the Cretaceous period?

It's fun to see the environment adapt — and often collapse, unfortunately. I'm still tweaking those weights.

Movement logic

By Kindlewild · 8 months ago

Movement in the evolution simulation is governed by a priority-based decision system that balances multiple competing needs. Each organism evaluates its current individual situation and chooses movement based on what it needs most urgently.

Since every individual organism s different, but exists in the same context, their movement naturally forms into loosely governed groups, creating an emergent herd movement, similar to bird murmurings.

Fear

Organisms act on fear of threats, violence, and being away from others of their own species. This happens when they're outnumbered by other species or when they encounter potential predators. Fear influences movement decisions, ensuring survival takes precedence.

Fear-based movement creates natural herding behaviors where organisms of the same species cluster together for protection. Threatened organisms move toward known safe locations where their species congregates, creating defensive formations and territorial boundaries. Organisms prefer to venture out away from a larger group if someone else is with them.

Survival

When organisms are in danger, they flee toward safety, often seeking out others of their own kind for protection. This creates natural herding behaviors where similar organisms cluster together. The fleeing behavior overrides all other movement decisions, ensuring survival takes precedence.

Energy seeking

Organisms become strategic foragers when they need energy. They remember where they've found food before and return to those locations. If they're at a known food source, they stay put. If not, they move toward remembered feeding grounds. Only when they have no memory of good locations do they explore randomly.

Social

Reproduction creates complex movement patterns. When ready to reproduce, organisms first look for compatible partners nearby. If none are available locally, they travel to areas where their species congregates, creating natural mating grounds.

Organisms also prefer to rest among their own kind. If they find themselves surrounded by different species, they'll move toward areas where their species is more common. This creates natural territorial boundaries and species segregation.

Knowledge

Organisms have memory - they remember where they've found food, where they've encountered others of their species, and where they've been safe. This knowledge guides their movement decisions, creating efficient foraging patterns and social networks.

Energy constraints

Every movement has consequences. Moving requires energy, so organisms must balance the benefits of reaching a goal against the cost of getting there. This creates realistic patterns where organisms don't move constantly but instead make strategic decisions about when and where to go.

The energy cost of movement also creates natural selection pressure. Organisms that move efficiently have an advantage over those that waste energy on unnecessary movement. This drives the evolution of more sophisticated movement strategies over time.

Emergent behaviors

From these simple movement rules emerge complex, lifelike behaviors. Organisms naturally form territories, establish migration routes, and create social networks. They develop foraging strategies that balance exploration with exploitation. They exhibit predator-prey dynamics where some organisms flee while others pursue.

The movement system creates a dynamic, ever-changing world where the distribution of organisms constantly shifts in response to changing conditions. Food sources become depleted and new ones are discovered. Populations grow and disperse. Species compete for space and resources.

This emergent complexity makes the simulation fascinating to watch. Simple rules about where to move create rich, realistic behaviors that mirror what we see in natural ecosystems.

Movement

By Rosedo Devs · 8 months ago

I made the organisms move around randomly as well as staying close to their own species, looking for opportunities to reproduce and to find sources of energy to stay alive.

After giving organisms an understanding of their surroundings outside of their exact location, I allowed them to use this understanding in picking a direction to move to next.

Because the preferred directions were looked up in a x and y axis manner, starting top left, organisms turned out to have an affinity to move northwest, since that direction was technically evaluated first in the grid.

Once a supposed direction was found, no more directions were evaluated, as a way to not waste precious processing time.

The way to solve the north west drift was simply to shuffle the set of of directions first before evaluating them.

Since I am iterating over each organism over and over, all precise and evaluations must be as fast as possible. I implemented the Fisher-Yates shuffle to shuffle positions for directions, as it appears to have slightly better performance over the built in shuffle. If anyone has a more performant shuffle, let me know.

What is life?

By Robin Dowling · 10 months ago

So how are the organisms going to live their life? Live any life at all? What even is life? And how can any sort of representation of life be simulated?

Questions I asked myself.

Goals

In life, all organisms have goals. Without these goals we would all die and leave nothing. No next generation. A flash-in-the-pan organism, long forgotten in the history of... life.

The organisms needed some basic goals to promote an evolution to even take place.

In evolution, the single goal of any organism can be reduced to: produce offspring that eventually also produces offspring.

Everything else is fluff from an evolutionary perspective.

Keep in mind that evolution itself is not even something organized by nature, or an intrinsic attribute of the world. It just happens to be the natural progression of events, given certain criteria. Such as organisms being able to produce offspring that eventually also produces offspring.

I gave the organisms two basic goals

  • Stay alive
  • Reproduce

In addition to these goals, I gave them behavioral goals that promoted the two basic goals. You can't just run around in circles in your own corner if you want to eat and/or reproduce, right?

Basic elements

By Robin Dowling · 10 months ago

I have also added basic elements, eg oxygen, sulphur, carbon, chlorine, iron etc, as elements in the world.

These elements were then added randomly to each organism, as a chemical composition, which together with the other genetic attributes make the organisms' definitions even more complex and varied.

Each element has an assigned amount of energy, based on which element it is. The sum of all element energies is used to calculate the organism's energy.

They're all organisms

By Robin Dowling · 10 months ago

I didn't want to have separate definitions for plants and animals. Or for there to even be a notion of that. I wanted the evolution to come up with that on its own, if that was what were to be randomly evolved over time.

Instead I added an attribute for whether the organism was motile or not. Motile, as in able to move around on purpose. What really is the difference from a Venus flytrap and a "walking stick" Phasmid? In terms of genetics.

A lot, I'm sure. But in the end, there is no natural genetic flag for plant or animal. These are just interpretations made by us humans.

Either way, I made all organisms be the same, but with different genetics, the motile genetic marker carrying heavily in the taxonomy classification, effectively dividing motile (animals) and sessile (plants) organisms into two different taxonomy domains.

Genetics in code

By Robin Dowling · 10 months ago

So, how do you assign genetics to an organism in code? That's what I asked myself at first.

I created an Organism class, and added a few attributes that I believed the organisms in my world ought to have. Things that define them and propagate naturally to offspring.

Fuzzy values for max possible age, values for how likely the organism is to want to reproduce, given the right circumstances, the maximum number of offspring, its max theoretical mass and density.

Stuff like that.