Skip to content

examples: Conway's Game of Life on the ANE #173

Description

@sbryngelson

A tiny, very shareable demo in the spirit of examples/reaction_diffusion.py and examples/train_neural_ca.py: Conway's Game of Life with every generation as one on-engine forward pass.

Approach:

  • The neighbor count is a fixed 3x3 convolution with a center-zero kernel (all ones except the middle). aneforge/graph.py has af.conv / conv2d (see line ~455) -- use it with a constant weight, pad=1 (wrap-around is optional; zero-pad is fine for a first version).
  • The birth/survival rule is elementwise: a cell is alive next step iff (neighbors == 3) or (alive and neighbors == 2). Build it from select / maximum / clip (all in graph.py) or from arithmetic on the boolean-ish masks -- no host loop over cells.
  • Roll out N steps, dispatching the step graph each generation, and render frames to an animated webp with PIL exactly like reaction_diffusion.py does (from PIL import Image). Seed with a glider gun or a random field.

Deliverable: examples/game_of_life.py (self-contained, one file, module docstring saying what it shows), plus a one-line entry in examples/README.md. Keep the output asset small.

Testing: compare the first few generations against a trivial numpy Life reference to confirm the on-engine rule matches, then let it run. Requires any Apple Silicon Mac. A great newcomer demo -- follow reaction_diffusion.py as the template for the render loop and _common.py for env setup.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions