SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Arrays
Exercise:
Programming Projects
Question:13 | ISBN:9780321531346 | Edition: 7

Question

The mathematician John Horton Conway invented the “Game of Life.”

Though not a “game” in any traditional sense, it provides interesting behavior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows

the rules of LIFE to show the continuing behavior of the configuration.

LIFE is an organism that lives in a discrete, two-dimensional world. While

this world is actually unlimited, we don’t have that luxury, so we restrict

the array to 80 characters wide by 22 character positions high. If you have

access to a larger screen, by all means use it.

This world is an array with each cell capable of holding one LIFE cell. Generations

mark the passing of time. Each generation brings births and deaths to

the LIFE community. The births and deaths follow the following set of rules.

We define each cell to have eight neighbor cells. The neighbors of a cell

are the cells directly above, below, to the right, to the left, diagonally

above to the right and left, and diagonally below to the right and left.

If an occupied cell has zero or one neighbors, it dies of loneliness. If an

occupied cell has more than three neighbors, it dies of overcrowding.

If an empty cell has exactly three occupied neighbor cells, there is a

birth of a new cell to replace the empty cell.

Births and deaths are instantaneous and occur at the changes of generation.

A cell dying for whatever reason may help cause birth, but a newborn

cell cannot resurrect a cell that is dying, nor will a cell’s death

prevent the death of another, say, by reducing the local population.

Notes: Some configurations grow from relatively small starting configurations.

Others move across the region. It is recommended that for text output

you use a rectangular array of char with 80 columns and 22 rows to

store the LIFE world’s successive generations. Use an asterisk * to

indicate a living cell, and use a blank to indicate an empty (or dead)

cell. If you have a screen with more rows than that, by all means make

use of the whole screen.

Examples:

***

becomes

*

*

*

then becomes

***

again, and so on.

Suggestions: Look for stable configurations. That is, look for communities

that repeat patterns continually. The number of configurations in the

repetition is called the period. There are configurations that are fixed,

which continue without change. A possible project is to find such

configurations.

Hints: Define a void function named generation that takes the array we call

world, an 80-column by 22-row array of char, which contains the initial

configuration. The function scans the array and modifies the cells, marking

the cells with births and deaths in accord with the rules listed earlier. This

involves examining each cell in turn, either killing the cell, letting it live, or,

if the cell is empty, deciding whether a cell should be born. There should be

a function display that accepts the array world and displays the array on

the screen. Some sort of time delay is appropriate between calls to

generation and display. To do this, your program should generate and

display the next generation when you press Return. You are at liberty to

automate this, but automation is not necessary for the program.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.