The Game of Life, also known as Conways’ Game of Life, is a cellular automaton game invented by mathematician John Horton Conway in 1970.

The game is played on a grid of cells, each of which can be either dead or alive. The state of each cell is determined by its neighbors according to a set of rules. At each step in the game, the state of each cell is updated based on the state of its neighbors in the previous step.

This code will render a random initial configuration to see how one half of the window ‘incubates’ and spreads living cells into the rest of the window. Sometimes it does, some others it gets extinct.

# Remember to install pygame 
# !pip install pygame

import pygame
import random

# Initialize pygame
pygame.init()

# Set up the window
width, height = 1000, 500
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Game of Life")

# Set up the grid
cell_size = 10
rows = 50
columns = 100
grid = [[0 for _ in range(columns)] for _ in range(rows)]

# Set up the colors
dead_color = (255, 255, 255)
alive_color = (0, 0, 0)

# Set up the clock
clock = pygame.time.Clock()

# Set up the initial state of the cells (change here to fix the initial spread)
for i in range(rows):
    for j in range(columns//2):
        grid[i][j] = random.choice([0, 1])

# Main game loop
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    # Update the state of the cells
    new_grid = [[0 for _ in range(columns)] for _ in range(rows)]
    for i in range(rows):
        for j in range(columns):
            # Count the number of alive neighbors
            alive_neighbors = 0
            for x in range(-1, 2):
                for y in range(-1, 2):
                    if x == 0 and y == 0:
                        continue
                    if i + x < 0 or i + x >= rows or j + y < 0 or j + y >= columns:
                        continue
                    alive_neighbors += grid[i + x][j + y]
            # Update the cell based on the rules of the Game of Life
            if grid[i][j] == 1:
                if alive_neighbors < 2 or alive_neighbors > 3:
                    new_grid[i][j] = 0
                else:
                    new_grid[i][j] = 1
            else:
                if alive_neighbors == 3:
                    new_grid[i][j] = 1

    # Draw the cells on the screen
    for i in range(rows):
        for j in range(columns):
            color = alive_color if grid[i][j] == 1 else dead_color
            pygame.draw.rect(screen, color, (j * cell_size, i * cell_size, cell_size, cell_size))

    # Update the grid
    grid = new_grid

    # Update the display
    pygame.display.flip()

    # Limit the frame rate
    clock.tick(1000)

# Quit pygame
pygame.quit()

Update: Run this code for Google Colab:

import matplotlib.pyplot as plt
import random
import numpy as np
from IPython.display import clear_output  # Import the clear_output function

# Set up the grid
cell_size = 10
rows = 50
columns = 100
grid = np.zeros((rows, columns), dtype=int)

# Set up the colors
dead_color = (255, 255, 255)
alive_color = (0, 0, 0)

# Set up the initial state of the cells (change here to fix the initial spread)
for i in range(rows):
    for j in range(columns // 2):
        grid[i, j] = random.choice([0, 1])

# Function to update the state of the cells
def update_grid(grid):
    new_grid = np.copy(grid)
    for i in range(rows):
        for j in range(columns):
            # Count the number of alive neighbors
            alive_neighbors = np.sum(grid[max(0, i-1):min(rows, i+2), max(0, j-1):min(columns, j+2)]) - grid[i, j]
            # Update the cell based on the rules of the Game of Life
            if grid[i, j] == 1:
                if alive_neighbors < 2 or alive_neighbors > 3:
                    new_grid[i, j] = 0
            else:
                if alive_neighbors == 3:
                    new_grid[i, j] = 1
    return new_grid

# Main loop to simulate the steps of the game and display the evolution
steps = 500  # Number of steps to run the simulation
for step in range(steps):
    plt.imshow(grid, cmap='binary')
    plt.xticks([]), plt.yticks([])
    plt.pause(0.02)
    clear_output(wait=True)  # Clear the previous frame before displaying the new one
    grid = update_grid(grid)

# Show the final state after the simulation ends
plt.show()

* recommended version in C++ or JS for optimal performance.

The game is known for its ability to generate complex and seemingly intelligent behavior from a simple set of rules. It has been used as a model for understanding complex systems in fields such as biology, economics, and social science.

Despite its simplicity, the Game of Life has been the subject of much research and fascination, and it continues to be a popular topic in computer science and mathematics.