Question: Using linux VM to create this project. Vectors only no arrays. Following Conway's game of life and these instructions: Life must continously update to a
Using linux VM to create this project. Vectors only no arrays. Following Conway's game of life and these instructions:
Life must continously update to a desired generation or 1 by 1 as seen at end of code.
Thanks.

Rules are at the top of the picture.
This is what I have, not sure what to do:
#include
#include // for exit();
#include // to parse long arguments.
#include // sleep
#include
using std::vector;
#include
using std::string;
static const char* usage =
"Usage: %s [OPTIONS]... "
"Text-based version of Conway's game of life. "
" --seed,-s FILE read start state from FILE. "
" --world,-w FILE store current world in FILE. "
" --fast-fw,-f NUM evolve system for NUM generations and quit. "
" --help,-h show this message and exit. ";
size_t max_gen = 0; /* if > 0, fast forward to this generation. */
string wfilename = "/tmp/gol-world-current"; /* write state here */
FILE* fworld = 0; /* handle to file wfilename. */
string initfilename = "/tmp/gol-world-current"; /* read initial state from here. */
/* see the hints section of the readme: to get the basics working,
* uncomment this next line, and you'll have a suitable test vector
* to which you can apply the rules. */
// #define WARMUP 1
//ifdef WARMUP
vector > world = {
#include "res/bglider-small"
};
//endif
/* NOTE: you don't have to write these functions -- this is just how
* I chose to organize my code. */
size_t nbrCount(size_t i, size_t j, const vector >& g);
void update();
int initFromFile(const string& fname); /* read initial state into vectors. */
void mainLoop();
void dumpState(FILE* f);
/* NOTE: you can use a *boolean* as an index into the following array
* to translate from bool to the right characters: */
char text[3] = ".O";
int main(int argc, char *argv[]) {
// define long options
static struct option long_opts[] = {
{ "seed", required_argument, 0, 's' },
{ "world", required_argument, 0, 'w' },
{ "fast-fw", required_argument, 0, 'f' },
{ "help", no_argument, 0, 'h' },
{ 0,0,0,0 }
};
// process options:
char c;
int opt_index = 0;
while ((c = getopt_long(argc, argv, "hs:w:f:", long_opts, &opt_index)) != -1) {
switch (c) {
case 'h':
printf(usage, argv[0]);
return 0;
case 's':
initfilename = optarg;
break;
case 'w':
wfilename = optarg;
break;
case 'f':
max_gen = atoi(optarg);
break;
case '?':
printf(usage, argv[0]);
return 1;
}
}
/* NOTE: at this point wfilename initfilename and max_gen
* are all set according to the command line. */
/* If you wrote the initFromFile function, call it here: */
// initFromFile(initfilename);
mainLoop();
return 0;
}
void mainLoop() {
/* TODO: write this */
/* update, write, sleep */
if (max_gen == 0) {
/* make one generation update per second */
}
else {
/* go through generations as fast as you can until
* max_gen is reached... */
}
}
Content of world file:
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0 }, { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
1. If a live cell has fewer than 2 neighbors, it dies (underpopulation) 2. If a live cell has more than 3 neighbors, it dies (overpopulation 3. If a dead cell has exactly 3 nelghbors, 1t becomes alive (reproduction. Before going any further, make sure you understand how the rules would give you the following beforejafter 00I00 do.. Note also that the grid is finite, but to avold having any walls or boundaries we'll glue opposi te edges together to form a torus, kind of like some of those old school video games. So, each cell will have exactly & neighbors. Command line interface Part of this assignment's purpose 1s to teach you about writing programs that acoept arguments on the command line. I've given you a skeleton that works most of this stuff out for you (using GNU's venerable getopt long function).In particular, we will have the following options, which can be shown by running /LLfe--help: Usage: /LLfe [OPTIONS).. Text-based verslon of Conway's gane of lif FILE read start state fron FILE store current world in FILE --worldFILE fast-fw, help, -h NUM lve systen for NUM generations and quit. show this eassage and exit The s option is for the initial state of the "world" You can see examples in the res/ directory for the format. Dead cells are represented by characters and live ones by . Ybu can infer the grid size from the length of the first line, and the total umber of lines you've read There are two kinds of modes for your program. The first mode slowly evolves the initial configuration once every second, writing the output to whatever file was supplied with.You can then watch the system evolve by watching the output file with the watch command. It'll look something like this A few early generations of the R-pentomino The second mode will evolve the system as fast as it can for some specified number of generations, specified by -f. Important: if the user supplies f.you should not do any walting! Compate the desired generation, write the output, and uit. Standard input and output 1. If a live cell has fewer than 2 neighbors, it dies (underpopulation) 2. If a live cell has more than 3 neighbors, it dies (overpopulation 3. If a dead cell has exactly 3 nelghbors, 1t becomes alive (reproduction. Before going any further, make sure you understand how the rules would give you the following beforejafter 00I00 do.. Note also that the grid is finite, but to avold having any walls or boundaries we'll glue opposi te edges together to form a torus, kind of like some of those old school video games. So, each cell will have exactly & neighbors. Command line interface Part of this assignment's purpose 1s to teach you about writing programs that acoept arguments on the command line. I've given you a skeleton that works most of this stuff out for you (using GNU's venerable getopt long function).In particular, we will have the following options, which can be shown by running /LLfe--help: Usage: /LLfe [OPTIONS).. Text-based verslon of Conway's gane of lif FILE read start state fron FILE store current world in FILE --worldFILE fast-fw, help, -h NUM lve systen for NUM generations and quit. show this eassage and exit The s option is for the initial state of the "world" You can see examples in the res/ directory for the format. Dead cells are represented by characters and live ones by . Ybu can infer the grid size from the length of the first line, and the total umber of lines you've read There are two kinds of modes for your program. The first mode slowly evolves the initial configuration once every second, writing the output to whatever file was supplied with.You can then watch the system evolve by watching the output file with the watch command. It'll look something like this A few early generations of the R-pentomino The second mode will evolve the system as fast as it can for some specified number of generations, specified by -f. Important: if the user supplies f.you should not do any walting! Compate the desired generation, write the output, and uit. Standard input and output
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
