3 (* From: MODULA-2, An Introduction, by Daniel Thalmann, Springer-Verlag,
8 (* John Horton Conway's game "life" *)
10 FROM InOut IMPORT Write, WriteString, WriteLn, WriteCard,
18 IndRange = [1..MaxInd];
19 IndRange1 = [0..MaxInd1];
21 Cells = ARRAY IndRange1, IndRange1 OF State;
25 Generation, NbOfGen: CARDINAL;
26 PreviousNext: BOOLEAN;
27 CellsState: ARRAY BOOLEAN OF Cells;
28 Status: ARRAY IndStat OF State;
32 PROCEDURE InitAndReadPos;
34 Line, Column: CARDINAL;
37 FOR Line := 0 TO MaxInd1 DO
38 FOR Column := 0 TO MaxInd1 DO
39 CellsState[FALSE][Line, Column] := 0;
42 CellsState[TRUE] := CellsState[FALSE];
48 CellsState[FALSE][Line, Column] := 1;
52 PreviousNext := FALSE;
57 (* Ezra Gottheil method *)
70 WriteString("Please, enter the number of generations: ");
73 WriteString(" line and column positions: ");
78 PROCEDURE NextGeneration;
80 Line, Column: IndRange;
83 PROCEDURE Neighbourhood(L, C: IndRange1; VAR nbn: CARDINAL);
85 Line1, Column1: IndRange1;
88 FOR Line1 := L - 1 TO L + 1 DO
89 FOR Column1 := C - 1 TO C + 1 DO
90 INC(nbn, CellsState[PreviousNext][Line1, Column1]);
93 DEC(nbn, CellsState[PreviousNext][L, C]);
96 BEGIN (* NextGeneration *)
97 FOR Line := 1 TO MaxInd DO
98 FOR Column := 1 TO MaxInd DO
99 Neighbourhood(Line, Column, nbN);
100 CellsState[NOT PreviousNext][Line, Column] :=
101 Status[CellsState[PreviousNext][Line, Column]*9 + nbN];
104 PreviousNext := NOT PreviousNext;
107 PROCEDURE Impression;
110 Line, Column: IndRange;
113 WriteString(" GENERATION : ");
114 WriteCard(Generation, 3);
118 FOR N := 1 TO 2 * MaxInd + 3 DO
122 FOR Line := 1 TO MaxInd DO
124 FOR Column := 1 TO MaxInd DO
125 IF CellsState[PreviousNext][Line, Column] = 1 THEN
135 FOR N := 1 TO 2*MaxInd + 3 DO
149 IF Generation = NbOfGen THEN EXIT; END;