about summary refs log tree commit diff stats
path: root/js/baba-yaga/scratch/baba/life-demo-alt.baba
diff options
context:
space:
mode:
Diffstat (limited to 'js/baba-yaga/scratch/baba/life-demo-alt.baba')
-rw-r--r--js/baba-yaga/scratch/baba/life-demo-alt.baba91
1 files changed, 91 insertions, 0 deletions
diff --git a/js/baba-yaga/scratch/baba/life-demo-alt.baba b/js/baba-yaga/scratch/baba/life-demo-alt.baba
new file mode 100644
index 0000000..b4c35ce
--- /dev/null
+++ b/js/baba-yaga/scratch/baba/life-demo-alt.baba
@@ -0,0 +1,91 @@
+// Conway's Game of Life Demo
+
+// Simple blinker pattern demonstration
+// Initial state: vertical line of 3 cells
+// Next state: horizontal line of 3 cells
+
+// Generation 0 - vertical blinker
+cell_0_1 : 1;  // top
+cell_1_1 : 1;  // middle  
+cell_2_1 : 1;  // bottom
+
+// All other cells are 0
+cell_0_0 : 0;
+cell_0_2 : 0;
+cell_1_0 : 0;
+cell_1_2 : 0;
+cell_2_0 : 0;
+cell_2_2 : 0;
+
+io.out "Conway's Game of Life - Blinker Demo";
+io.out "====================================";
+
+io.out "Generation 0 (vertical line):";
+io.out "Row 0:";
+io.out cell_0_0;
+io.out cell_0_1;
+io.out cell_0_2;
+io.out "Row 1:";
+io.out cell_1_0;
+io.out cell_1_1;
+io.out cell_1_2;
+io.out "Row 2:";
+io.out cell_2_0;
+io.out cell_2_1;
+io.out cell_2_2;
+
+// Calculate Generation 1
+// For the middle cell (1,1): has 2 vertical neighbors, survives
+// For cells (1,0) and (1,2): each has 3 neighbors, become alive
+// All other cells die or stay dead
+
+// Middle cell (1,1) - count neighbors
+neighbors_1_1 : cell_0_1 + cell_2_1;  // 2 neighbors
+next_1_1 : when (cell_1_1 = 1 and (neighbors_1_1 = 2 or neighbors_1_1 = 3)) is
+  true then 1 _ then 0;
+
+// Left cell (1,0) - count neighbors  
+neighbors_1_0 : cell_0_0 + cell_0_1 + cell_1_1 + cell_2_0 + cell_2_1;  // 3 neighbors
+next_1_0 : when (cell_1_0 = 0 and neighbors_1_0 = 3) is
+  true then 1 _ then 0;
+
+// Right cell (1,2) - count neighbors
+neighbors_1_2 : cell_0_1 + cell_0_2 + cell_1_1 + cell_2_1 + cell_2_2;  // 3 neighbors  
+next_1_2 : when (cell_1_2 = 0 and neighbors_1_2 = 3) is
+  true then 1 _ then 0;
+
+// All other cells in generation 1 will be 0
+next_0_0 : 0;
+next_0_1 : 0;
+next_0_2 : 0;
+next_2_0 : 0;
+next_2_1 : 0;
+next_2_2 : 0;
+
+io.out "";
+io.out "Generation 1 (horizontal line):";
+io.out "Row 0:";
+io.out next_0_0;
+io.out next_0_1;
+io.out next_0_2;
+io.out "Row 1:";
+io.out next_1_0;
+io.out next_1_1;
+io.out next_1_2;
+io.out "Row 2:";
+io.out next_2_0;
+io.out next_2_1;
+io.out next_2_2;
+
+io.out "";
+io.out "Neighbor counts:";
+io.out "Cell (1,1) neighbors:";
+io.out neighbors_1_1;
+io.out "Cell (1,0) neighbors:";
+io.out neighbors_1_0;
+io.out "Cell (1,2) neighbors:";
+io.out neighbors_1_2;
+
+io.out "";
+io.out "The blinker oscillates between vertical and horizontal!";
+io.out "This demonstrates Conway's Game of Life rules.";