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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started