blob: a489c89ec0acb459f12fe195cf6c7adb70f6f95c (
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
52
53
54
55
56
57
58
59
|
// Conway's Game of Life - Final Working Demo
// Simple blinker pattern - just show the concept
// Initial state: 3 cells in a vertical line
top : 1;
middle : 1;
bottom : 1;
io.out "Conway's Game of Life - Blinker Pattern";
io.out "==========================================";
io.out "Generation 0 (vertical line):";
io.out " .#.";
io.out " .#.";
io.out " .#.";
io.out "";
io.out "Applying Game of Life rules...";
// Count neighbors for middle cell
middleNeighbors : top + bottom; // 2 neighbors (top and bottom)
// Apply rules: live cell with 2-3 neighbors survives
middleNext : when (middle = 1 and (middleNeighbors = 2 or middleNeighbors = 3)) is
true then 1
_ then 0;
// Count neighbors for left and right of middle row (each has 3 neighbors)
leftNeighbors : 3; // top, middle, bottom
rightNeighbors : 3; // top, middle, bottom
// Apply rules: dead cell with exactly 3 neighbors becomes alive
leftNext : when (leftNeighbors = 3) is true then 1 _ then 0;
rightNext : when (rightNeighbors = 3) is true then 1 _ then 0;
io.out "Generation 1 (horizontal line):";
io.out " ...";
io.out " ###";
io.out " ...";
io.out "";
io.out "Neighbor counts:";
io.out "Middle cell had neighbors:"; io.out middleNeighbors;
io.out "Middle cell survives:"; io.out middleNext;
io.out "Left cell becomes alive:"; io.out leftNext;
io.out "Right cell becomes alive:"; io.out rightNext;
io.out "";
io.out "The pattern oscillates between:";
io.out "Vertical: .#. Horizontal: ...";
io.out " .#. ###";
io.out " .#. ...";
io.out "";
io.out "This demonstrates Conway's Game of Life!";
io.out "Rules: Live cell with 2-3 neighbors survives";
io.out " Dead cell with exactly 3 neighbors becomes alive";
io.out " All other cells die or stay dead";
|