-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathblock-202.fth
More file actions
32 lines (23 loc) · 1.2 KB
/
block-202.fth
File metadata and controls
32 lines (23 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
( Conway's Game Of Life )
rows(--n)75 ; cols(--n)150 ;
grid-sz rows cols * const grid-sz
grid grid-sz var grid
work grid-sz var work
start grid cols + 1+ const start
end work cols - 2 - const end
states 10 var states states z" ?* " s-cpy drop
nb(addr--addr+1)dup c@ 1+ over c! 1+ ;
neighbors(addr--)cols - 1- nb nb nb cols + 3 - nb 1+ nb cols + 3 - nb nb nb drop ;
?alive(--)c@a '*' =ifa@ grid - work + neighborsthen;
live?(--c)c@b states + c@ dup '?' =ifdrop c@athen;
prep(a--a1 c)100 + >t t@ c@t 0 c!t tdrop ;
.row(r--)cols * grid + 10 + dup prep >t >t ztype t> t> swap c! ;
disp(--)1 1 ->cr 35 for i 10 + .row cr next ;
grid->work(--)start a!begin ?alive a@+ end < while;
work->grid(--)work b! grid a! grid-sz for live? c!a+ 0 c!b+ next ;
slow-down(--)10 ms ;
one-gen(--)grid->work work->grid disp slow-down ;
gens(gens--)for one-gen key?ifkey drop unloop exitthennext ;
init(--)grid a! grid-sz for 100 rand-mod 70 > 10 * 32 + c!a+ next ;32+10=42 ('*')
life(gens--)cur-off dupif0drop 500thencls init gens cur-on ;
lifes(n--)for 1000 life.s key dropnext ;