python code for qts conway’s game of life

Getting your Trinity Audio player ready…

View Post

Below is a fully-working Python 3 program that implements the Quantum-Teleodynamic Synthesis (QTS) interpretation of Conway’s Game of Life exactly as described in the rule-set you asked for. The code is short, self-contained, and uses only numpy and matplotlib (both standard scientific-Python packages).

pythonCopyEdit"""
qts_life.py  –  Quantum-Teleodynamic Synthesis (QTS) version of Conway’s Game of Life
=====================================================================================

The update rule is still B3/S23, but every conditional is written in the language of
QTS pillars:

• Quantum-coherence gate  – kills cells whose neighbourhood count is not {2,3}
• Information-ratchet birth – births at neighbourhood count == 3
• Information-ratchet survival – survives at neighbourhood count in {2,3}
• Teleodynamic pruning – everything else dies

Run the file directly to see an animated simulation.
"""

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
from typing import Tuple


def qts_life_step(grid: np.ndarray) -> np.ndarray:
    """
    Vectorised one-tick update following the QTS rule-set
    ----------------------------------------------------
    Parameters
    ----------
    grid : np.ndarray, shape (H, W), dtype=bool or int
        Current lattice state (1 = live, 0 = dead)

    Returns
    -------
    next_grid : np.ndarray, same shape as `grid`, dtype=bool
        Lattice after one update tick
    """
    # Sum of the eight Moore neighbours via np.roll (periodic boundaries)
    nbrs = sum(np.roll(np.roll(grid, i, axis=0), j, axis=1)
               for i in (-1, 0, 1) for j in (-1, 0, 1)
               if (i, j) != (0, 0))

    # --- QTS conditionals --------------------------------------------------
    birth   = (grid == 0) & (nbrs == 3)         # information-ratchet birth
    survive = (grid == 1) & ((nbrs == 2) | (nbrs == 3))  # info-ratchet survival
    # teleodynamic pruning and coherence gate are implicit in the default False
    # -----------------------------------------------------------------------

    return (birth | survive).astype(bool)


# ---------------------------------------------------------------------------
# Optional utility functions for running / animating a simulation
# ---------------------------------------------------------------------------

def random_grid(shape: Tuple[int, int], density: float = 0.2) -> np.ndarray:
    """
    Create a random Boolean grid with given live-cell density.
    """
    return np.random.rand(*shape) < density


def run_simulation(size: Tuple[int, int] = (120, 160),
                   density: float = 0.2,
                   steps: int = 400,
                   interval: int = 40) -> None:
    """
    Launch a Matplotlib animation of the QTS-Life automaton.

    Parameters
    ----------
    size : (H, W)
        Lattice dimensions.
    density : float
        Fraction of live cells in the initial state.
    steps : int
        Number of animation frames to show.
    interval : int
        Delay between frames in milliseconds.
    """
    grid = random_grid(size, density)

    fig, ax = plt.subplots()
    img = ax.imshow(grid, cmap="binary")
    ax.set_axis_off()
    ax.set_title("QTS-interpreted Conway Life  (B3/S23)")

    def update(_frame):
        nonlocal grid
        grid = qts_life_step(grid)
        img.set_data(grid)
        return (img,)

    anim = animation.FuncAnimation(fig, update, frames=steps,
                                   interval=interval, blit=True)
    plt.show()


# ---------------------------------------------------------------------------
# Command-line entry point
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    run_simulation()

How to use it

  1. Save the file as qts_life.py.
  2. Make sure numpy and matplotlib are installed: bashCopyEditpip install numpy matplotlib
  3. Run: bashCopyEditpython qts_life.py An animated window will appear, evolving a random lattice under the QTS-formatted B3/S23 rule.

What the code does

  • qts_life_step is the pure update kernel; it embodies the four QTS conditionals exactly.
  • run_simulation is a minimal helper that seeds a random grid and animates it with periodic boundaries (torus topology).
  • All logic stays vectorised, so even large grids animate smoothly.

Feel free to replace the random seed with any pattern (e.g., a Gosper gun) or adapt the neighbourhood logic if you decide to experiment with alternative QTS-inspired rules.

o3


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *