Java application game of life, JAVA Programming

Assignment Help:

The game of Life, invented by John Conway, is supposed to model the genetic laws for birth, survival, and death (see Scienti_c American, October 1970, p. 120). We will play it on a board with a maximum of 60 squares (i.e. columns) in the horizontal direction and a maximum of 20 squares (i.e. rows) in the vertical direction. Each square can be empty or contain an X indicating the presence of an organism. The small dashed square shown in the segment of the board drawn below connects all the neighbors of the organism in row 3, column 3 (note that the upper left corner cell on the board is at location row 1, column 1).

1940_game.png

The next generation of organisms is determined according to the following criteria:

Birth An organism will be born in each empty location that has exactly three neighbors.

Death An organism with four or more organisms as neighbors will die from overcrowding. An organism with fewer than two neighbors will die from loneliness.

Survival An organism with two or three neighbors will survive to the next generation.

Generations 2 and 3 for the sample follow:

430_game1.png

Generation #2 Generation #3

2131_game2.png

Note that each new generation is computed only from the data in the previous generation. In other words, when considering a cell's neighbors you only use the information on the previous generation, not the data (organisms) in the current generation you are computing.

You should allow for a minimum game board of 3 rows by 3 columns and a maximum size of 20 rows by 60 columns. Read in an initial configuration of organisms from a text data _le

(specified on the command line with the _le name echo printed to the screen; do not make any assumptions about the name of this _le) with the following format:

1084_game3.png

 

Any data, characters, or blank lines that might follow the '0 0' sentinel value pair should be ignored.

Use the following algorithm as a starting point for writing your simulation:

initialize the board to empty (i.e. no organisms)

set generation equal to 1

input starting board from data _le

write board to screen and pause

repeat

increment generation by 1

compute the next generation

write new generation to screen and pause

until _nished

Be sure to subdivide your code into appropriate methods as discussed in class.

All inputed data must be in the ranges indicated; any erroneous data should be reported to the user and a fatal exception (of type java.lang.RuntimeException; see below) should be raised. Each board should be printed in text mode (i.e. do not use graphics and/or separate windows|you must use print, println, or printf to produce your output) and should be labeled with its generation number, with the initial con_guration labeled as generation 1.

You should number the rows and columns in the manner shown in the examples (especially note the numbering in the second sample run below) that follow plus print a boundary around each board (using the +, -, and | characters) and use the X (capital x) character to represent organisms, e.g. the Generation 1 board on the previous page would be drawn like this:

1234

+----+

1| |1

2| X X|2

3| X |3

4| X |4

5| X X|5

+----+

1234

(Note that there are no blank rows in the example given; this board is printed using 9 rows total, counting the numbering and borders.) You should also pause between printing each generation, continuing only when the user presses the ENTER key; make sure they are prompted to press enter to continue (probably the easiest way to do this is by just calling the nextLine() method in the Scanner class).

Exceptions can be raised using the following code:

if ( some_condition ) throw new java.lang.RuntimeException("your error message goes here"); where some condition is the boolean error condition you are checking for, and the string passed to the constructor for java.lang.Exception should be some appropriate error message to the user.

2 Sample Runs

The following are only partial sample runs.

2.1 Sample Run #1

Data _le life2.dat:

3

3

5

1 2

3

2 2

3 2

0 0

Sample run:

liberty:~/javaprogs/% java Life2012 life2.dat

Game of Life (with board wrap)

D. Resler 2/99 [2012]

Opened file: life2.dat

Generation 1:

123

+---+

1| X |1

2| X |2

3| X |3

+---+

123

(press enter to continue)

Generation 2:

123

+---+

1| |1

2|XXX|2

3| |3

+---+

123

(press enter to continue)

Generation 3:

123

+---+

1| X |1

2| X |2

3| X |3

+---+

123

4

(press enter to continue)

Generation 4:

123

+---+

1| |1

2|XXX|2

3| |3

+---+

123

(press enter to continue)

Generation 5:

123

+---+

1| X |1

2| X |2

3| X |3

+---+

123

(press enter to continue)

liberty:~/javaprogs/%

2.2 Sample Run #2

Data _le lifeHandout.dat:

20

60

20

6 27

6 29

7 27

7 29

8 27

8 28

8 29

0 0

Sample run:

liberty:~/javaprogs/% java Life2012 lifeHandout.dat

Game of Life (with board wrap)

D. Resler 2/99 [2012]

(press enter to continue) (More would follow { not a complete run!)

3 Deliverables

You are to turn in your project through the project submission form on the class web page. Name your source code _le Proj7XXXX.java where XXXX is the last 4 digits of your student id number (and your class should therefore be named Proj7XXXX).


Related Discussions:- Java application game of life

Java class loaders , Classes are attached into the JVM as they are referenc...

Classes are attached into the JVM as they are referenced by name in a class that is already running in the JVM. So, how is the staring class loaded? The very first class is espec

What is javaserver faces expression language, A easy expression language us...

A easy expression language used by a JavaServer Faces UI component tag attributes to bind the associated component to a bean property or to bind the associated component's value to

What is public static void main signifies, What is 'public static void main...

What is 'public static void main (String args[ ] ) ' signifies? Access specifier is the 'public' keyword. 'static' keyword allows main() to called without instantiating

Can a human doctor be replaced through an expert system, Can a human doctor...

Can a human doctor be replaced through an Expert System? Give reasons to support your answer. Expert System is a computer system that simulates the knowledge and expertise of a

Help about java code regarding udp, I need to know waht exactly is happinin...

I need to know waht exactly is happining in the following code class Worker implements Runnable { DatagramSocket socket = null; DatagramPacket packet = null; public W

Interfaces and generics, In this assignment, you are provided with an inter...

In this assignment, you are provided with an interface that contains a generic type. You are asked to create two classes that implement this interface. A. The Sequenced Interfac

List down the analytical engine''s elements name, List down the Analytical ...

List down the Analytical Engine's elements name An analytical engine elements are as follows: Input Memory Processor Output.

I want java web developer finish a webcam site, Java Web Developer A web...

Java Web Developer A web developer is required to finish a webcam site with basic account management and voting functionality. The website can make use of a third party flash

Need help, please fix polygon method, code below: /** * @(#)AnimationExtr...

please fix polygon method, code below: /** * @(#)AnimationExtraCredit.java * * AnimationExtraCredit Applet application * * @author * @version 1.00 2013/5/5 */ import jav

Describe exception handling in java, Question A What are the difference be...

Question A What are the difference between an interface and an abstract class? Question B Describe Exception Handling in JAVA Question C Describe the following with resp

Write Your Message!

Captcha
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