about summary refs log tree commit diff stats
path: root/js/baba-yaga/scratch/baba/life-simple.baba
blob: b2da07c1eebbdd7ef54d295add70d1abd0748e10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Simple Conway's Game of Life

// Create a simple 3x3 blinker using individual variables
c00 : 0; c01 : 1; c02 : 0;
c10 : 0; c11 : 1; c12 : 0;  
c20 : 0; c21 : 1; c22 : 0;

// Count neighbors for center cell (1,1)
neighbors11 : c00 + c01 + c02 + c10 + c12 + c20 + c21 + c22;

// Apply Game of Life rules to center cell
next11 : when (c11 = 1) is
  true then when (neighbors11 = 2 or neighbors11 = 3) is true then 1 _ then 0
  _ then when (neighbors11 = 3) is true then 1 _ then 0;

// Count neighbors for top-left cell (0,0)  
neighbors00 : c01 + c10 + c11;

// Apply rules to top-left cell
next00 : when (c00 = 1) is
  true then when (neighbors00 = 2 or neighbors00 = 3) is true then 1 _ then 0
  _ then when (neighbors00 = 3) is true then 1 _ then 0;

// Count neighbors for top-center cell (0,1)
neighbors01 : c00 + c02 + c10 + c11 + c12;

// Apply rules to top-center cell  
next01 : when (c01 = 1) is
  true then when (neighbors01 = 2 or neighbors01 = 3) is true then 1 _ then 0
  _ then when (neighbors01 = 3) is true then 1 _ then 0;

// Display results
io.out "Conway's Game of Life - Blinker Pattern";
io.out "Generation 0:";
io.out c00; io.out c01; io.out c02;
io.out c10; io.out c11; io.out c12;
io.out c20; io.out c21; io.out c22;

io.out "Generation 1 (center cell):";
io.out "Center cell neighbors:"; io.out neighbors11;
io.out "Center cell next state:"; io.out next11;

io.out "Generation 1 (top-left cell):";
io.out "Top-left neighbors:"; io.out neighbors00;
io.out "Top-left next state:"; io.out next00;

io.out "Generation 1 (top-center cell):";
io.out "Top-center neighbors:"; io.out neighbors01;
io.out "Top-center next state:"; io.out next01;

io.out "Done!";