Question: Java game development The cellular automata algorithm which generated this output uses the following steps: For each cell, randomly define it as: wall (45% chance)

Java game development

The cellular automata algorithm which generated this output uses the following steps:

For each cell, randomly define it as: wall (45% chance) or floor (55% chance)

Perform the following procedure 4 times: o Calculate the number of wall neighbours of each cell, and define each cell which has at least 5 neighbouring wall cells, as a wall cell itself. Otherwise (i.e. if it has less than 5 wall neighbours) define it as a floor cell.

Your task is to write a Java class to implement this cellular automata algorithm:

(i) The class should store the cave-like structure in suitable member data [4]

(ii) The data should be randomly initialized according to the 1st step of the algorithm indicated above. Hint: use Math.random() to generate a random float between 0 and 1 [4]

(iii) The 2nd step of the algorithm (which repeats 4 times) should be implemented. You should pay particular attention to array bounds when examining a cells neighbours. [7]

(iv) The resulting data should be printed to the console, (using System.out.println) as the # and . symbols, as shown below.

Java game development The cellular automata algorithm which generated this output uses

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!