cell = cluster is new, set_neighbors, set_test_list, clear, get_x, get_y, set_generation, get_generation, set_alive, get_alive, born_neighbor, dead_neighbor, get_died, get_born, generate, affect_neighbors cells = sequence[cell] acell = array[cell] rep = record[ Alive_Last: bool, Alive_Now: bool, Generation: int, Neighbors: cells, Neigh_Count: int, Test_List: acell, X: int, Y: int ] New = proc (X: int, Y: int) returns (cvt) return (rep${ Alive_Last: false, Alive_Now: false, Generation: -1, Neighbors: _cvt[null, cells](nil), Neigh_Count: 0, Test_List: _cvt[null, acell](nil), X: X, Y: Y }) end New Set_Neighbors = proc (C: cvt, Ns: cells) C.Neighbors := Ns end Set_Neighbors Set_Test_List = proc (C: cvt, TL: acell); C.Test_List := TL end Set_Test_List; Clear = proc (C: cvt, G: int); C.Alive_Last := false C.Alive_Now := false C.Generation := G C.Neigh_Count := 0 end Clear; Get_X = proc (C: cvt) returns (int); return (C.X) end Get_X; Get_Y = proc (C: cvt) returns (int); return (C.Y) end Get_Y; Set_Generation = proc (C: cvt, G: int); C.Generation := G end Set_Generation; Get_Generation = proc (C: cvt) returns (int); return (C.Generation) end Get_Generation; Set_Alive = proc (C: cvt, Al: bool, Generation: int) returns (bool) C.Alive_Last := C.Alive_Now C.Alive_Now := Al Changed: bool := C.Alive_Last ~= Al if (Changed cand (C.Generation ~= Generation)) then acell$AddH(C.Test_List, up(C)) C.Generation := Generation end return (Changed) end Set_Alive Get_Alive = proc (C: cvt) returns (bool); return (C.Alive_Now) end Get_Alive; Born_Neighbor = proc (C: cvt) C.Neigh_Count := C.Neigh_Count + 1 end Born_Neighbor Dead_Neighbor = proc (C: cvt) C.Neigh_Count := C.Neigh_Count - 1 end Dead_Neighbor Get_Died = proc (C: cvt) returns (bool) return (C.Alive_Last cand ~ C.Alive_Now) end Get_Died Get_Born = proc (C: cvt) returns (bool) return (C.Alive_Now cand ~ C.Alive_Last) end Get_Born Generate = proc (C: cvt) returns (bool) C.Alive_Last := C.Alive_Now Count: int := C.Neigh_Count if ((Count < 2) cor (Count > 3)) then C.Alive_Now := false elseif (Count = 3) then C.Alive_Now := true end return (C.Alive_Now ~= C.Alive_Last) end Generate Affect_Neighbors = proc (C: cvt, Generation: int) if (C.Alive_Last) then if (~ C.Alive_Now) then for N: cell in cells$Elements(C.Neighbors) do NR: rep := down(N) NR.Neigh_Count := NR.Neigh_Count - 1 if (NR.Generation ~= Generation) then acell$AddH(NR.Test_List, N) NR.Generation := Generation end end if (C.Generation ~= Generation) then acell$AddH(C.Test_List, up(C)) C.Generation := Generation end end else if (C.Alive_Now) then for N: cell in cells$Elements(C.Neighbors) do NR: rep := down(N) NR.Neigh_Count := NR.Neigh_Count + 1 if (NR.Generation ~= Generation) then acell$AddH(NR.Test_List, N) NR.Generation := Generation end end if (C.Generation ~= Generation) then acell$AddH(C.Test_List, up(C)) C.Generation := Generation end end end end Affect_Neighbors end cell