/* Forest fire in Picat. From Rosetta Code: http://rosettacode.org/wiki/Forest_fire Model created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go => forest_fire(). forest_fire => _ = random2(), % dim oldgen(200,200), newgen(200,200) Rows = 20, Cols = 20, OldGen = new_array(Rows,Cols), NewGen = new_array(Rows,Cols), foreach(I in 1..Rows, J in 1..Cols) OldGen[I,J] := 1+random() mod 3, NewGen[I,J] := 0 end, % P = 99, % F = 9999, P = 9, F = 99, foreach(Generation in 1..4) printf("Generation %d\n", Generation), foreach(X in 2..Rows-1) foreach(Y in 2..Cols-1) % writeln([X,Y]), if OldGen[X,Y] == 0 then if random() mod 10 > P then NewGen[X,Y] := 1 %, % print("G") end elseif OldGen[X,Y] == 2 then if NewGen[X,Y] == 0 then % print("B") 1=1 end elseif OldGen[X,Y] == 1 then if OldGen[X-1,Y-1] == 2; OldGen[X-1,Y] == 2; OldGen[X-1,Y+1] == 2; OldGen[X,Y-1] == 2; OldGen[X,Y+1] == 2; OldGen[X+1,Y-1] == 2; OldGen[X+1,Y] == 2; OldGen[X+1,Y+1] == 2; % random() mod 10000 > F then random() mod 100 > F then % print("R"), NewGen[X,Y] := 2 end else 1=1 % print(" ") end, OldGen[X-1,Y-1] := NewGen[X-1,Y-1], if NewGen[X,Y] == 0 then print(" ") elseif NewGen[X,Y] == 1 then print("B") else print("R") end end, printf("\n") end, printf("\n") end, nl. c(0,"G"). c(1,"B"). c(2,"R").