5. A mathematician called John Horton Conway devised a \"zero-player game\" call
ID: 3678436 • Letter: 5
Question
5. A mathematician called John Horton Conway devised a "zero-player game" called The Game of Life in 1970. The universe of the game consists of a 2D grid of cells. Each cell consists of one of two states: Alive, Dead. Rules as follows are used to determine which cells live and which cells die on a generation by generation basis. Let's determine the fate of one cell using the following algorithm. Write the code that performs it.
INPUT
---------
i) Ask the user for the alive/dead status of one of its neighbors
ii) Repeat the above step 8 times to get all neighbor information
Keep track of how many of the neighbors are alive
CALCULATIONS
-----------------------
iii) If 0 or 1 neighbors are living, the cell is Dead in the next generation
If 2 or 3 neighbors are living, the cell is Living in the next generation
If 4 or more neighbors are living, the cell is Dead in the next generation
OUTPUT
------------
iv) Display if the cell is Alive or Dead
Explanation / Answer
import java.io.*;
import java.util.*;
public class Game() {
public static void main(String args[]) throws Exception() {
String user; int i; String status;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter User:”);
user = br.readLine();
System.out.println(“Enter status: Alive/Dead”);
status = br.readLine();
for(i: 0 t0 8) {
int[] a,d,count=0,count1=0;
if(status = = “Alive”)
a[i] = status;
count = count+1;
else
d[i]=status;
count1=count1+1;
}
system.out.println(“No.of neighbors alive:” + count);
System.out.println(“No.of neighbors Dead :” + count1);
public void Cell(int count) {
String sin;
for(i: 0 t0 8) {
if(count == 0 || count == 1)
sin = “DEAD”;
else if(count ==2 || count == 3)
sin=”ALIVE”;
else if(count >=4)
sin = “DEAD”;
}
System.out.println(“Cell Status :” + sin);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.