ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 08 May 2017 My Price 9.00

Compute one step of Conway's Game of Life

Compute one step of Conway's Game of Life. The rules and history of the Game of Life can be found here.

Summary

The universe of the Game of Life is an infinite two-dimensional orthogonal grid of square cells, each of which is in one of two possible states, alive or dead. Every cell interacts with its eight neighbours, which are the cells that are horizontally, vertically, or diagonally adjacent. At each step in time, the following transitions occur:

  1. Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  2. Any live cell with two or three live neighbours lives on to the next generation.
  3. Any live cell with more than three live neighbours dies, as if by overcrowding.
  4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.

The initial pattern constitutes the seed of the system. The first generation is created by applying the above rules simultaneously to every cell in the seed - births and deaths occur simultaneously, and the discrete moment at which this happens is sometimes called a tick (in other words, each generation is a pure function of the preceding one). The rules continue to be applied repeatedly to create further generations.

Requirements

  1. Create and add a single C source file called "t3.c". 
  2. "t3.c" should contain the function life() and agree exactly with this function declaration:
      void life( uint8_t array[], 
         unsigned int cols, 
         unsigned int rows );
          
  3. Edge pixels wrap around left-right and top-bottom, creating a torus topology rather than the infinite grid of Conway's original. 
  4. 'Off' pixels have the value 0. 
  5. All non-zero values are considered 'On' pixels. 
  6. New 'on' pixels are set to 255. 
  7. New 'off' pixels are set to 0.

 

Examples

Your function must correctly compute a single step of Life, so that it can be used in a loop to create a Life simulation as shown here.

  int glider[][2] = { {1,0}, {2,1}, {0,2}, {1,2}, {2,2} };   

  for( int i=0; i<5; i++ )
    set_pixel( img, w, h, glider[i][0], glider[i][1], 255 );
  
  for( int i=0; i<32; i++ )
    { 
      draw_image_grey( img, w, h );
      life( img, w, h );
    } 
  draw_image_grey( img, w, h );

Answers

(11)
Status NEW Posted 08 May 2017 03:05 AM My Price 9.00

-----------

Not Rated(0)