Difference: Lab7Kenyon (1 vs. 27)

Revision 272018-05-10 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 144 to 145
 
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 12)
  • glider.png (10,10),(10,11),(10,12),(11,10),(12,11)
Changed:
<
<
  • f.png (10,11),(10,12),(11,10),(11,11),(12,11)

>
>
  • f.png (10,11),(10,12),(11,10),(11,11),(12,11)

    Solutions

 
META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1472070155" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1472070155" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"

Revision 262017-11-02 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 26 to 26
 

population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg

Problem

Changed:
<
<
The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 22 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.
>
>
The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 20 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.
 
  • We define each cell to have eight neighbor cells. The neighbors of a cell are the cells directly above, below, to the right, to the left, diagonally above to the right and left, and diagonally below to the right and left.
  • If an occupied cell has zero or one neighbors, it dies of loneliness. If an occupied cell has more than three neighbors, it dies of overcrowding.
Line: 35 to 35
 

Notes

Changed:
<
<
Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 22 rows and 80 columns to store the LIFE world’s successive generations. (char world[22][80];) Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.
>
>
Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 22 rows and 82 columns (the world is actually 20,80, see for why we add the extra two rows nd columns) to store the LIFE world’s successive generations. (char world[22][82];) Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.
  Also, it would be best if you used constants for the row number and column number, e.g.:
Line: 90 to 89
 
[r+1,c-1] [r+1,c] [r+1,c+1]
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[24][82], the first index r goes (top to bottom) from 0 to 23, or 24 cells, and the other index c goes (left to right) from 00 to 81. Start by making every element a space. Use these boundary cells while computing next generations, but never change or print the boundary cells. Then a boundary is really not an exception, it is just considered a dead cell with no chance for life. The boundary cells should never be displayed (they are for internal use only).
>
>
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[22][82], the first index r goes (top to bottom) from 0 to 21, or 22 total rows, and the other index c goes (left to right) from 00 to 81. Start by making every element a space. Use these boundary cells while computing next generations, but never change or print the boundary cells. Then a boundary is really not an exception, it is just considered a dead cell with no chance for life. The boundary cells should never be displayed (they are for internal use only).
  Example:
  0 ... c-1 c c+1 ... 81

Revision 252017-11-01 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 41 to 41
  %CODE{"c++"}% int const rows=22;
Changed:
<
<
int const columns = 8-0;
>
>
int const columns = 80;
  char world[rows][columns]; %ENDCODE%
Line: 58 to 58
  On startup have the program ask for coordinates of where to put *'s:
Changed:
<
<
Welcom to LIFE.  Enter x and y coordinates where 1<=x<=80 and 1<=y<=20.  Enter x of -1 to end.

>
>
Welcom to LIFE.  Enter row and column coordinates where 1<=row<=20 and 1<=column<=80.  Enter row of -1 to end.

 Enter coordinate 1: 10 10 coordinate 2: 10 11 coordinate 3: 10 12
Line: 104 to 104
 There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

Design - the following routines might be useful:

Changed:
<
<
  • int alive(char cell) - return a 1for alive('*'), and false otherwise. Used to check if a cell is alive.
>
>
  • int alive(char cell) - return a 1 for alive('*'), and 0 otherwise. Used to check if a cell is alive.
  • int neighborsAlive(car world [][82], int r, int c) - Return the number of neightbors of cell (r,c) that are alive. Simply add the Alive valuefor all the neigbors.
 
  • char nextGenCell(char world[][82], int row, int column) - 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. Note this changes the current world to a new world, so internally it will need to have some sort of temporary world to compute into, then it will need to copy that new world back over the current world.
  • You find a LOT of interesting patterns here: conwaylife

Revision 242017-10-31 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 112 to 113
  You should consider using classes to do the game. What I would suggest the following class:
World
Changed:
<
<
int board[22][82];
int tempBoard[22][82];
>
>
char board[22][82];
char tempBoard[22][82];
 
