https://github.com/Jeadie/Go-L Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + By Plan + Enterprise + Teams + Compare all + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} Jeadie / Go-L Public * Notifications * Fork 3 * Star 46 Game of Life with different update rules and on a bunch of different topologies (sphere, torus, klein bottle, etc.) 46 stars 3 forks Star Notifications * Code * Issues 0 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights Jeadie/Go-L This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 2 branches 0 tags Code * Clone HTTPS GitHub CLI [https://github.com/J] Use Git or checkout with SVN using the web URL. [gh repo clone Jeadie] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @Jeadie Jeadie Merge pull request #2 from leoredi/patch-1 ... 60e4d9b Nov 7, 2022 Merge pull request #2 from leoredi/patch-1 Typos 60e4d9b Git stats * 47 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows run gh-page action in docs/ folder Jul 17, 2022 cmd temp from macOS Oct 6, 2022 docs temp from macOS Oct 6, 2022 pkg/gol Merge branch 'main' into main Aug 29, 2022 .gitignore add wasm and js cmd for Go-l Jul 20, 2022 README.md Typos Nov 7, 2022 go.mod Merge branch 'main' into main Aug 29, 2022 go.sum Merge branch 'main' into main Aug 29, 2022 View code Go-L Usage Border Topologies More on Game of Life Update Rules Update Rules: 1D example 2D Implementation README.md Go-L Game of Life simulation I originally wrote a Game of Life model in C, GOL. But I wanted to convert it into Golang for a few reasons: * Learn Go * Consider more novel topologies based on border rules (see # border-topologies). * Extend GOL simulation for generic update rules. * Extend GOL lattice for integer values (i.e. not just 1/0) * Run physical system simulations based on applications of cellular automaton: + Computational fluid dynamics + Population dynamics + Ising Models + Other interesting cellular automaton: Rule 90, Langton's ant + Boolean binary logic rules (i.e. consider the 1 cell + 4 neighbours as a 5 bit input - 1 bit output to a logic circuit) + Discretise and extend to 2D my previous research in rho signalling in cell-cell junctions during collective cell migration Usage Current usage simply displays the simulation onto the terminal. Usage: > Go-L --help Usage of Go-L: -aliveratio float The fraction of squares that start as alive, assigned at random. Domain: [0.0, 1.0]. (default 0.8) -gridsize uint Length of square grid to define game on. (default 20) -iterations uint Max number of iterations to simulate game of life. If stable solution, will exit early. (default 100) -topology string Specify the topology of the grid (as a fundamental topology from a parallelograms). Valid parameters: BORDERED, TORUS, KLEIN_BOTTLE, PROJECTIVE_PLANE, SPHERE. (default "BORDERED") -updatedelay uint Additional period delay between updating rounds of the game, in milliseconds. Does not take into account processing time. (default 200) -updaterule uint Specify the number associated with the update rule to use. Default to Conway's Game of Life. (default 1994975360) Border Topologies In redefining how the border conditions work, we can simulate GOL as if it was played on a variety of manifolds. This is most clearly seen when looking at the fundamental polygons derived from a square (or parallelogram). When considering the neighbours of a cell on the border of the lattice, a fundamental polygon helps show where the neighbouring values should be. Sphere Real Projective Plane Klein Bottle Torus Sphere Real Projective Plane Klein Bottle Torus Consider a square lattice of size 5, coordinates indexed in $[0,4] \ times [0,4]$. For a standard coordinate, say $(2,2)$, its neighbours are: ${(1,2),(3,2),(2,1),(2,3)}$. These are all within standard bounds. Now consider the point $(4,2)$ with neighbours: ${(3,2), (5,2),(4,1),(4,3)}$. What value should we use for $(5,2)$? The topology dictates how lattice-border neighbours get selected. For a bordered topology, there is nothing outside of lattice, therefore index it the null value (or 0 in GOL rules). For a sphere, the $(5,2) $ becomes $(2,0)$ given its equivalence relation (on an $n$ square lattice): $$ \displaylines{ (x, 0) \backsim (n, n-x), \quad x\in [0, n] \\ (x, n) \backsim (0, n-x), \quad x\in [0, n] } $$ Or for a torus $$ \displaylines{ (x, 0) \backsim (x, n), \quad x\in [0, n] \\ (0, y) \backsim (n, y), \quad y\in [0, n] } $$ or a real projective plane $$ \displaylines{ (0, y) \backsim (n, n-y), \quad y\in [0, n] \\ (x, 0) \backsim (n-x, n), \quad x\in [0, n] } $$ and lastly a klein bottle $$ \displaylines{ (0, y) \backsim (n, y), \quad y\in [0, n] \\ (x, 0) \backsim (n-x, n), \quad x\in [0, n] } $$ For update rules that consider 2nd degree neighbours (i.e. $(6,2)$ ), the mapping gets a bit more complicated. More on Game of Life A cellular automaton designed by mathematician John Conway showing how complex emergent behaviour can arise from simple rules. In his case, at each future timestamp, a cell will be updated, based on its four neighbouring cells: 1. A live cell will survive if only 2 or 3 of its neighbours are alive 2. A dead cell with 3 alive neighbours will become alive 3. All other cells die. Update Rules Conway's Game of Life is but one 2D cellular automata that depends only on its 4 direct neighbours. One can conceive of other update rules. If one considers the five relevant cells: left, cell, right, up & down, there are then $2^5=32$ possible states to consider. An update rule can be defined as follows. 1. Define an ordered set on the 32 possible states $ { s_i }_{i=0}^ {32} $ 2. Create a 32 digit binary number, $B$, where $B_i = 1$ iff the update rule maps the cell with state $S_i$ to 1. 3. All update rules can be then indexed from this, $U_B : {0,1}^5 \ to { 0, 1}$ Update Rules: 1D example Consider a simple 1D case of: left, cell, right. There are 8 states with a natural indexing: $111, 110, 101, 100, 011, 010, 001, 000$. An example update rule $U_{177}$ updates the cell to 1 in the following cases: 111, 101, 100, 000 (all other cases to 0). With the binary expansion $177 = 10110001b$, this can be expressed simply below: 111 110 101 100 011 010 001 000 1 0 1 1 0 0 0 1 2D Implementation In this repo, we consider a similar binary representation for cells: left, cell, right, up, down and a natural indexing $11111, 11110, 11101, ..., 00001, 00000$. This creates $2^5=32$ possible states and therefore $2^{32} = 4294967296$ possible update rules (conveniently fitting in a 32-bit integer). We can now consider the update rule in Conway's Game of Life: 1. Alive and 3 neighbours: 01111, 10111, 11101, 11110 ([15, 23, 29, 30]) 2. Alive and 2 neighbours: 00111, 01101, 01110, 10101, 10110, 11100 ([7, 13, 14, 21, 22, 28]) 3. Dead and 3 neighbours: 01011, 10011, 11001, 11010 ([11, 19, 25, 26]) Which gives a binary number with 1's at positions: [7, 11, 13, 14, 15, 19, 21, 22, 23, 25, 26, 28, 29, 30] or in binary: 01110110111010001110100010000000 or in base 10: 1994975360 About Game of Life with different update rules and on a bunch of different topologies (sphere, torus, klein bottle, etc.) Topics golang game-of-life cellular-automata cellular-automaton conways-game-of-life game-of-life-golang Resources Readme Stars 46 stars Watchers 2 watching Forks 3 forks Packages 0 No packages published Contributors 3 * @Jeadie Jeadie Jack Eadie * @leoredi leoredi Federico Leo Redi * @dangrier dangrier Daniel Grier Languages * Go 100.0% Footer (c) 2022 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.