Page 1 of 1

Without changing the definition of cgrid or ngrid, amend the program in the Appendix to implement the "Game of Life," di

Posted: Fri Apr 29, 2022 7:11 am
by answerhappygod
Without Changing The Definition Of Cgrid Or Ngrid Amend The Program In The Appendix To Implement The Game Of Life Di 1
Without Changing The Definition Of Cgrid Or Ngrid Amend The Program In The Appendix To Implement The Game Of Life Di 1 (79.26 KiB) Viewed 31 times
DO NOT COPY AND PASTE WHAT IS ON CHEEG OR THE INTERNET ALREADY!
IT IS WRONG. I WILL DOWN VOTE YOUR ANSWER IF YOU DO THAT.
PLEASE PROVIDE PYTHON CODE PLEASE!!
Without changing the definition of cgrid or ngrid, amend the program in the Appendix to implement the "Game of Life," displaying cells 20 pixels wide and animated at a rate of four frames per second. The only functions allowed are: main() and on_closing(). The program must be structured and formatted appropriately, including a call to main(), an appropriate program header, and commenting throughout. Include the following structured English to comment the code: Gracefully respond to the closing of the game window Create the game window Define the Cells Grid (cgrid) and Neighbors Grid (ngrid) The main GOL loop Clear and repaint the canvas Count the number of live neighbors (update ngrid) Apply Conway's GOL rules (update cgrid) Detect closing of the game window Call the main()
APPENDIX: import numpy as np import random GRIDSIZE = 10 print(f'Grid Size = {GRIDSIZE}') cgrid = np.zeros((GRIDSIZE+2, GRIDSIZE+2), dtype='int') cgrid(1:-1, 1:-1] = np.random.randint(2, size=(GRIDSIZE, GRIDSIZE)) print('Cells Grid:') for cell in cgrid: print(cell) ngrid = np.zeros_like(cgrid) for row in range(1, GRIDSIZE+1): for col in range(1, GRIDSIZE+1): ngrid[row][col] = np.sum(cgrid[row-1:row+2, col-1:col+2]) \ - cgrid[row][col] print('NCount:') for cell in ngrid: print(cell) for row in range(1, GRIDSIZE+1): for col in range(1, GRIDSIZE+1): cgrid[row][col] = 1 if (ngrid[row][col] == 3) or (cgrid[row][col] == 1 and ngrid[row][col] == 2) else 0 print('Next Generation') for cell in cgrid: print(cell)