The grid is populated randomly

Assignment Help C/C++ Programming
Reference no: EM13166208

John H. Conway, a Cambridge mathematician, invented the Game of Life. The simulation runs on a square, two-dimensional array. Each cell in the array is in one of two states: occupied by a creature or empty.

Initially, the grid is populated randomly with occupied and empty cells. Once the initial grid has been created, the program loops. Each iteration of the loop represents a tick or time step in the environment.

Cells interact with their eight neighbors. Neighbors are the cells that are horizontally, vertically, or diagonally adjacent.

Creatures are created and die based on the following rules:

  1. Any living creature (occupied cell) with fewer than two live neighbors dies of loneliness.

  2. Any living creature with two or three live neighbors lives on to the next generation.

  3. Any living creature with more than three live neighbors dies of overcrowding.

  4. Any empty cell with exactly three live neighbors becomes an occupied cell. This represents a birth.

Your project should have three classes: Cell, Environment, and EnvironmentDriver. The Cell class will represent a single cell. It should contain the following:

Instance variables:
• A private boolean variable occupied that is true if the cell is occupied and false if

the cell is not occupied.

Methods:

  • A constructor that takes one boolean argument. This constructor should use its

    parameter to set the instance variable occupied.

  • An accessor (get) method for the occupied instance variable.

    The Environment class be responsible for running the simulation: Instance variables:

    • A private two-dimensional array of cells.

    Methods:

  • A constructor that takes one argument, n. The constructor should create the n x n

    array of cells. It should then randomly fill the array with occupied and empty cells.

  • A public runSimulation method is responsible for displaying the grid graphically

    and creating the next generation based on the rules given above.

    In addition, you should create private methods that divide up the work and make your code easier to read. These might include: a method that that is responsible for creating a grid that represents the next generation of creatures; a method that determines how many neighbors a single cell has; and a method that displays the grid graphically.

    You should use the class StdDraw to create your graphical representation. StdDraw will be demonstrated in class.

    The EnvironmentDriver class should contain the main method that starts the simulation. Here is some sample code for this method:

    public static void main(String[] args) {

    Environment e = new Environment(20);

    e.runSimulation(); }

    This code creates a 20 x 20 grid and starts the simulation.

Reference no: EM13166208

Questions Cloud

Change the inheritance to private inheritance : Take the following C++ code and make the following changes. Change the inheritance to private inheritance. Change the private data member balance to protected. Define get function members of IntAccount class to retrieve name and balance.
Which pair is written with first member having the higher : Which pair is written with the first member having the higher boiling point?
Draw a lewis structure for h2nnh2 : Draw a Lewis Structure for C3O2. Draw a Lewis Structure for C2H3NO5
State what concentration of ca remains in solution : If 2.55 g of NaOH were added to a 100.0 mL solution containing 0.10 M Ca(NO3)2, what concentration of Ca 2+ remains in solution?
The grid is populated randomly : Initially, the grid is populated randomly with occupied and empty cells. Once the initial grid has been created, the program loops. Each iteration of the loop represents a tick or time step in the environment.
Optimize the query in the select script using alter table : optimize the query in the select script using Alter Table to add appropriate indexes. Also use Optimize and Explain to show how the performance of this query has improved.
What is the approximate ph after adding the sodium acetate : If you are given sodium acetate and asked to make a .5 M acetate buffer at pH 4.75, will you have to add acid, base, or nothing in order to achieve the proper pH? What is the approximate pH after adding the sodium acetate?
Consider the standard heats of formation : Consider the following standard heats of formation: Standard Heat of formations for the substances:CO2(g) = -393.5 kJ/mol PbO(s) = -151.6 kJ/mol CO(g)
Before each sort, write psudo-code : Ceate a single cpp ?le (FILE=MAIN2.cpp) containing all three elementry sorts(bubble, insertion, selection). Before each sort, write psudo-code and invarient analysis of the sort in block comment style. Add the code from 3.). Generate a list of 100..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd