Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rules of the Game The game starts with a initial set of alive cells (this is the first generation). The next generation evolves from applying

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Rules of the Game The game starts with a initial set of alive cells (this is the first generation). The next generation evolves from applying the following rules simultaneously to every cell on the game board, i.e. births and deaths happen simultaneously. Afterwards, the rules are iteratively applied to create future generations. Each generation depends exclusively on the preceding one. Rule 1 Alive cells with no neighbors s neighbor die of lonelines: Rule 3 Alive cells with two or thre neighbors survive. Ivouce the top rigri cell nas Iour States for the Game There are three states that the game can reach in regards to the rules provided. 1. There are no more living cells for the next generation. 2. There are living cells, but the next generation is the same as the last (stable game). 3. The next generation infinitely cycles throughout the game. Note that there are more scenarios for states 2 and 3 , these are just one example for each. Implementation Overview of files provided - GameOfLife class holds all of the methods to be written that will then be tested when running the game. Edit the empty methods with you solution, but DO NOT edlt the provided ones or the methods signatures of any method. This is the file you submit. 1. GameOfLife - One argument constructor - This method builds your game board (grid) from the input file (initial game pattem). - You have been provided some input files to test this method (input1.txt, input2.txt, input3.txt). The format is as follows: - One line containing the number of rows in the board game - One line containing the number of columns in the board game - Several lines (one for each row) containing the cell state (false for dead, true for alive) for each column in the board, space separated Use the Stdln library to read from a file: - StdIn .setfile(filename) opens a file to be read - StdIn. readInt() reads the next integer value from the opened file (weather the value is in the current line or in the next line) - StdIn. readBoolean() read the next boolean value from the opened file (weather the value is in the current line or in the next line) 2. getCellState Given two integers representing the cell row and column this method retums true if the cell is alive and false if the cell is dead. Test this method using the driver: - upon clicking the button Cell State you will be prompted to select a cell - select a cell by clicking in one square - the selected cell will light up red and the driver will state whether the cell is living or dead. 3. isAlive Retums true or false based on whether or not there are living cells within the board (grid) Test this method using the driver. Click on the Is Alive button and the driver will display whether or not there are living cells on the board game. Given two integers representing the cell row and column this method returns the cell's number of alive neighbors of a maximum of 8 neighbors. Test this method using the driver: - upon clicking the button Allve Neighbors you will be prompted to select a cell - select a cell by clicking in one square - the selected cell will light up red and the driver will state the total number of alive cells around the selected cell Example with default constructor 5. computeNewGrid This is where you will be using the rules of the game (stated above) to compute the next generation of cells. - create a new board (grid) to be returned, representing the new generation - for each cell, use the numOfAliveNeighbors method to determine how many cells are alive around a cell - then using the number of alive neighbors with the rules of the game determine if the cell will be set to be alive or dead in the new grid 6. nextGeneration Update the board (grid) with the board returned by the computeNewGrid method. Test this and the computeNewGrid methods using the driver by clicking the Next Generation button. The driver will state Next generation calculated. 7. nextGeneration - One argument The input integer parameter represents the number of generations to compute (fast forward). Test this methods using the driver: - upon clicking the Next N Generations button you will be prompted to enter a number - enter a number and click the Submit button - the driver will state that the board has evolved the number of generations requested 8. numberOfCommunities This method computes and returns the number of separate communities of cells in the board. A community is made of connected cells. Recall that Union-Find keeps track of connected components. In this assignment each connected component is a community of cells (all the cells in the community are connected). - Cells from separate communities are not connected. In algorithm Weighted Quick Union UF each community (connected component) is a tree. The community's representative is the root of the tree. - To connect two cells use the union method - To find the root of the tree a cell belongs to use the find method - To find the number of communities count the number of unique roots of trees Test this methods using the driver by clicking the Communities button. The driver will state the number of communities currently on the board

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions