Question
IN C LANGUAGE. PLEASE INCLUDE COMMENTS AS WELL. THANK YOU!! We will be using the concepts from project 2 to test the more recent concepts
IN C LANGUAGE. PLEASE INCLUDE COMMENTS AS WELL. THANK YOU!!
We will be using the concepts from project 2 to test the more recent concepts of linked lists, pointers, and file I/O. The initial data points will be stored in a file (specification of the layout of the file below), each grid of values will be dynamically allocated and then referenced via a pointer in a linked list. The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead, or "populated" or "unpopulated". Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:
Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
Any live cell with two or three live neighbours lives on to the next generation.
Any live cell with more than three live neighbours dies, as if by overpopulation.
Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seedbirths and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.
More details are:
input file
first line will list the number of time steps to simulate
second line will include number of rows followed by the number of columns in the grid to be simulated
remaining lines in the file will have the positions of the initial cells that are "alive"
dynamically create nodes that use the following struct
struct node { int rows; int columns; int * grid; // a pointer to the grid that should be of size rows*columns struct node *next_step; // a pointer to the node that holds the grid for the next time step };
you will create a linked list of nodes where each node is a single time step
the begin pointer should point to the initial grid, and each time step should follow.
no array notation is to be used, so no []'s should appear in your code.
You MUST create the following functions
struct node *createInitialNode(FILE *input, int *numsteps); // read data from file pointer input and return a dynamically created node with the data and the number of time steps to simulate in numsteps void nextStep(struct node *begin); // add a struct node to the end of the list pointed to by begin for the next time step, so use data in the last node in the list to create the new timestep. void printList(struct node *begin); // print out all the grids contained in the list pointed to by begin.
Example input file sampleinput.txt
contains:
3 10 12 7 7 7 8 7 9 8 7 9 8
So your code should display the following:
Welcome to Conway's game of Life Please enter filename 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000011100 000000010000 000000001000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000001000 000000011000 000000010100 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000011000 000000010100 000000010000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000000000 000000011000 000000110000 000000001000 000000000000
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