Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2 The Game of Life Imagine a world of organisms living in a two-dimensional cell grid of size nzm. Each organism can only occupy a
2 The Game of Life Imagine a world of organisms living in a two-dimensional cell grid of size nzm. Each organism can only occupy a single cell. Each cell, except those at the boundaries (the edge of the world), has exactly eight neighboring cells (up, down, left, right, and four diagonals). The cells at the boundaries have less than eight neighboring cells. The world evolves from one generation to the other using the following rules: 1. Any organism with fewer than two neighbors (a neighbor is an organism that lives in a neighboring cell) dies (out of 2. Any organism with more than three live neighbors dies (overcrowding) 3. Any organism with two or three live neighbors lives on to the next generation 4. Any vacant cell with exactly three live neighbors becomes occupied by a new organism (birth) Write a C program that plays the game of life. Your program should 1. Read an initial world configuration from a file world.txt. The world is of size 10r10 2. Evolve the world to the next generation. 3. Display the old and new world generation on screen. 4. Ask the user if he/she wants to continue evolution to the next generation. 5. Display a message if the entire world is extinct. You should ignore the cells at the boundary of the world since the do not have enough neighbors to play the game. For a modular design, you should use the following functions void read-world (FILE *inp , int x[][SIZE]); // reads a world from a file to array x void print.world (int xSIZE]): II prints world stored in array x on screen int evolve (int xSIZE, int row, int col); // returns the evolved cell value for cell x [row]col void copy-world (int xsIZE,int ySIZE]ITcopies world in x to y int extinct (int xSIZEDE T/ returnsa zero if all organisms are extinct Sample initial worlds are provided HINTS Play the game by hand on a small array to understand it You need 2 two-dimensional arrays: one that stores the current generation and one that stores the future one. . Start your cell procession from cell (1,1) up to cell (1,m-2) and cell (m-2, 1) to cell (m-2, m-2) For better understanding of your code use #define ALIVE 1 and #define DEAD 0, to denote the organism state. Print "* for an alive mechanism and a "0" for a dead one Sample Evolution old World:0 0 0 0 0 0 0 0 00 New World:0 0 00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started