Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MatLab function that satisifes ALL of the following Extra Credit Functio

ID: 3797550 • Letter: W

Question

Write a MatLab function that satisifes ALL of the following

Extra Credit Function Name: conway Inputs 1. (logical An NxN start state for the cells in the Game of Life outputs 1. (logical) The final state in the Game of Life Function Description: Conway's Game of Life is a simulation of cell reproduction and population. It is an automatic process, meaning that it is completely derived from an input state and a set of rules that will drive the simulation forward. There are a lot of cool patterns that the game can produce, and not all of them end, but some of them over time w reach a point where it settles and oscillates between two states forever. For this homework problem, your job is to perform Conway's Game of Life on an input array and give the resting states of the game. The input to the function is a logical array where trues represent living cells in the system. At every tick of the game, the "board" is updated by the following rules: 1. Any live cell with fewer than two live neighbors dies, as by underpopulation 2. Any live cell with two or three live neighbors lives on to the next generation 3. Any live cell with more than three live neighbors dies, as by overpopulation 4. Any dead cell with exactly three live neighbors comes back to life, as by reproduction After an undefined time of iterating and updating the game boards, the boards will eventually oscillate between two final states. The output array is the combination of the two final states a logical combination of cells in each of the two final states. That is, if there is a live cell in either of the two final states at an index, it should appear at the index in the output array Notes: The board will be square As stated earlier, not every possible input state will end in an two oscillating states, but you can assume that any input that we give will end in two oscillating states. The board wraps around-for example, any cell in the first column has a neighbor on its left that is the same row in the last column. The same goes for the top row/bottom row and any combination of the two The Cells are 8 connected, which means that neighbors are not only horizontally/vertically adjacent but also diagonally adjacent. Every cell on the board should be updated "simultaneously" such that in the middle of one update changing one cell will not affect how any of the other cells update ttps://en.wikipedia.org/wiki/Conway's Game of Life

Explanation / Answer

with Ada.Text_IO; use Ada.Text_IO;

procedure Life is

   type Cell is (O, X); -- Two states of a cell

      -- Computation of neighborhood

   function "+" (L, R : Cell) return Integer is

   begin

      case L is

         when O =>

            case R is

               when O => return 0;

               when X => return 1;

            end case;

         when X =>

            case R is

               when O => return 1;

               when X => return 2;

            end case;

      end case;

   end "+";

   function "+" (L : Integer; R : Cell) return Integer is

   begin

      case R is

         when O => return L;

         when X => return L + 1;

      end case;

   end "+";

      -- A colony of cells. The borders are dire and unhabited

   type Petri_Dish is array (Positive range <>, Positive range <>) of Cell;

   procedure Step (Culture : in out Petri_Dish) is

      Above : array (Culture'Range (2)) of Cell := (others => O);

      Left : Cell;

      This : Cell;

   begin

      for I in Culture'First (1) + 1 .. Culture'Last (1) - 1 loop

         Left := O;

         for J in Culture'First (2) + 1 .. Culture'Last (2) - 1 loop

            case Above        (J-1) + Above        (J) + Above        (J+1) +

                 Left                                  + Culture (I,   J+1) +

                 Culture (I+1, J-1) + Culture (I+1, J) + Culture (I+1, J+1) is

               when 2 =>     -- Survives if alive

                  This := Culture (I, J);

               when 3 =>     -- Survives or else multiplies

                  This := X;

               when others => -- Dies

                  This := O;

            end case;

            Above (J-1) := Left;

            Left        := Culture (I, J);

            Culture (I, J) := This;

         end loop;

         Above (Above'Last - 1) := Left;

      end loop;

   end Step;

   procedure Put (Culture : Petri_Dish) is

   begin

      for I in Culture'Range loop

         for J in Culture'Range loop

            case Culture (I, J) is

               when O => Put (' ');

               when X => Put ('#');

            end case;

         end loop;

         New_Line;

      end loop;

   end Put;

   Blinker : Petri_Dish := (2..4 =>(O,O,X,O,O), 1|5 =>(O,O,O,O,O));

   Glider : Petri_Dish :=

             ( (O,O,O,O,O,O,O,O,O,O,O),

                (O,O,X,O,O,O,O,O,O,O,O),

                (O,O,O,X,O,O,O,O,O,O,O),

                (O,X,X,X,O,O,O,O,O,O,O),

                (O,O,O,O,O,O,O,O,O,O,O),

               (O,O,O,O,O,O,O,O,O,O,O)

             );

begin

   for Generation in 1..3 loop

      Put_Line ("Blinker" & Integer'Image (Generation));

      Put (Blinker);

      Step (Blinker);

   end loop;

   for Generation in 1..5 loop

      Put_Line ("Glider" & Integer'Image (Generation));

      Put (Glider);

      Step (Glider);

   end loop;

end Life;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote