Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Programming Assignment 6 - Game of Life, Part 2

ECS 32A - Summer 2022

Your final programming assignment is to complete the Game of Life program that you     began in Programming Assignment 5.  Your program should take the form of a function  called life.   This function should not expect any arguments and should not return any  value (other than the default None).  This function should read data for the initial grid      from a text file, print some number of generations of new grids, and then save the most    recent generation to a text file.  The exact details of how your program should behave can be seen in this example:

>>> life()

Enter input file name: data .txt

No such file .  Try again .

Enter input file name: lifedata .txt

How many new generations would you like to print? four

Not a valid number .

How many new generations would you like to print? 4

Generation:  0

. . . . . . .

. . * . . . .

. . . * . . .

. * * * . . .

. . . . . . .

. . . . . . .

Generation:  1

. . . . . . .

. . . . . . .

. * . * . . .

. . * * . . .

. . * . . . .

. . . . . . .

Generation:  2

 


 

. .

. .

. .

. *

. .

. .

.

.

.

.

*

.

. . . .

. . . .

* . . .

* . . .

* . . .

. . . .

 


 

Generation:  3

. . . . . . .

. . . . . . .

. . * . . . .

. . . * * . .

. . * * . . .

. . . . . . .


Generation:  4

. . . . . . .

. . . . . . .

. . . * . . .

. . . . * . .

. . * * * . .

. . . . . . .

Would you like to save the latest generation? ('y' to save): y

Enter destination file name: lifedata .txt

Do you want to overwrite that file? ('y' to continue): n

Enter destination file name: save.txt

Saving data to save.txt

End of program.

>>> life()

Enter input file name: save .txt

How many new generations would you like to print? 5

Generation:  0

. . . . . . .

. . . . . . .

. . . * . . .

. . . . * . .

. . * * * . .

. . . . . . .

Generation:  1

. . . . . . .

. . . . . . .

 


 

. . .

. . *

. . .

. . .

.

.

*

*

. . .

* . .

* . .

. . .

 


 

Generation:  2

 


 

. . .

. . .

. . .

. . .

. . *

. . .

.

.

.

.

.

*

. . .

. . .

. . .

* . .

* . .

* . .

 


 

Generation:  3

. . . . . . .

. . . . . . .

. . . . . . .

. . . * . . .

. . . . * * .

. . . * * . .


Generation:  4

. . . . . . .

. . . . . . .

. . . . . . .

. . . . * . .

. . . . . * .

. . . * * * .

Generation:  5

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . * . * .

. . . . * * .

Would you like to save the latest generation? ('y' to save): n

End of program.

>>>

As seen in the example above, your program must ask the user for the name of the input file, and must verify that the file exists.  If that file doesn't exist, your program must ask for another file name.

When all the generations have been printed, your program must ask the user if the latest   generation should be saved.  If the answer is yes, your program must then ask for the        name of the file where the data will be saved.  If that file already exists, your program      should verify that the user wants to overwrite that file, and ask for another file name if the user does not want to overwrite the existing file.

When your program asks the user for the number of generations to print, the program should verify that the user's input is valid.

For the initial grid in the example above, the data in the text file would look like this:

 

0000000

0010000

0001000

0111000

0000000

0000000

It is important to remember, however, that the dimensions of the initial grid may be       different than what is shown above.  Your program must reformat the input data as a list of lists before passing this data to the nextGen function. When saving a grid to a text  file, your program must save the data as a string, in the format used for the initial grid    above.  Your program should be able to use a file saved in this fashion as the initial grid for another run of your program.


Your program must be written so that it uses your nextGen function from Programming Assignment 5 to compute the new grids.  Your nextGen function must behave as           specified in Programming Assignment 5, and your Game of Life program must                 communicate with the nextGen function in exactly the way specified in Programming   Assignment 5.  We may replace your nextGen function with our own when grading

your program.

Your solution is to be written using Python 3. Make sure you provide              comments including the file name, your name, and the date at the top of the file you submit. Also make sure to include appropriate docstrings for all       functions.

The names of your functions must exactly match the names given in this           assignment. The order of any parameters in your parameter list must exactly match the order given in this assignment.

You  may want to write additional functions other than those specified for your solution. That's fine with us.

Where to do the assignment

You can do this assignment on your own computer, or in the labs. In either case, use the IDLE development environment -- that's what we'll use when we grade your       program. Put all the functions you created for both Programming Assignment 5 and Programming Assignment 6 in a file called "prog56.py".

Submitting the Assignment

We will be using Canvas to turn in assignments. Submit the file containing your    functions as an attachment.  Do NOT cut-and-paste your functions into a text        window. Do NOT hand in a screenshot of your functions' output.  Do NOT include your test data.  We want one file from you: "prog56.py".