ofile := "/tmp/ff.jbv" ;; type cell = `Forest | `Fire | `Ash ;; type configuration = [cell]Moore ;; fun populate_grid(g:Moore, size_x:int, size_y:int) = ( for i = 0 to size_x do for j = 0 to size_y do g.(i * |E> + j * |N>) := if random(10000) < 5 then `Fire else `Forest fi; g ) ;; S0 := populate_grid(Moore:(),100,100) ;; configuration(S0);; trans rules = { // Fire propagates to neighbor forest cells `Forest as c / neighbors_exists(equal(`Fire), c) => `Fire; // Extinction of fire `Fire => `Ash; } ;; fun output(S) = ( ofile << " { " ; foreach c @ p in S do begin let (x,y) = sequify(p) in ofile << " { " << x << " " << y; ofile << switch c case `Forest: " 0.6 0.73 0.35 } " case `Fire: " 0.96 0.59 0.27 } " case `Ash: " 0.29 0.27 0.16 } " endswitch end; ofile << " }\n" ; S ) ;; rules[fixpoint, prelude = output, interlude = output ](S0) ;;