World() // Constructor
void inputBoard() // Ask user for positions of life
void display() // Display the board
void nextGen(); // move to the next generation
The functions described in the design above should be private helper functions inside the class. The main can be something like:

Revision 232017-10-26 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 57 to 57
 

Input

On startup have the program ask for coordinates of where to put *'s:

Changed:
<
<
Welcom to LIFE.  Enter x and y coordinates where 1<=x<=80 and 1<=y<=22.  Enter x of -1 to end.

>
>
Welcom to LIFE.  Enter x and y coordinates where 1<=x<=80 and 1<=y<=20.  Enter x of -1 to end.

 Enter coordinate 1: 10 10 coordinate 2: 10 11 coordinate 3: 10 12
Line: 113 to 113
 You should consider using classes to do the game. What I would suggest the following class:
World
int board[22][82];
int tempBoard[22][82];
Changed:
<
<
World() // Constructor
void input() // Ask user for positions of life
void display() // Display the board
void nextGen(); // move to the next generation
>
>
World() // Constructor
void inputBoard() // Ask user for positions of life
void display() // Display the board
void nextGen(); // move to the next generation
 The functions described in the design above should be private helper functions inside the class. The main can be something like: %CODE{"c++"}%
Line: 121 to 121
 int main() { char done;
Changed:
<
<
Board b; // create the board b.input(); // fill board with life;
>
>
World w; // create the board w.inputBoard(); // fill board with life;
  do {
Changed:
<
<
b.Display(); // show the board b.nextGen(); // go to next generation
>
>
w.Display(); // show the board w.nextGen(); // go to next generation
  cout << "Hit D if done:"; cin >> done; } while (done = "D");

Revision 222017-10-26 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 104 to 103
 There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

Design - the following routines might be useful:

Changed:
<
<
  • bool alive(char cell) - return a true for alive('*'), and false otherwise. Used to check if a cell is alive.
>
>
  • int alive(char cell) - return a 1for alive('*'), and false otherwise. Used to check if a cell is alive.
 
  • char nextGenCell(char world[][82], int row, int column) - 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. Note this changes the current world to a new world, so internally it will need to have some sort of temporary world to compute into, then it will need to copy that new world back over the current world.
  • You find a LOT of interesting patterns here: conwaylife
Line: 133 to 132
 }

%ENDCODE%

Changed:
<
<

>
>
 

Examples

There is a cool online version to play with here and here.

Revision 212017-10-25 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 104 to 104
 There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

Design - the following routines might be useful:

Changed:
<
<
  • int alive(char cell) - return a 1 for alive('*'), and 0 otherwise. Used to check if a cell is alive.
>
>
  • bool alive(char cell) - return a true for alive('*'), and false otherwise. Used to check if a cell is alive.
 
  • char nextGenCell(char world[][82], int row, int column) - 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. Note this changes the current world to a new world, so internally it will need to have some sort of temporary world to compute into, then it will need to copy that new world back over the current world.
  • You find a LOT of interesting patterns here: conwaylife
  • void copyWorld( char from[ ][82], char to[ ][82]) - Copy world from to world to.

Added:
>
>

Using Classes

You should consider using classes to do the game. What I would suggest the following class:

World
int board[22][82];
int tempBoard[22][82];
World() // Constructor
void input() // Ask user for positions of life
void display() // Display the board
void nextGen(); // move to the next generation
The functions described in the design above should be private helper functions inside the class. The main can be something like:
<-- SyntaxHighlightingPlugin -->
int main()
{
  char done;
  Board b;   // create the board
  b.input();   // fill board with life;
  do {
     b.Display();       // show the board
     b.nextGen();      // go to next generation
     cout << "Hit D if done:";
     cin >> done;
  } while (done != "D");
}
<-- end SyntaxHighlightingPlugin -->

Examples

  There is a cool online version to play with here and here.

Revision 202017-10-09 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Changed:
<
<

Due: April 6, 11:55pm

>
>

Due: November 2, 11:55pm

