Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Conways Game of Life Conway's Game of Life1 is probably the best-known cellular automaton experiment. The world is an mn grid of cells, each of

Conways Game of Life Conway's Game of Life1 is probably the best-known cellular automaton experiment. The world is an mn grid of cells, each of which is either alive (marked by * asterisk) or dead (marked by space). Based on the current state of the world, a new generation is generated, wherein some cells may change their states, and others may stay the same. Each cell's new state will be based solely on its current state, and the current state of its eight immediate neighbours. Conway's Game of Life has four rules for determining the new state of a cell: 1. A dead cell (space) will become alive if it has exactly three live neighbours (reproduction). 2. A live cell (asterisk) with two or three live neighbours will continue to live. 3. A live cell (asterisk) with one or fewer neighbours will die of loneliness. 4. A live cell (asterisk) with four or more live neighbours will die of overcrowding. Objective: Your program will read a text file (ASCIIDataFile) representing the initial state of the world (generation 0). The first line contains the size of the world (width and height). Following this are height lines each consisting of width asterisks and spaces. There are no characters (i.e. no tabs) between the asterisks and spaces on each line, but the line ends with a newline ( ). After reading generation 0, the program should display the world in a BasicForm such as shown in Figure 1 displaying pulsar.txt. When the user presses Next, the program should generate the next generation and display it in the form, replacing the previous generation. This process continues until the user presses Quit at which point the program terminates.

Implementation: The world can be represented as a two-dimensional array of characters (char). After reading the width and height of the world, generation 0 can be read, one cell at a time, using the ASCIIDataFile method readC. readC reads the next character in the input file including tabs, newlines, etc. It is a raw read, reading everything in the file as opposed to readChar which reads a field containing a character separated from other fields by tabs and newlines. This means that, prior to reading the first character of the first row, it will have to skip the newline character at the end of the line containing the width and height. This is most easily done using the method nextLine. Similarly, after reading the last character of a row, it will have to skip over the newline at the end of that line via nextLine. For each generation, a new array representing the next generation will have to be created and populated according to the rules above. This then becomes the current generation and is displayed before generating the next generation, etc. In writing the world to the form (into a TextArea of exactly the right size), the program will have to output the cells (char) using writeC. writeC is a raw write that outputs the character into the next print position without any tabs or newlines between it and the previous character. After writing all the cells in the row, it will be necessary to write a newline using the newLine method. To avoid the TextArea containing the world from scrolling after the last row of the world is written, there should not be a newline written after the last row. Hints: Consider writing methods to: 1. load the world (generation 0) 2. display the world on the form 3. count the number of neighbors of a cell 4. produce the next generation.

Text files: acorn

30 30

*

*

** ***

--------------------------------------------

large world

7 7

* **

**

* *

** *

** *

** **

** *

Pulsar:

17 17

*** ***

* * * *

* * * *

* * * *

*** ***

*** ***

* * * *

* * * *

* * * *

*** ***

small world:

4 4

* *

* **

*

****

spaceship:

20 7

****

* *

*

* *

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

How Do I Use A Database Research Tools You Can Use

Authors: Laura La Bella

1st Edition

1622753763, 978-1622753765

More Books

Students also viewed these Databases questions

Question

How would you assess the value of an approach like this?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago

Question

3. How would this philosophy fit in your organization?

Answered: 1 week ago