How to resolve the algorithm Forest fire step by step in the J programming language
How to resolve the algorithm Forest fire step by step in the J programming language
Table of Contents
Problem Statement
Implement the Drossel and Schwabl definition of the forest-fire model.
It is basically a 2D cellular automaton where each cell can be in three distinct states (empty, tree and burning) and evolves according to the following rules (as given by Wikipedia) Neighborhood is the Moore neighborhood; boundary conditions are so that on the boundary the cells are always empty ("fixed" boundary condition). At the beginning, populate the lattice with empty and tree cells according to a specific probability (e.g. a cell has the probability 0.5 to be a tree). Then, let the system evolve. Task's requirements do not include graphical display or the ability to change parameters (probabilities p and f ) through a graphical or command line interface.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Forest fire step by step in the J programming language
Source code in the j programming language
NB. states: 0 empty, 1 tree, _1 fire
dims =:10 10
tessellate=: 0,0,~0,.0,.~ 3 3 >./@,;._3 ]
mask=: tessellate dims$1
chance=: 1 :'(> ? bind (dims$0)) bind (mask*m)'
start=: 0.5 chance
grow =: 0.01 chance
fire =: 0.001 chance
spread=: [: tessellate 0&>
step=: grow [`]@.(|@])"0 >.&0 * _1 ^ fire +. spread
run=:3 :0
forest=. start''
for.i.y do.
smoutput ' #o' {~ forest=. step forest
end.
)
run 2
##### #
# #
### ####
# # # #
##### #
## # #
# #
o## #
##### #
# #
### ####
# # # #
##### #
## # #
o #
o# #
You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the AWK programming language
You may also check:How to resolve the algorithm Bitmap/Bézier curves/Cubic step by step in the Raku programming language
You may also check:How to resolve the algorithm Longest common subsequence step by step in the BASIC programming language
You may also check:How to resolve the algorithm The Name Game step by step in the Factor programming language
You may also check:How to resolve the algorithm Abbreviations, easy step by step in the Pascal programming language