Moodle Link

1280px-Game_of_life_glider_gun.svg.png

Alternate Graphics Oriented Lab

If you wish, you can try this alternate lab involving Allegro Graphics. You will need to install Alegro on you own computer, Allegro is not on the lab computers.

 
Deleted:
<
<
Moodle Link
1280px-Game_of_life_glider_gun.svg.png

 

Instructions

  • Turn in the code (a cpp file), and the run outputs as requested below.

Revision 192017-04-07 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 32 to 32
 

Notes

Changed:
<
<
Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.
>
>
Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 22 rows and 80 columns to store the LIFE world’s successive generations. (char world[22][80];) Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.

Also, it would be best if you used constants for the row number and column number, e.g.:

<-- SyntaxHighlightingPlugin -->
int const rows=22;
    int const columns = 8-0;
    char world[rows][columns];
<-- end SyntaxHighlightingPlugin -->
 

Examples:

Step 1 Step 2 Step 3 Step 4
Line: 71 to 79
 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 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.
>
>
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. This would be defined by world[22][80]. 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.
 
Changed:
<
<
So, the life of a cell [x,y] depends on surrounding cells:
[x-1,y-1] [x,y-1] [x+1,y-1]
[x-1,y] [x, y] [x+1 ,y]
[x-1,y+1] [x,y+1] [x+1,y+1]
>
>
So, the life of a cell [r,c] where r is the row, and c is the column, depends on surrounding cells:
[r-1,c-1] [r-1,c] [r-1,c+1]
[r,c-1] [r, c] [r,c+1]
[r+1,c-1] [r+1,c] [r+1,c+1]
 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[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.
>
>
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 first index r goes (top to bottom) from 0 to 23, or 24 cells, and the other index c goes (left to right) from 00 to 81. Start by making every element a space. Use these boundary cells while computing next generations, but never change or print the boundary cells. Then a boundary is really not an exception, it is just considered a dead cell with no chance for life. The boundary cells should never be displayed (they are for internal use only).
  Example:
Changed:
<
<
  0 ... x-1 x x+1 ... 81
>
>
  0 ... c-1 c c+1 ... 81
 
0 space ... space space space ... space
... space ... ... ... ... ... space
Changed:
<
<
y-1 space ... [x-1,y-1] [x,y-1] [x+1,y-1] ... space
y space ... [x-1,y] [x, y] [x+1 ,y] ... space
y+1 space ... [x-1,y+1] [x,y+1] [x+1,y+1] ... space
>
>
r-1 space ... [r-1,c-1] [r-1,c] [r-1,c+1] ... space
r space ... [r,c-1] [r, c] [r,c+1] ... space
r+1 space ... [r+1,c-1] [r+1,c] [r+1,c+1] ... space
 
... space ... ... ... ... ... space
23 space ... space space space ... space
There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

Design - the following routines might be useful:

  • int alive(char cell) - return a 1 for alive('*'), and 0 otherwise. Used to check if a cell is alive.
Changed:
<
<
  • 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.
>
>
  • char nextGenCell(char world[][82], int row, int column) - 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. Note this changes the current world to a new world, so internally it will need to have some sort of temporary world to compute into, then it will need to copy that new world back over the current world.
  • You find a LOT of interesting patterns here: conwaylife
  • void copyWorld( char from[ ][82], char to[ ][82]) - Copy world from to world to.

Revision 182017-04-06 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 105 to 106
 Runs of the following cases. Run until they are either stable, or 10 steps, whichever come first. Turn in the results.

  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 12)
Changed:
<
<
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

>
>
  • glider.png (10,10),(10,11),(10,12),(11,10),(12,11)
  • f.png (10,11),(10,12),(11,10),(11,11),(12,11)

 
META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1472070155" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1472070155" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"

Revision 172017-01-17 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Changed:
<
<

Due: Nov 3, 11:55pm

>
>

Due: April 6, 11:55pm

 
Changed:
<
<
Moodle Link
1280px-Game_of_life_glider_gun.svg.png
>
>
Moodle Link
1280px-Game_of_life_glider_gun.svg.png
 

Instructions

Revision 162016-11-02 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 92 to 93
 There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

Design - the following routines might be useful:

Changed:
<
<
  • int alive(char cell) - return a 1 for life ('*'), and 0 otherwise. Use to check if a cell is alive.
>
>
  • int alive(char cell) - return a 1 for alive('*'), and 0 otherwise. Used to check if a cell is alive.
 
  • 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.
Changed:
<
<
  • void nextGenWorld(char current[ ][82]) - Given the current world, compute the next generation for the world.
>
>
  • void nextGenWorld(char current[ ][82]) - Given the current world, compute the next generation for the world. Note this changes the current world to a new world, so internally it will need to have some sort of temporary world to compute into, then it will need to copy that new world back over the current world.
 
  • You find a LOT of interesting patterns here: conwaylife
  • void copyWorld( char from[ ][82], char to[ ][82]) - Copy world from to world to.

Revision 152016-11-02 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 108 to 107
 
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 12)
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

Deleted:
<
<
  • 1280px-Game_of_life_glider_gun.svg.png:



 
META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1472070155" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1472070155" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"

Revision 142016-10-29 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Line: 104 to 105
  Runs of the following cases. Run until they are either stable, or 10 steps, whichever come first. Turn in the results.
Changed:
<
<
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 13)
>
>
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 12)
 
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

  • 1280px-Game_of_life_glider_gun.svg.png:



Revision 132016-10-24 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7 - Game of Life

Changed:
<
<

Due: Nov 1, 11:55pm

1280px-Game_of_life_glider_gun.svg.png
>
>

Due: Nov 3, 11:55pm

Moodle Link

1280px-Game_of_life_glider_gun.svg.png
 

Instructions

  • Turn in the code (a cpp file), and the run outputs as requested below.
  • Remember to format the code as described and the book and text, and to include comments including complete commetns at the beginning of the program.
Changed:
<
<

Grading

Feature %
Program correctness and completeness with respect to defination 70%
Code Format (Indenting, variable names) 10%
Code Comments 10%
Turning in runs of the cases below. 10%
>
>

Grading Table

Requirement Grading Comments Points Score
Easy to use user interface   10  
C++ code includes comments, with project information at top, pre and post conditions for each functions and other cmments as needed.   10  
The C++ code has good formatting, indentation, and organization.   10  
Good variable and function names, appropriate use of constants rather then literal numbers.   10  
Functions: Logic divided up into cohesive functions with a single purpose   20  
Runs: Run examples from trials with correct output   40  
Total   100  
 

Conway's Game of Life

population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg

Problem

Revision 122016-10-01 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Changed:
<
<

Lab 7

>
>

Lab 7 - Game of Life

 

Due: Nov 1, 11:55pm

1280px-Game_of_life_glider_gun.svg.png

Revision 112016-10-01 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7

Line: 32 to 32
 Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.

Examples:

Changed:
<
<
* * *

becomes

*
*
*
then becomes

* * *
>
>
Step 1 Step 2 Step 3 Step 4
Screen_Shot_2016-09-30_at_10.25.25_PM.png Screen_Shot_2016-09-30_at_10.28.44_PM.png Screen_Shot_2016-09-30_at_10.25.25_PM.png ???
 again, and so on.

What happens with this?

Changed:
<
<
* *
* *
* *
>
>
Screen_Shot_2016-09-30_at_10.33.02_PM.png
 

Input

On startup have the program ask for coordinates of where to put *'s:

Line: 96 to 92
 
  • int alive(char cell) - return a 1 for life ('*'), and 0 otherwise. Use to check if a cell is alive.
  • 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.
Changed:
<
<
  • 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
>
>
  • 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 and here.

 

Turn In:

Line: 106 to 103
 
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 13)
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
Changed:
<
<
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

  • 1280px-Game_of_life_glider_gun.svg.png:

  • population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg:
>
>
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

  • 1280px-Game_of_life_glider_gun.svg.png:



 
META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1472070155" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1472070155" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"
META FILEATTACHMENT attachment="f.png" attr="" comment="" date="1472070155" name="f.png" path="f.png" size="4173" user="JimSkon" version="1"
META FILEATTACHMENT attachment="1280px-Game_of_life_glider_gun.svg.png" attr="" comment="" date="1475261682" name="1280px-Game_of_life_glider_gun.svg.png" path="1280px-Game_of_life_glider_gun.svg.png" size="12241" user="JimSkon" version="1"
META FILEATTACHMENT attachment="population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg" attr="" comment="" date="1475261682" name="population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg" path="population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg" size="134541" user="JimSkon" version="1"
Added:
>
>
META FILEATTACHMENT attachment="Screen_Shot_2016-09-30_at_10.25.25_PM.png" attr="" comment="" date="1475288966" name="Screen_Shot_2016-09-30_at_10.25.25_PM.png" path="Screen_Shot_2016-09-30_at_10.25.25_PM.png" size="7294" user="JimSkon" version="1"
META FILEATTACHMENT attachment="Screen_Shot_2016-09-30_at_10.28.44_PM.png" attr="" comment="" date="1475288966" name="Screen_Shot_2016-09-30_at_10.28.44_PM.png" path="Screen_Shot_2016-09-30_at_10.28.44_PM.png" size="7782" user="JimSkon" version="1"
META FILEATTACHMENT attachment="Screen_Shot_2016-09-30_at_10.33.02_PM.png" attr="" comment="" date="1475289214" name="Screen_Shot_2016-09-30_at_10.33.02_PM.png" path="Screen_Shot_2016-09-30_at_10.33.02_PM.png" size="8635" user="JimSkon" version="1"
 
META TOPICMOVED by="JimSkon" date="1444937173" from="KenyonCpp.Lab6" to="KenyonCpp.Lab7Kenyon"

Revision 102016-09-30 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Added:
>
>
 

Lab 7

Due: Nov 1, 11:55pm

Added:
>
>
1280px-Game_of_life_glider_gun.svg.png

 

Instructions

Changed:
<
<
  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
>
>
  • Turn in the code (a cpp file), and the run outputs as requested below.
 
  • Remember to format the code as described and the book and text, and to include comments including complete commetns at the beginning of the program.

Grading

Line: 13 to 16
 
Code Format (Indenting, variable names) 10%
Code Comments 10%
Turning in runs of the cases below. 10%
Added:
>
>

Conway's Game of Life

population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg

 

Problem

The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 22 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.

Line: 103 to 108
 
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)
Added:
>
>
  • 1280px-Game_of_life_glider_gun.svg.png:

  • population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg:
 
META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1472070155" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1472070155" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"
META FILEATTACHMENT attachment="f.png" attr="" comment="" date="1472070155" name="f.png" path="f.png" size="4173" user="JimSkon" version="1"
Added:
>
>
META FILEATTACHMENT attachment="1280px-Game_of_life_glider_gun.svg.png" attr="" comment="" date="1475261682" name="1280px-Game_of_life_glider_gun.svg.png" path="1280px-Game_of_life_glider_gun.svg.png" size="12241" user="JimSkon" version="1"
META FILEATTACHMENT attachment="population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg" attr="" comment="" date="1475261682" name="population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg" path="population-dynamics-in-conways-game-of-life-and-its-variants-9-728.jpg" size="134541" user="JimSkon" version="1"
 
META TOPICMOVED by="JimSkon" date="1444937173" from="KenyonCpp.Lab6" to="KenyonCpp.Lab7Kenyon"

Revision 92016-08-24 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7

Changed:
<
<

Due: Nov 3, 11:55pm

>
>

Due: Nov 1, 11:55pm

 

Instructions

  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
Line: 15 to 15
 
Turning in runs of the cases below. 10%

