Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use this codes to do it please Due: June 22nd, 2017 (a 11:59.59 PM Program 18 60

ID: 3850656 • Letter: U

Question




Use this codes to do it please


Due: June 22nd, 2017 (a 11:59.59 PM Program 18 60 points (see Grading Notes for details) You are going to be implementing the classic computer science simulation, Conways Game of Life. Conway's Life is played on a matrix of cells, kind of like a chess board but theoretically extending infinitely in every direction. Each to the screen. Adead cell is shown by leaving that area of the matrix in the display empty. Each cell has a "neighborhood consisting of the eight cells in everydirection around it, including diagonals. Cells on the edges of the matrix may not have eight true" neighbors, but we will assume that their neighbors that would be off the matrix are considered to always be dead cells. From generation to generation, whether or not a cell survives or has life born into it depends on how many neighbors it has. Some examples follow. Please note that these eight examples are not the only possible scenarios that your program might encounter In each of these examples, we are focusing on what happens to the middle cell in these examples from one generation to the next. Adead middle cell with exactly three live neighbors becomes a live cell in the next generation (birth) The middle cell would become live in The middle cell would become live in the next generation because it has the next generation because it has exactly 3 live neighbors. exactly 3 live neighbors. Alive middle cell with two or three live neighbors stays alive in the next generation (survival): The middle cell would survive to the The middle cell would survive because next generation because it has two live it has three live neighbors neighbors In all other cases, the middle cell dies or remains dead (overcrowding or loneliness) The middle cell would die in the next The middle cell would die in the next generation because it has only one live T T generation because it has four live neighbor (loneliness). neighbors (overcrowding). The middle cell would remain dead in The middle cell would remain dead in the next generation because it has only the next generation because it has four two live neighbors (loneliness). live neighbors (overcrowding). PROGRAMIREQUIREMENT1 USECODE GIVEN TO YOU You will be able to copy the skeleton of a program out of my directory to get started. This skeleton code will set up your main method, a method that actually drives the simulation, a method that displays the matrix to the screen and a method that sets a default pattern in the matrix. Studying the code given to you will help you understand how the entire program fits together. The starter code for our class is located in the Assignments section on Blackboard. You must use this starter code as it is significantly different from other sections Now, use vim to edit NetID Life .j ava the way you normally would edit a program file.

Explanation / Answer

public class jsmith_Life {

private final static int GRIDSIZE = 18;

public static void main(String args[]) {

boolean board[][] = new boolean[GRIDSIZE][GRIDSIZE];

char choice;

int x=1;

Scanner sc=new Scanner(System.in);

intro();

do {

System.out.println("Start with a (r)andom board, the (q)ueen bee shuttle or the (g)lider pattern?");

choice=sc.next().charAt(0);

}while(choice != 'u' && choice != 'p' && choice != 'r' && choice != 'q' && choice != 'g' && choice != 'b');

clearGrid(board);

setup(board,choice);

do {

System.out.println(" ");

System.out.println("Viewing generation #%d: ");

displayGrid(board);

genNextGrid(board);

System.out.println(" (q)uit or any other key + ENTER to continue");

choice = sc.next().charAt(0);

}while(choice != 'q');

}

public static void setup(boolean[][] grid, char choice) {

  

}

public static void intro() {

System.out.println("Welcome to the Conway's Life");

System.out.println("User has to provide some random 2d Array provided with some live cells");

System.out.println("The output is the next generation 2d array obtained from user's input");

  

}

public static void clearGrid(boolean[][] grid) {

for(int i=GRIDSIZE;i<GRIDSIZE;++i)

for(int j=GRIDSIZE;j<GRIDSIZE;++j)

board[i][j]=false;

}

public static int countNeighbors(boolean[][] grid, final int row, final int col) {

int count=0;

if((row-1)>=0) if(grid[row-1][col]==true) count++;

if((col-1)>=0) if(grid[row][col-1]==true) count++;

if((row-1)>=0 && (col-1)>=0) if(grid[row-1][col-1]==true) count++;

if((row+1)<GRIDSIZE && (col-1)>=0) if(grid[row+1][col-1]==true) count++;

if((row-1)>=0 && (col+1)<GRIDSIZE) if(grid[row-1][col+1]==true) count++;

if((row+1)<GRIDSIZE && (col+1)<GRIDSIZE) if(grid[row+1][col+1]==true) count++;

if((row+1)<GRIDSIZE) if(grid[row+1][col]==true) count++;

if((col+1)<GRIDSIZE) if(grid[row][col+1]==true) count++;

return count;

}

public static void getNextGrid(boolean[][] grid) {

boolean temp[][]=new boolean[GRIDSIZE][GRIDSIZE];

clearGrid(temp);

for(int i=0;i<GRIDSIZE;++i) {

for(int j=0;j<GRIDSIZE;++j) {

temp[i][j]=grid[i][j];

int count = countNeighbors(grid,i,j);

if(grid[i][j]==false && count==3) temp[i][j]=true;

else if(grid[i][j]==true && (count==2 || count==3)) temp[i][j]=true;

else temp[i][j]=false;

}

}

for(int i=0;i<GRIDSIZE;++i) {

for(int j=0;j<GRIDSIZE;++j) {

grid[i][j]=temp[i][j];

}

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote