Question: Using Java to create a Game of Life simulation We want to represent the Game of Life with a 2D Board that contains Cells. Generation

Using Java to create a Game of Life simulation We want to represent the Game of Life with a 2D Board that contains Cells. Generation 0 is the initial setup, then with each step cells may live or die. The rules for going from one Conway Cell generation to another are: A dead cell is born, if exactly 3 neighbors are alive. A live cell dies, if less than 2 or more than 3 neighbors are alive. The rules for going from one Fredkin Cell generation to another are: A dead cell is born, if the number of neighbors is odd. A live cell dies, if the number of alive neighbors is even. Conway Cells have 8 neighbors: 1 2 3 4 @ 5 6 7 8 Fredkin Cells have 4 neighbors: . 1 . 2 @ 3 . 4 . Input The input is organized as follows: The first line contains the Cell Type and the Size. The next lines are x and y coordinates for the Alive pieces on the Board. For instance, the blinker is represented with: 0 5 1 2 2 2 3 2 The first line, 0 5 tells us that the Cell Type is 0 (ConwayCell) and the Size of the board is 5x5. The next three lines show us what cells should be alive. Below is a diagram of what it should look life if .'s are dead cells and @'s are alive cells. 0 1 2 3 4 0 . . . . . 1 . . @ . . (1,2) 2 . . @ . . (2,2) 3 . . @ . . (3,2) 4 . . . . . Implementation Board class Constructor Parameter: the name of the input file as a String Use a Scanner to parse the input data. You'll need to create an NxN 2d array and fill each element with the appropriate Cell. step() Moves forward one generation. Apply the algorithm shown in class. toString() This is for testing. Output something like this below, where @ is alive and . is dead. generation 1: . . . . . . . @ . . . . @ . . . . @ . . . . . . . After you have completed the Conway Cell class, you can test the Board, Cell, ConwayCell classes by adding this method to Board. public static void main(String[] args) { if (args.length != 1) { System.out.println("Error, program requires an argument. java programName input_file.txt"); } else { Board board = new Board(args[0]); System.out.println(board); board.step(); System.out.println(board); } } Conway Cell Conway Cell should extend Cell. You'll need to import javafx.scene.paint.Color. Constructor DEAD by default. Set the color to white. this.setFill(Color.WHITE); If given a state, determine which one and set the appropriate color. WHITE for DEAD and BLACK for ALIVE. dies() Set the state and color. (DEAD, WHITE) born() Set the state and color. (ALIVE, BLACK) getNeighbors() Parameters: x and y coordinates and a size. Returns: a List of Points that are the available neighboring points. getNewState() Parameter: the number of live neighbors Returns: DEAD, ALIVE, or SAME Game of Life You should not be able to run the Game of Life. I suggest using the main method in the Board class to make sure it works first. Once that works, use the GameOfLife class instead. Make sure to remove the main method from Board. $ javac GameOfLife.java Board.java Cell.java ConwayCell.java Point.java $ java GameOfLife input/conway_blinker.txt` Fredkin Cell Implementation is the same as Conway but the rules and number of neighbors differ.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!