Win a copy of Head First Android this week in the Android forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Tim Cooke
• Junilu Lacar
Sheriffs:
• Rob Spoor
• Devaka Cooray
• Jeanne Boyarsky
Saloon Keepers:
• Jesse Silverman
• Stephan van Hulst
• Tim Moores
• Carey Brown
• Tim Holloway
Bartenders:
• Jj Roberts
• Al Hobbs
• Piet Souris

# Multi Dimensional Arrays - Hints to the following prob

Greenhorn
Posts: 1
• Number of slices to send:
Optional 'thank-you' note:
Consider a two dimensional array with M rows and N columns. This represents the world in which some organisms live. Each of the M by N cells in this array is either occupied (if an organism lives there) or is vacant. No more than one organism can live in any one cell at any time. Each cell, except those on the boundaries (the edge of the world), has exactly eight neighboring cells (above, below, left, right, and four diagonals). The cells on the boundaries have less than eight neighboring cells.

Initially, there is a given population of organisms occupying certain of the cells. At each succeeding generation, the organisms reproduce and die as follows:

Each organism of the current generation survives to the next generation if, and only if, it has 2 or 3 neighbors (a neighbor is an organism that lives in a neighboring cell). Otherwise, it dies and its cell becomes empty in the next generation. Note: it dies if it is ``lonely'' or ``overcrowded''.

Each vacant cell in the current generation becomes occupied by a new organism in the next generation if, and only if, it has exactly 3 neighbors. Otherwise, it remains vacant in the next generation.
For example, suppose the initial world (the ``zero"th generation) is as follows, using X to indicate the occupied cells and blanks for the vacant cells:

X X
XXX XX XXXX
X X XX

Then the next generation is X XX
X XX XX
X XX XX

On the input file, the blanks are represented by dots.

Write a program to play this Game of Life. Your program should read the initial world from a file (see below) and repeatedly generate new generations, prompting the user each time to see if he or she wants to see the next generation or terminate the program. Also, the program should terminate automatically if the world becomes empty, displaying a message accordingly (this will happen for life3.dat).

Use two-dimensional arrays of type char to store the old and new generations respectively. To keep things simple, assume that M=25 and N=75, i.e. the world has 25 rows and 75 columns, and define these in a final statement before declaring your array variables.

Data files for testing your program will be provided on the home page. You should make sure your program works correctly on all these files, and you should also try your own test data. Download these files simply by choosing save Target link as when the cursor is on the specific file on the The Data for the Game of Life page and the mouse right button is pressed. If you type .dat after the file name, it will be saved as dat file. Thus your program would read for instance, file0.dat. The program should prompt the user for the name of the input file (use a String variable).