MODULE cellular_automaton;
CONST n = 79; (* number of elements *)
m = (n+1) DIV 2; (* number of loops := middle *)
CONFIGURATION list [1..n];
CONNECTION left: list[i] <-> list[i-1] :right;
VAR i : INTEGER;
val: list OF BOOLEAN;
c : list OF ARRAY BOOLEAN OF CHAR;
(* = ARRAY[FALSE..TRUE] OF CHAR *)
BEGIN
val := ID(list) = m; (* Init *)
c[FALSE]:= " ";
c[TRUE] := "X";
FOR i := 1 TO m DO
Write(c[val]); WriteLn;<
val := MOVE.left(val) <> MOVE.right(val);
END;
END cellular_automaton.
The CONFIGURATION and CONNECTION declarations define a doubly linked list of
PEs. For screen output of the current state of all PEs, every boolean state is
converted to a symbol of type CHAR. The complete character vector is then
written to the screen sequentially by a vector valued Write operation. The
initialization of the main program assigns the value TRUE only to the middle PE
with number (n+1 DIV 2); all other PEs receive the value FALSE. Finally, there
is a scalar loop which prints the current state and calculates the next cell
state in each pass, using data exchange with the left and right neighbors.Figure 13 shows the states of this cellular automaton, in which time progresses from top to bottom.
Figure 13 Output of cellular automaton