Python implementation of cellular autonoma for GollyX.
Provides a collection of Python classes for simulating various two-dimensional cellular automata, with a focus on Conway's Game of Life and its multi-team variants. It features several distinct simulation engines, each with different data structures, performance characteristics, and support for different grid topologies and rulesets.
The library is structured around two main types of classes: Manager Classes and Life Simulator Classes.
The manager classes are the primary user-facing components. They act as wrappers that simplify the process of configuring and running a simulation. Users instantiate a manager class, providing parameters such as grid dimensions, rules, and initial conditions for each team. The manager then creates and controls the appropriate underlying life simulator instance.
The main responsibilities of a manager class are:
- Loading and parsing configuration (e.g., initial patterns from JSON).
- Instantiating the correct life simulator class.
- Providing a simple interface to the simulation, typically with methods like
next_step()to advance the simulation by one generation andcount()to retrieve statistics.
The primary manager classes are:
ToroidalGOL: Manages a standard two-team Game of Life on a periodic (toroidal) grid.HellmouthGOL: Manages a two-team Game of Life using a high-performance, linked-list-based engine.KleinGOL: Manages a two-team Game of Life on a Klein bottle topology.StarGOLGenerations: Manages a complex, multi-state cellular automaton with "Generations" rules, where dead cells must "rest" for a number of turns before they can be reborn.RainbowGOL: Manages a four-team variant of the Game of Life.
These classes contain the core logic for the cellular automata. They manage the state of the grid and implement the algorithms for evolving it from one generation to the next. There are several distinct implementations, each with different characteristics.
- Purpose: A two-team (binary) Game of Life simulator on a toroidal grid (periodic boundary conditions).
- Data Structure: Represents the grid as a sorted list of rows, where each row is a list containing the
y-coordinate followed by all the x-coordinates of live cells (e.g.,
[y, x1, x2, x3, ...]). This is simple but can be inefficient for very sparse patterns. - Interaction: Instantiated and controlled by the
ToroidalGOLmanager. The manager forwards calls to itsnext_generation()andget_live_counts()methods.
- Purpose: A highly optimized two-team Game of Life simulator.
- Data Structure: Uses a sophisticated data structure composed of custom linked lists (
LifeList,SortedRowList). This avoids the overhead of Python lists and is designed for high performance, especially with sparse cell patterns. - Interaction: Instantiated and controlled by the
HellmouthGOLmanager. This class is more self-contained thanToroidalBinaryLife; it has its ownLifeStatsinner class that manages statistics and calculates victory conditions based on a moving average of population dynamics. The manager primarily interacts with thenext_step()andget_stats()methods.
- Purpose: Simulates a two-team Game of Life on a Klein bottle.
- Data Structure: Uses the same list-of-lists structure as
ToroidalBinaryLife. - Key Difference: Its uniqueness lies in the handling of boundary conditions. When a pattern wraps around the
top/bottom edges, its x-coordinates are inverted (
columns - x - 1), creating the characteristic twist of a Klein bottle. - Interaction: Instantiated and controlled by the
KleinGOLmanager.
- Purpose: Simulates a more complex cellular automaton based on the "Generations" ruleset, which is distinct from Conway's Game of Life.
- Key Differences:
- Multi-State Cells: Cells are not just "alive" or "dead". When a live cell dies, it enters a "dead wait"
state for a number of generations (
rule_c) before it can be reborn. - Three Colors: It supports two competing teams and a third "referee" color for cells born from ties.
- Rules: It uses separate rules for Birth (
rule_b) and Survival (rule_s).
- Multi-State Cells: Cells are not just "alive" or "dead". When a live cell dies, it enters a "dead wait"
state for a number of generations (
- Data Structure: Represents the grid very differently from the other simulators. It uses
setobjects containing string representations of coordinates (e.g.,"(x,y)") to track the state of each color, providing fast lookups. - Interaction: Instantiated and controlled by the
StarGOLGenerationsmanager.
The pattern of interaction is consistent across the library:
- A user chooses a Manager Class (e.g.,
HellmouthGOL) based on the desired rules and topology. - The user provides configuration (grid size, initial patterns) to the manager's constructor.
- The manager's
create_life()method instantiates the corresponding Life Simulator Class (e.g.,HellmouthBinaryLife), passing it the parsed configuration. - When the user calls
next_step()on the manager, the manager calls the correspondingnext_step()ornext_generation()method on its internallifeobject. - The life simulator updates the grid state according to its specific rules and data structures.
- The manager retrieves updated statistics by calling a counting method on the
lifeobject (e.g.,get_stats(),get_live_counts()).