blob: b4c35ce89f52fa4808fa87ae0e56fe28518c04c5 (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.";
|