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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 29 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)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply