# Difference: Lab7Kenyon (5 vs. 6)

#### Revision 62015-10-27 - JimSkon

Line: 1 to 1

 META TOPICPARENT name="WebHome"

# Lab 7

### Due: Nov 3, 11:55pm

Line: 66 to 66
Look for stable configurations. That is, look for communities that repeat patterns continually. The number of configurations in the repetition is called the period. There are configurations that are fixed, which continue without change. A possible project is to find such configurations.

### Hints:

Changed:
<
<
Define a void function named generation that takes the array we call world, a 80-column by 22-row array of char, which contains the initial configuration. The function scans the array and modifies the cells, marking the cells with births and deaths in accord with the rules listed earlier. This involves examining each cell in turn, either killing the cell, letting it live, or, if the cell is empty, deciding whether a cell should be born. Generation will need to have a local array ( newWorld) of the same type and size, and it will compute the next generation status of each cell from world into newWorld. Generation will then copy newWorld back into world and return.
>
>
Define a void function named nextGenWorld that takes the array we call world, a 80-column by 22-row array of char, which contains the initial configuration. The function scans the array and modifies the cells, marking the cells with births and deaths in accord with the rules listed earlier. This involves examining each cell in turn, either killing the cell, letting it live, or, if the cell is empty, deciding whether a cell should be born. nextGenWorld will need to have a local array ( newWorld) of the same type and size, and it will compute the next generation status of each cell from world into newWorld.nextGenWorld will then copy newWorld back into world and return.
So, the life of a cell [x,y] depends on surrounding cells:
 [x-1,y-1] [x,y-1] [x+1,y-1]
Line: 75 to 75
Given each cell, you will write a to examine the surrounding cells to determine what happens to that cell.
Changed:
<
<
One trick is dealing with the boundary conditions, that is when something is on the edge of the array. A neat trick is to make the array one bigger in every direction, and then use this as boundary space. So if we make world[23][81], the x direction goes from 0 to 81, or 82 cells. Make 0 and 81 always be a space, and never change or print these boundary cells. Then a boundary is really not an exception, it is just considered a dead cell.
>
>
One trick is dealing with the boundary conditions, that is when something is on the edge of the array. A neat trick is to make the array one bigger in every direction, and then use this as boundary space. So if we make world[24][82], the x direction goes from 0 to 81, or 82 cells. Make 0 and 81 always be a space, and never change or print these boundary cells. Then a boundary is really not an exception, it is just considered a dead cell.
Example:
Line: 91 to 91

### Design - the following routines might be useful:

• int alive(char cell) - return a 1 for life ('*'), and 0 otherwise. Use to check if a cell is alive.
Changed:
<
<
• char nextGenCell(int x, int y) - return a '*' if the cell at this location should be alive in the next generation. Otherwise return a space.
• void nextGenWorld(char current[ ][80], char next[ ][80]) - Given the current world, compute the next generation for the world.
• void copyWorld( char from[ ][80], char to[ ][80]) - Copy world from to world to.
You find a LOT of interesting patterns here: conwaylife
>
>
• char nextGenCell(char world[][82], int x, int y) - return a '*' if the cell at this location should be alive in the next generation. Otherwise return a space.
• void nextGenWorld(char current[ ][82]) - Given the current world, compute the next generation for the world.
• You find a LOT of interesting patterns here: conwaylife
• void copyWorld( char from[ ][82], char to[ ][82]) - Copy world from to world to.
There is a cool online version to play with here

 META TOPICMOVED by="JimSkon" date="1444937173" from="KenyonCpp.Lab6" to="KenyonCpp.Lab7Kenyon"

Copyright © 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback