Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new Python project called GameOfLife with a new Python file called playGOL . 2 . Be sure to include the Common Header as

Create a new Python project called GameOfLife with a new Python file called playGOL.
2. Be sure to include the Common Header as your intial documentation for the project.
3. Create the Python code that accomplishes the following (in loose order of how you can code the
program):
Import the numpy library as np
Create a two-dimensional Numpy array that looks like the following...
o Accomplish this by 1st creating a 2-dimentional Numpy array of size 5x5 which is
prefilled with zeros. (Note this can be done in one line of code.)
Use appropriate slicing methods to add the individuals to the grid. The upper corner will
require one line of code and the block of 1s in the middle of grid can be accomplished
in one line of code.
Display the starting array to the user through a print statement.
Create another numpy array that will represent the previous generation. At the beginning,
this array will simply be an exact copy of the starting array.
Create a for loop that will spawn the next 5 generations of the boards.
Within each loop iteration (generation cycle)...
o You will basically have 3 boards...
1. The board previous to the starting board for the cycle (previous board)
2. The board used at the beginning of the cycle (starting board)
3. The board generated in the cycle based on the starting board (new board)
o Based on the contents of the array within the starting board for the current generation,
determine the contents of array for the next generation. Use the rules described in the
project background section to determine the contents of the next generation.
1. Use the numpy sum function to determine the number of neighbors. An
important thing to consider is that you can use slicing to get the block of cells
and then use sum to determine the total population of the block. If you
subtract the value of the cell being evaluated, you will have the population of
the neighborhood.
o Print off the 3 boards (previous, starting, next gen)
o After determining the next generation board print out how many cells in the next
generation board are different from the starting board and how many cells in the next
generation board are different from the previous board.
1. NOTE In this step you are determining which cells are different. You are not
determining if the number of lives in the board is different. The reason for this
is because if the cells in the next generation board are the same as the starting
board, youll basically have an infinite cycle where the spawned boards are not
any different than the starting board. Additionally, if the next generation board
is a mirror copy of the previous board, youll have a loop where the boards will
just oscillate back and forth.
Run the application by clicking the Start button with the green arrow. Ensure the program runs
as expected. If the program does not run as expected, make appropriate coding changes and
retest.
Hint the hardest part of the program is determining the number of neighbors a cell has. In
general, you must check a 3-by-3 square around the cell in question. Exceptions must be made
when the cell is on the edge of the array. Dont forget that a cell is not a neighbor of itself. Within
one game board, you must check all cells in all rows and columns. You can consider a version of a
next loop where the outer loop will loop through the rows and the inner loop will loop through
the columns

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions