Die nächste Generation II

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

GameOfLife.m2
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;

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1999 Andreas Borchert, in HTML konvertiert am 04.02.1999