Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -0,0 +1,77 @@
#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

View file

@ -13,7 +13,7 @@ class Forest {
has $.f;
method new(Int $height, Int $width, $p=0.01, $f=0.001) {
my $c = self.bless(*, :$height, :$width, :$p, :$f);
my $c = self.bless(:$height, :$width, :$p, :$f);
$c!init-grid;
$c!init-neighbors;
return $c;