-- Assignment 1. -- Eugene Burke -- Oct 23, 1996 -- -- FILE: -- life_game.ads -- uses life_game.adb, is used by life1.adb -- PURPOSE: -- Implement the game of life, an example of a finite automaton -- Specification for the Life Board package Life_Game is MaxRow : constant INTEGER := 20; MaxCol : constant INTEGER := 40; subtype ROW is INTEGER range 1..MaxRow; subtype COL is INTEGER range 1..MaxCol; type STATUS is (Alive,Dead); type GRID is array (ROW,COL) of STATUS; function Neighbor_Count (I : ROW; J : COL; Map : GRID) return INTEGER; procedure Initialize (Map : out GRID); procedure Write_Map (Map : in GRID); function Enquire return BOOLEAN; end Life_Game; -- COMMENTS -- Is there any reason that ROW and COLUMN must be subranges? Why can't -- they be an integer types that is declared in the package? -- My major suggestions for reusability is to make the package -- generic on the size of the GRID or use unconstrained array types - -- See below.. -- I am not suggesting that you nest the package within the procedure; -- it is more reusable if you program it as a separate unit. --with TEXT_IO; --procedure FirstSuggestion is -- generic -- MAX_ROWS: POSITIVE; -- MAX_COLUMNS: POSITIVE; -- package GRID is -- type GRID_BOX is array (1.. MAX_ROWS,1..MAX_COLUMNS) of BOOLEAN; -- procedure Initialize (Life: out GRID_BOX); -- end GRID; -- package body GRID is -- procedure Initialize (Life: out GRID_BOX) is -- begin -- for I in Life'Range loop -- for J in Life'Range loop -- Life (I, J) := TRUE; -- end loop; -- end loop; -- end Initialize; -- end GRID; --begin -- declare -- package MyLife is new Grid (MAX_ROWS => 5, -- MAX_COLUMNS => 10); -- T: MyLife.GRID_BOX; -- begin -- MyLife.Initialize(T); -- end; --end FirstSuggestion; --with TEXT_IO; --procedure SecondSuggestion is --package LIFE is --type BUFFER is array (POSITIVE range <>, POSITIVE range <>) of Boolean; -- procedure Initialize (T: out BUFFER); -- procedure OutPut (T: in BUFFER); --end; --package body LIFE is -- procedure Initialize (T: out BUFFER) is -- begin -- for I in T'RANGE loop -- for J in T'RANGE loop -- T(I,J) := TRUE; -- end loop; -- end loop; -- end; -- procedure OutPut (T: in BUFFER) is -- begin -- for I in T'Range loop -- for J in T'Range loop -- if (T(I,J)) then -- TEXT_IO.Put ('x' ); -- else -- TEXT_IO.Put (' '); -- end if; -- end loop; -- TEXT_IO.New_Line; -- end loop; -- end; --end LIFE; --begin -- declare -- T: LIFE.BUFFER (1..10,1..15); -- begin -- Life.Initialize (T); -- Life.OutPut(T); -- end; --end Second Suggestion;