Question
Write a program that consists of a 10 by 10 game board, with 10 generations.


Project The Game of Life The life game consists of a board with size of NxN cells and cells are occupied by creatures. Each cell can have at most one creature. The surrounding cells are called the neighbors of this cell. Each game state is called generation. The game progresses from one generation to the next according to the following rules: A creature that has more than 3 neighbors- dies of crowding. Its cell will be empty in the next generation. 1. 2. A creature that has less than 2 neighbors dies of loneliness. 3. If an empty cell that has exactly 3 neighbors, a new creature is born in that cell Write a program that consists of a 10 x 10 cell grid board. The program will prompt for the initial state of the world and the number of generations to be played. After each generation the program will update the state of the board and will display the updated board. The program can stop if it has reached the number of required generations or if no further changes occur (i.e, no more creatures alive or it has reached a steady or repeating pattern)
media%2Feeb%2Feeb2ed1f-c56e-4d3b-a25a-7e
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<string>

using namespace std;

int main(){

   int n,m;
   char ch;
   string s1;
   cout << "Enter number of stages:";
   cin >> m;
   char **data = new char *[10];
   for (int i = 0; i<10; i++)
       data[i] = new char[10];
   char **data1 = new char *[10];
   for (int i = 0; i<10; i++)
       data1[i] = new char[10];
   cout << "Enter " << 10 << " rows as strings\n";
   for (int i = 0; i<10; i++){
      cin >> s1;
      for (int j = 0; j<10; j++){
         data[i][j] = s1[j];
      }
   }
   int count = 0;
   for (int i = 0; i<10; i++){
          for (int j = 0; j<10; j++){
              cout << data[i][j] << " ";
          }
          cout << endl;
   }  
   n = 10;
   while(count <= m){

      for (int i = 0; i<10; i++){
          for (int j = 0; j<10; j++){
              int count1 = 0;
              if ( i-1 >= 0 && i-1 < n && j>=0 && j < n && data[i-1][j] == 'X'){
                 count1++;
              }
              if ( i-1 >= 0 && i-1 < n && j+1>=0 && j+1 < n && data[i-1][j+1] == 'X'){
                 count1++;
              }
              if ( i >= 0 && i < n && j+1>=0 && j+1 < n && data[i][j+1] == 'X'){
                 count1++;
              }
              if ( i+1 >= 0 && i+1 < n && j+1>=0 && j+1 < n && data[i+1][j+1] == 'X'){
                 count1++;
              }
              if ( i+1 >= 0 && i+1 < n && j>=0 && j < n && data[i+1][j] == 'X'){
                 count1++;
              }
              if ( i+1 >= 0 && i+1 < n && j-1>=0 && j-1 < n && data[i+1][j-1] == 'X'){
                 count1++;
              }
              if ( i >= 0 && i < n && j-1>=0 && j-1 < n && data[i][j-1] == 'X'){
                 count1++;
              }
              if ( i-1 >= 0 && i-1 < n && j-1>=0 && j-1 < n && data[i-1][j-1] == 'X'){
                 count1++;
              }
              if (count1 == 3 || count1 == 2)
                 data1[i][j] = data[i][j];
              if (count1 > 3 || count1 < 2)
                 data1[i][j] = '-';
              if (count1 == 3)
                 data1[i][j] = 'X';
          }
          cout << endl;
      }     
      for (int i = 0; i<n; i++){
          for (int j = 0; j<n; j++){
              data[i][j] = data1[i][j];
              cout << data[i][j] << " ";
          }
          cout << endl;
      }
      count++;
   }
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a program that consists of a 10 by 10 game board, with 10 generations. Project...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please use C++, thank you! The life game consists of a board with size of NxN cells and cells are occupied by creatures. Each cell can have at most one creature. The surrounding cells are called the...

    Please use C++, thank you! The life game consists of a board with size of NxN cells and cells are occupied by creatures. Each cell can have at most one creature. The surrounding cells are called the neighbors of this cell Each game state is called "generation". The game progresses from one generation to the next according to the following rules: A creature that has more than 3 neighbors- dies of crowding. Its cell will be empty in the next...

  • Write this Game of Life program in Java. The Game of Life is a well-known mathematical...

    Write this Game of Life program in Java. The Game of Life is a well-known mathematical game that gives rise to amazingly complex behavior, although it can be specified by a few simple rules. Here are the rules. The game is played on a rectangular board. Each square can be either empty or occupied. At the beginning, you can specify empty and occupied cells using 1's and 0's; then the game runs automatically. In each generation, the next generation is...

  • Write this Game of Life program in Java. The Game of Life is a well-known mathematical...

    Write this Game of Life program in Java. The Game of Life is a well-known mathematical game that gives rise to amazingly complex behavior, although it can be specified by a few simple rules. Here are the rules. The game is played on a rectangular board. Each square can be either empty or occupied. At the beginning, you can specify empty and occupied cells using 1's and 0's; then the game runs automatically. In each generation, the next generation is...

  • I have a question about my assignment. Could you please make program and give me some...

    I have a question about my assignment. Could you please make program and give me some explanation of codes? I need c++ codes. Conway's Game of Life is a game invented by mathematician John Conway in 1970. The rules are as follows: Each cell lives in a cell in a square (make it 10x10) grid. A cell can either be dead or alive. Before you start the game, you need to provide an initial state. You can do this by...

  • I have a question about my assignment. Could you please make program and give me some...

    I have a question about my assignment. Could you please make program and give me some explanation of codes? Conway's Game of Life is a game invented by mathematician John Conway in 1970. The rules are as follows: Each cell lives in a cell in a square (make it 10x10) grid. A cell can either be dead or alive. Before you start the game, you need to provide an initial state. You can do this by randomly setting 20 of...

  • Option 2: Conwav's Game of Life Your task is to write a program that plays Conway's...

    Option 2: Conwav's Game of Life Your task is to write a program that plays Conway's Game of Life (for details and ex amples, see https://en.vikipedia.org/wiki/Convay's.Game of Life). The basic gam ts played on each generation, each cell changes according to the following instructions: nal grid of square cells, each of which is either alive or dead. With 1. Any dead cell with exactly three live neighbors (out of its eight nearest neighbors) comes to life [reproduction]. 2. Any live...

  • JAVA. Threading the Game of Life Write a Java program to implement the Game of Life,...

    JAVA. Threading the Game of Life Write a Java program to implement the Game of Life, as defined by John Conway: Any live cell with fewer than two live neighbors dies, as if caused by under-population. Any live cell with two or three live neighbors lives on to the next generation. Any live cell with more than three live neighbors dies, as if by overpopulation. Any dead cell with exactly three live neighbors becomes a live cell, as if by...

  • You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's...

    You are going to be implementing the classic computer science simulation, Conway's Game of Life. Conway's Life is played on a matrix of cells, kind of like a chess board but theoretically extending infinitely in every direction. Each individual cell in the matrix can either be alive or dead. A live cell in the matrix is shown in our simulation by printing an asterisk (*) to the screen. A dead cell is shown by leaving that area of the matrix...

  • Objective: Write a program that implements the Game of Life cellular automata system invented by John...

    Objective: Write a program that implements the Game of Life cellular automata system invented by John Conway. 1. Create two game grids of size at least 50x50. These grid cells can be either Boolean or integer. In the following, I’ll refer to these as gridOne and gridTwo. 2. Set all cells in both grids to false. 3. Start by initializing gridOne. Allow the user to specify two different ways of initializing the grid: 1) by specifying a pattern file to...

  • I am really struggling with how to approach this program. Conway's Game of life, whereby, 1....

    I am really struggling with how to approach this program. Conway's Game of life, whereby, 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 over-population. 4. Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction. Submit...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT