Game of Life in Your Terminal

A simple implementation of Conway's Game of Life runnable in your Linux terminal using ncurses library


English 🇬🇧

🎮 Game Of Life in Your Terminal

A version of Conway’s Game of Life in your terminal written entirely in C, with graphics made possible by the ncurses library.

Open in Gitpod You can run the program online with GitPod. You need to log in with GitHub, select VSCODE Browser as the editor, set the class to Large, and click continue. Once vscode web is open, expand the terminal and execute gcc -Ofast -march=native -fomit-frame-pointer -funroll-loops main.c -o game_of_life -lncurses

📹 Demonstration Video

📑 Table of Contents

How it Works 🔧

For a more detailed description of the code, see main.c.

The algorithm operates as follows:

A support variable is used to save the grid configuration before starting the simulation. If the simulation is paused, it is possible to move to the next frame.

How to Play 🎮

Compile the Program 🛠️

gcc main.c -o game_of_life -lncurses

Run the Program with the Following Command

./game_of_life

Note: The program might temporarily change the terminal colors once finished. Just open a new terminal.

Note: The positions of the text in the menu have been optimized to be as centered as possible without overlapping. If the menu screen is not similar to this, close the program, enlarge the terminal, or execute the command ctrl + - and restart it:

show image img.png

Note: If the terminal is resized during the program execution, graphical bugs may occur, and it will be necessary to terminate and restart the process.

Game Commands

Menu:

Edit Mode:

During Simulation:

In edit mode, the cursor "X" will be visible, but not during the simulation.

In the top left corner, various information will be displayed:

Conway’s Game Rules 📋

Quoting Wikipedia: Game of Life

It is actually a game without players, meaning its evolution is determined by its initial state, without the need for any input from human players. It takes place on a grid of square cells that extends infinitely in all directions; this grid is called the world. Each cell has 8 neighbors, which are the cells adjacent to it, including those diagonally. Each cell can be in two states: alive or dead (or on and off). The state of the grid evolves in discrete time steps, meaning it progresses in clear intervals. The states of all cells at a given time are used to calculate the state of the cells at the next time step. All cells in the world are updated simultaneously in the transition from one time step to the next: thus, a generation passes.

The transitions depend solely on the state of neighboring cells in that generation:

  1. Underpopulation: Any live cell with fewer than two live neighbors dies, as if by isolation.
  2. Survival: Any live cell with two or three live neighbors survives to the next generation.
  3. Overpopulation: Any live cell with more than three live neighbors dies, as if by overpopulation.
  4. Reproduction: Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

Bugs 🐛

License 📜

This project is licensed under the MIT License. See the LICENSE file for details.

Italiano 🇮🇹

🎮 Game Of Life nel Tuo Terminale

Una versione di Conway’s Game of Life nel proprio terminale scritta interamente in C, grafica realizzata grazie alla libreria ncurses.

Open in Gitpod È possibile eseguire il programma online con GitPod. È necessario effettuare il login con github, selezionare come editor VSCODE Browser impostare la classe su Large e cliccare su continue. Una volta aperto vscode web espandi il terminale ed esegui gcc -Ofast -march=native -fomit-frame-pointer -funroll-loops main.c -o game_of_life -lncurses

📹 Video dimostrativo

📑 Indice

Funzionamento 🔧

Per una descrizione più dettagliata del codice vedere main.c.

L’algoritmo opera nel seguente modo:

Come giocare 🎮

Compila il programma 🛠️

gcc main.c -o game_of_life -lncurses

Esegui il programma con il seguente comando

./game_of_life

Nota: Il programma potrebbe modificare momentaneamente anche i colori del terminale una volta terminato. Basterà aprire un nuovo terminale.

Nota: Le posizioni delle scritte nel menu sono state ottimizzate per poter essere più centrate possibile senza accavallarsi. Se la schermata del menu non è simile a questa allora chiudere il programma, ingrandire il terminale oppure eseguire il comando ctrl + - e riavviarlo:

mostra l'immagine img.png

Nota: Se verrà ridimensionato il terminale durante l’esecuzione del programma potrebbero presentarsi bug grafici, sarà necessario terminare e rieseguire il processo.

Comandi di gioco

Menu:

Modalità edit:

Durante la simulazione:

Nella modalità edit sarà visibile il cursore "X", durante la simulazione no.

In alto a sinistra saranno mostrate varie informazioni relative a:

Regole del Gioco di Conway 📋

Citando Wikipedia: Gioco della vita

Si tratta in realtà di un gioco senza giocatori, intendendo che la sua evoluzione è determinata dal suo stato iniziale, senza necessità di alcun input da parte di giocatori umani. Si svolge su una griglia di caselle quadrate (celle) che si estende all’infinito in tutte le direzioni; questa griglia è detta mondo. Ogni cella ha 8 vicini, che sono le celle ad essa adiacenti, includendo quelle in senso diagonale. Ogni cella può trovarsi in due stati: viva o morta (o accesa e spenta, on e off). Lo stato della griglia evolve in intervalli di tempo discreti, cioè scanditi in maniera netta. Gli stati di tutte le celle in un dato istante sono usati per calcolare lo stato delle celle all’istante successivo. Tutte le celle del mondo vengono quindi aggiornate simultaneamente nel passaggio da un istante a quello successivo: passa così una generazione.

Le transizioni dipendono unicamente dallo stato delle celle vicine in quella generazione:

  1. Solitari: Qualsiasi cella viva con meno di due celle vive adiacenti muore, come per effetto d’isolamento.
  2. Sopravvivenza: Qualsiasi cella viva con due o tre celle vive adiacenti sopravvive alla generazione successiva.
  3. Sovrappopolazione: Qualsiasi cella viva con più di tre celle vive adiacenti muore, come per effetto di sovrappopolazione.
  4. Riproduzione: Qualsiasi cella morta con esattamente tre celle vive adiacenti diventa una cella viva, come per effetto di riproduzione.

Bug 🐛

Licenza 📜

Questo progetto è concesso in licenza sotto la Licenza MIT. Vedi il file LICENSE per i dettagli.