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

  Write a function num_digits(n)

C programing, not C++ write a function num_digits(n) that returns the number of digits in a nonnegative integer n.

  Reportingmark a string of 2 to 4 upper case

Declare a structure named: Car containing: reportingMark a string of 2 to 4 upper case characters carNumber an int kind could be box tank flat or other loaded a bool destination a string with a destination or the word NONE Note: A destination is r..

  Write a program that reads from a file a list of course name

Write a program that reads from a file a list of course names, letter grades for each course and number of credits each course is worth. The program will read each course name, grade earned and number of credits from the file and print out the course..

  Same birthday

How likely is it that two people in one section of our class (40 students) have the same birthday ?

  Time conversion

Write a C++ program that takes an Eastern standard time in hours, minutes, and seconds,and prints it out in Central time, Mountain time, or Pacific time.

  Program to generate 100,000 prime numbers

Write a POSIX C/C++ program to generate 100,000 prime numbers. Assume that the program will be run on a computer with 5 CPUs and that your goal is to have this program finish as quickly as possible.

  Operating system and cpu scheduling

Operating System and CPU Scheduling

  Write a program that displays a weekly payroll report

Write a program that displays a weekly payroll report

  Braces for blocks of code

C-- should have braces for blocks of code, an if statement, while statement, and a double, int, and character. Each statement ends with a semi-colon and you must have a main routine

  Converts the temperature f in farenheit to c in celsius

Write a program that converts the temperature F in Farenheit to C in Celsius using C = (F-32)*5/9. For ease of programming you can display the result in fractions.

  Basics of code development on linux and cryptography

Prepare a C program that gives simple mono-alphabetic substitution between plaintext, and Enhance your code to use "-e" to encrypt a string argument and "-d" to decrypt it using argv and argc

  Add 10 people to the line

Add 10 people to the line and process them. Each time you process someone, print out their ticket information. After all 10 have been serviced, print the average wait time. Below is an example of the time calls you will need and a wait function.

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