Problem

Changed:
<
<
The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 22 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.
>
>
The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 22 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.
 
  • We define each cell to have eight neighbor cells. The neighbors of a cell are the cells directly above, below, to the right, to the left, diagonally above to the right and left, and diagonally below to the right and left.
  • If an occupied cell has zero or one neighbors, it dies of loneliness. If an occupied cell has more than three neighbors, it dies of overcrowding.
  • If an empty cell has exactly three occupied neighbor cells, there is a birth of a new cell to replace the empty cell.
Changed:
<
<
  • Births and deaths are instantaneous and occur at the changes of generation. A cell dying for whatever reason may help cause birth, but a newborn cell cannot resurrect a cell that is dying, nor will a cell’s death prevent the death of another, say, by reducing the local population.
>
>
  • Births and deaths are instantaneous and occur at the changes of generation. A cell dying for whatever reason may help cause birth, but a newborn cell cannot resurrect a cell that is dying, nor will a cell’s death prevent the death of another, say, by reducing the local population.
 

Notes

Changed:
<
<
Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.
>
>
Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.
 

Examples:

Changed:
<
<

* * *

>
>
* * *
  becomes
Changed:
<
<
*
*
*
>
>
*
*
*
then becomes
 
Changed:
<
<
then becomes

* * *

>
>
* * *
  again, and so on.

What happens with this?

Changed:
<
<
* *
* *
* *
>
>
* *
* *
* *
 

Input

On startup have the program ask for coordinates of where to put *'s:

Line: 101 to 99
  Runs of the following cases. Run until they are either stable, or 10 steps, whichever come first. Turn in the results.
Changed:
<
<
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 13)
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1446390879" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1446390899" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"
META FILEATTACHMENT attachment="f.png" attr="" comment="" date="1446390936" name="f.png" path="f.png" size="4173" user="JimSkon" version="1"
>
>
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 13)
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)

META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1472070155" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1472070155" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"
META FILEATTACHMENT attachment="f.png" attr="" comment="" date="1472070155" name="f.png" path="f.png" size="4173" user="JimSkon" version="1"
 
META TOPICMOVED by="JimSkon" date="1444937173" from="KenyonCpp.Lab6" to="KenyonCpp.Lab7Kenyon"

Revision 82015-11-05 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7

Due: Nov 3, 11:55pm

Line: 101 to 101
  Runs of the following cases. Run until they are either stable, or 10 steps, whichever come first. Turn in the results.
Changed:
<
<
  • boat.png
  • glider.png
  • f.png
>
>
  • boat.png (10,10), (11, 10), (10, 11), (12, 11), (11, 13)
  • glider.png (10,10),(11,10),(12,10),(10,11),(11,12)
  • f.png (10,11),(11,10),(12,10),(11,11),(11,12)
 
META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1446390879" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1446390899" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"

Revision 72015-11-01 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7

Due: Nov 3, 11:55pm

Line: 12 to 12
 
Program correctness and completeness with respect to defination 70%
Code Format (Indenting, variable names) 10%
Code Comments 10%
Changed:
<
<
Turning in complete run of every function at least twice with difference values. 10%
>
>
Turning in runs of the cases below. 10%
 

Problem

The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 22 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.

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 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.
>
>
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: 94 to 94
 
  • 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
Changed:
<
<
  • void copyWorld( char from[ ][82], char to[ ][82]) - Copy world from to world to.
>
>
  • void copyWorld( char from[ ][82], char to[ ][82]) - Copy world from to world to.
 There is a cool online version to play with here
Added:
>
>

Turn In:

Runs of the following cases. Run until they are either stable, or 10 steps, whichever come first. Turn in the results.

  • boat.png
  • glider.png
  • f.png

