# Game Of Life

By [Lax](https://paragraph.com/@lax-2) · 2021-12-25

---

![](https://storage.googleapis.com/papyrus_images/35ece708c9dd86aa5b8846d010beb1afdb65bf9604189c019056b54cce1d1fc2.jpg)

Game Of Life Rules :
--------------------

A board with equal size square boxes called cells. Each cell is alive when its bright and dead when its not. For a cell to be alive it must have 2 or more neighbouring cells that are alive too else it dies. If it has one alive neighbour it dies, no neighbour, it dies. A cell is born when a cell has exactly three live neighbours.

So usually, this is played in a infinite universe and an infinite environment space with unlimited memory and computing power that none of us has access to so building it on a periodic-repeating single plane universe when the edges are connected to its parallel ones.

Langauges:
----------

Rust, WebAssembly and Javascript

![the only god tier languages I know in existence ](https://storage.googleapis.com/papyrus_images/2d902c399fbbce7e763cf1060edc7086f5b55b75b08ee80623147fb8213e0524.png)

the only god tier languages I know in existence

Why Javascript?

*   can directly read and write to WebAssembly limear memory space
    
*   Garbage-collector heap
    
*   considers and returns scalar
    

What is `wasm_bindgen`

*   used to box Rust structures
    
*   wrapping pointers in javascript class for usability
    
*   basically clears boundries
    

Game Plan
---------

Well, here comes the binary! the best part. The whole universe is mapped cell to byte into a flat one dimensional array where the live cell is represented by 0 and a dead cell is represented by 1.

Consider a **4 x 4** universe : 16 cells in total mapped into an flat array looks like this →

![count index 0](https://storage.googleapis.com/papyrus_images/254cc8ef31a52d72b23f439d0aeb7905e2658ab3c70075310471fa9b19048701.png)

count index 0

How is it mapped? good question! An `index` function is used to allocate the cell environment into a byte memory reserved in the universe like this:

`index(row, column, universe) = row * width(universe)`

> WebAssembly LIner Memoy ?→ Rust `String` → Javascripts Garbage collector Heap → HTML `textContent`

code source

As you notice, a macro `#[repr(u8)]` is used so as to represent each cell with a single byte.

---

*Originally published on [Lax](https://paragraph.com/@lax-2/game-of-life)*
