PROCEDURE Neighbours (l, c: WorldIndex) : NeighbourCount;
(* Zaehlt die Anzahl der belegten Felder in
der Nachbarschaft von world[l, c]
*)
VAR
neighbours: NeighbourCount;
i, j: [-1..1];
nl, nc: WorldIndex;
BEGIN
neighbours := 0;
FOR i := -1 TO 1 DO
FOR j := -1 TO 1 DO
IF (i # 0) OR (j # 0) THEN
(* eigenes Feld ignorieren *)
IF border THEN
nl := l + i; nc := c + j;
ELSE (* Torus *)
nl := (noflines + l + i) MOD noflines;
nc := (nofcolumns + c + j) MOD nofcolumns;
END;
IF world[nl, nc] # space THEN
INC(neighbours);
END;
END;
END;
END;
RETURN neighbours
END Neighbours;
|