META FILEATTACHMENT attachment="boat.png" attr="" comment="" date="1446390879" name="boat.png" path="boat.png" size="4181" user="JimSkon" version="1"
META FILEATTACHMENT attachment="glider.png" attr="" comment="" date="1446390899" name="glider.png" path="glider.png" size="4182" user="JimSkon" version="1"
META FILEATTACHMENT attachment="f.png" attr="" comment="" date="1446390936" name="f.png" path="f.png" size="4173" user="JimSkon" version="1"
 
META TOPICMOVED by="JimSkon" date="1444937173" from="KenyonCpp.Lab6" to="KenyonCpp.Lab7Kenyon"

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:
  0 ... x-1 x x+1 ... 81
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"

Revision 52015-10-27 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7

Changed:
<
<

Due: Oct 30, 11:55pm

>
>

Due: Nov 3, 11:55pm

 

Instructions

  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
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 '*' is the cell at this location should be alive in the next generation. Otherwise return a space.
>
>
  • 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.
Changed:
<
<
  • void copyWorld(char from[ ][80], char to[ ][80]) - Copy world from to world to.
>
>
  • void copyWorld( char from[ ][80], char to[ ][80]) - Copy world from to world to.
 You find a LOT of interesting patterns here: conwaylife

There is a cool online version to play with here

Revision 42015-10-23 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 7

Due: Oct 30, 11:55pm

Line: 88 to 88
 
23 space ... space space space ... space

There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

Added:
>
>

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.
  • char nextGenCell(int x, int y) - return a '*' is 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

Revision 32015-10-15 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Changed:
<
<

Lab 6

Due: Oct 22, 11:55pm

>
>

Lab 7

Due: Oct 30, 11:55pm

 

Instructions

  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
Line: 92 to 92
 You find a LOT of interesting patterns here: conwaylife

There is a cool online version to play with here

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

Revision 22015-10-06 - JimSkon

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Lab 6

Changed:
<
<

Due: Oct 15, 11:55pm

>
>

Due: Oct 22, 11:55pm

 

Instructions

  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
Line: 21 to 21
 
  • If an occupied cell has zero or one neighbors, it dies of loneliness. If an occupied cell has more than three neighbors, it dies of overcrowding.
  • If an empty cell has exactly three occupied neighbor cells, there is a birth of a new cell to replace the empty cell.
  • Births and deaths are instantaneous and occur at the changes of generation. A cell dying for whatever reason may help cause birth, but a newborn cell cannot resurrect a cell that is dying, nor will a cell’s death prevent the death of another, say, by reducing the local population.
Changed:
<
<
Notes: Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.
>
>

Notes

Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank (or space) to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.

 

Examples:

Changed:
<
<
***
>
>

* * *

  becomes
Changed:
<
<
 *
 *
 *
>
>
*
*
*
  then becomes
Changed:
<
<
***
>
>

* * *

  again, and so on.
Added:
>
>
What happens with this?
* *
* *
* *
 

Input

On startup have the program ask for coordinates of where to put *'s:

Line: 54 to 57
  * * *
Changed:
<
<
Enter to 'Y' continue:Ne!
>
>
Enter to 'Y' continue:N!
 Bye!
Line: 63 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, an 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 size, and it will compute each cells from world into newWorld. It will then copy newWorld back into world.
>
>
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.
  So, the life of a cell [x,y] depends on surrounding cells:
