Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Game of Life was invented by John H. Conway to model some genetic laws for birth, death, and survival. Consider a checkerboard consisting of

The Game of Life was invented by John H. Conway to model some genetic laws for birth, death, and survival. Consider a checkerboard consisting of an n-by-n array of squares. Each square can contain one individual (denoted by 1) or be empty (denoted by - ). Figure 1 (a) shows a 6-by-6 board with four of the squares occupied. The future of each individual depends on the number of his neighbors. After each period of time, called a generation, certain individuals will survive, others will die due to either loneliness or overcrowding, and new individuals will be born. Each non-border square has eight neighboring squares. After each generation, the status of the squares changes as follows:

An individual survives if there are two or three individuals in neighboring squares.

An individual dies if he has more than three individuals or less than two in neighboring squares.

A new individual is born into each empty square with exactly three individuals as neighbors.

Figure 1 Two generations.

image text in transcribed

Figure 1 (b) shows the status after one generation.

Write a program to do the following:

Declare a two-dimensional array of size n, where n is input by the user, to hold the status of each square in the current generation. To specify the initial configuration, have the user input each row as a string of length n, and break the row into 1's or dashes with the Substring method.

Declare a two-dimensional array of size n to hold the status of each square in the next generation. Compute the status for each square and produce the display in Figure 1 (b). Note: The generation changes all at once. Only current cells are used to determine which cells will contain individuals in the next generation.

Assign the next-generation values to the current generation and repeat as often as desired.

Display the individuals in each generation. 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. Don't forget that a cell is not a neighbor of itself.

(Test the program with the initial configuration shown in Figure 2 . It is known as the figure-eight configuration and repeats after eight generations. )

Figure 2. The figure eight.

image text in transcribed

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

Database Basics Computer EngineeringInformation Warehouse Basics From Science

Authors: Odiljon Jakbarov ,Anvarkhan Majidov

1st Edition

620675183X, 978-6206751830

More Books

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago