Cellular Automaton
For this activity,
you will need to complete
a program called cellular.c
.
Download
cellular.c
,
or copy it into your current directory on a CSE system by running
$ cp /web/cs1511/17s2/week05/files/cellular.c .
This program is a simple life simulator.
It is an example of a 1-dimensional cellular automaton.
In this simulation,
the world is represented by an array.
Each element of the array
is a single cell
which can contain up to 1 creature.
If it contains a creature,
we call it ALIVE
.
If it contains no creatures,
we call it DEAD
.
The simulation will advance between generations. Every time it moves to a new generation each cell may
- become
ALIVE
, - become
DEAD
, - stay
ALIVE
, or - stay
DEAD
.
Your task is to complete the function nextGeneration
,
which takes in an array of the current generation
and the next generation,
and sets all of the values of the cells in the next generation.
Currently, this function makes every generation the same.
The rules for what happens on each generation are:
- If a cell in the current generation is
DEAD
, then in the next generation- it becomes
ALIVE
if it is next to one or twoALIVE
cells, otherwise - it remains
DEAD
.
- it becomes
- If a cell in the current generation is
ALIVE
, then in the next generation- it remains
ALIVE
if it is next to exactly oneALIVE
cell, otherwise - it becomes
DEAD
.
- it remains
- The first cell in the array and the last cell in the array are next to each other.
There are no tests for this activity, so feel free to have some fun. Try and see what happens to the output if you change the rules.
To run Styl-o-matic:
$ 1511 stylomatic cellular.c Looks good!
You’ll get advice if you need to make changes to your code.
Submit your work with the give command, like so:
$ give cs1511 wk05_cellular
Or, if you are working from home, upload the relevant file(s) to the wk05_cellular activity on Give Online.