How to resolve the algorithm Forest fire step by step in the Déjà Vu programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Forest fire step by step in the Déjà Vu 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 Déjà Vu programming language

Source code in the déjà programming language

#chance of empty->tree
set :p 0.004
#chance of spontaneous tree combustion
set :f 0.001
#chance of tree in initial state
set :s 0.5
#height of world
set :H 10
#width of world
set :W 20

has-burning-neigbour state pos:
	for i range -- swap ++ dup &< pos:
		for j range -- swap ++ dup &> pos:
			& i j
			try:
				state!
			catch value-error:
				:empty
			if = :burning:
				return true
	false

evolve state pos:
	state! pos
	if = :tree dup:
		if has-burning-neigbour state pos:
			:burning drop
		elseif chance f:
			:burning drop
	elseif = :burning:
		:empty
	else:
		if chance p:
			:tree
		else:
			:empty

step state:
	local :next {}
	for k in keys state:
		set-to next k evolve state k
	next

local :(c) { :tree "T" :burning "B" :empty "." }
print-state state:
	for j range 0 H:
		for i range 0 W:
			!print\ (c)! state! & i j
		!print ""

init-state:
	local :first {}
	for j range 0 H:
		for i range 0 W:
			if chance s:
				:tree
			else:
				:empty
			set-to first & i j
	first

run:
	init-state
	while true:
		print-state dup
		!print ""
		step

run-slowly:
	init-state
	while true:
		print-state dup
		drop !prompt "Continue."
		step

run

  

You may also check:How to resolve the algorithm Determine if a string has all the same characters step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Processing programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Zig programming language
You may also check:How to resolve the algorithm Read a file character by character/UTF8 step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Binary digits step by step in the mLite programming language