[x-1,y-1] [x,y-1] [x+1,y-1]
[x-1,y] [x, y] [x+1 ,y]
[x-1,y+1] [x,y+1] [x+1,y+1]
Changed:
<
<
One trick is dealing with the boundary conditions, that is when something is on the edge. A neat trick is to make the array one bigger in every direction, and then use this a 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 zero, and never change or print these boundary cells. Then a boundary is really not an exception, it is just considered a dead cell.
>
>
Given each cell, you will write a to examine the surrounding cells to determine what happens to that 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[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.

Example:

  0 ... x-1 x x+1 ... 81
0 space ... space space space ... space
... space ... ... ... ... ... space
y-1 space ... [x-1,y-1] [x,y-1] [x+1,y-1] ... space
y space ... [x-1,y] [x, y] [x+1 ,y] ... space
y+1 space ... [x-1,y+1] [x,y+1] [x+1,y+1] ... space
... space ... ... ... ... ... space
23 space ... space space space ... space

There should also be a function display that accepts the array world and displays the array on the screen. Is should merely display the contents of each row right to left.

You find a LOT of interesting patterns here: conwaylife

 
Changed:
<
<
There should also be a function display that accepts the array world and displays the array on
>
>
There is a cool online version to play with here

Revision 12015-10-05 - JimSkon

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WebHome"

Lab 6

Due: Oct 15, 11:55pm

Instructions

  • Turn in the code (a cpp file or ideone.com link), and the run outputs as requested below.
  • Remember to format the code as described and the book and text, and to include comments including complete commetns at the beginning of the program.

Grading

Feature %
Program correctness and completeness with respect to defination 70%
Code Format (Indenting, variable names) 10%
Code Comments 10%
Turning in complete run of every function at least twice with difference values. 10%

Problem

The mathematician John Horton Conway invented the “Game of Life.” Though not a “game” in any traditional sense, it provides interesting behav- ior that is specified with only a few rules. This Project asks you to write a program that allows you to specify an initial configuration. The program follows the rules of LIFE to show the continuing behavior of the configuration. LIFE is an organism that lives in a discrete, two-dimensional world. While this world is actually unlimited, we don’t have that luxury, so we restrict the array to 80 characters wide by 22 character positions high. If you have access to a larger screen, by all means use it. This world is an array with each cell capable of holding one LIFE cell. Generations mark the passing of time. Each generation brings births and deaths to the LIFE community. The births and deaths follow the following set of rules.

  • We define each cell to have eight neighbor cells. The neighbors of a cell are the cells directly above, below, to the right, to the left, diagonally above to the right and left, and diagonally below to the right and left.
  • If an occupied cell has zero or one neighbors, it dies of loneliness. If an occupied cell has more than three neighbors, it dies of overcrowding.
  • If an empty cell has exactly three occupied neighbor cells, there is a birth of a new cell to replace the empty cell.
  • Births and deaths are instantaneous and occur at the changes of generation. A cell dying for whatever reason may help cause birth, but a newborn cell cannot resurrect a cell that is dying, nor will a cell’s death prevent the death of another, say, by reducing the local population.
Notes: Some configurations grow from relatively small starting configurations. Others move across the region. It is recommended that for text output you use a rectangular array of char with 80 columns and 22 rows to store the LIFE world’s successive generations. Use an asterisk * to indicate a living cell, and use a blank to indicate an empty (or dead) cell. If you have a screen with more rows than that, by all means make use of the whole screen.

Examples:

***

becomes

 *
 *
 *

then becomes

***

again, and so on.

Input

On startup have the program ask for coordinates of where to put *'s:

Welcom to LIFE.  Enter x and y coordinates where 1<=x<=80 and 1<=y<=22.  Enter x of -1 to end.
Enter coordinate 1: 10 10
coordinate 2: 10 11
coordinate 3: 10 12
coordinate 4: -1

        * * *
Enter to 'Y' continue:Y
           *
           *
           *
Enter to 'Y' continue:Y

        * * *

Enter to 'Y' continue:Ne!
Bye!

Suggestions

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:

Define a void function named generation that takes the array we call world, an 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 size, and it will compute each cells from world into newWorld. It will then copy newWorld back into world.

So, the life of a cell [x,y] depends on surrounding cells:

[x-1,y-1] [x,y-1] [x+1,y-1]
[x-1,y] [x, y] [x+1 ,y]
[x-1,y+1] [x,y+1] [x+1,y+1]

One trick is dealing with the boundary conditions, that is when something is on the edge. A neat trick is to make the array one bigger in every direction, and then use this a 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 zero, and never change or print these boundary cells. Then a boundary is really not an exception, it is just considered a dead cell.

There should also be a function display that accepts the array world and displays the array on

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 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