Conways Game of Life
Conways Game of Life
MM2103
Remanshu 2301mm38
Pranay Bolli 2301mm39
Sankruti shetti 2301mm40
REPORT
Conway’s Game of Life
Objectives :
Logic :
1. Grid Setup :
A 256x256 grid is initialized with all cells dead (0).
Some cells are set to alive (1) to create an initial pattern.
2. Display Grid :
The current state of the grid is printed, using * for alive cells and . for dead cells.
3. Neighbor Counting :
For each cell, the program counts the number of alive neighbors (8 surrounding cells),
wrapping around edges using modulo arithmetic.
4. State Update :
The next state of each cell is determined:
o Alive cells survive with 2 or 3 neighbors; otherwise, they die.
o Dead cells become alive if they have exactly 3 alive neighbors.
5. Infinite Loop :
The grid is updated and printed continuously, with a short delay to visualize the evolution over
time.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define WIDTH 256
#define HEIGHT 256
#define ALIVE 1
#define DEAD 0
int main() {
int grid[HEIGHT][WIDTH] = {0};
int newGrid[HEIGHT][WIDTH] = {0};
while (1) {
printGrid(grid);
updateGrid(grid, newGrid);
return 0;
}
Output :