SlideShare a Scribd company logo
1 of 8
Download to read offline
Need help writing Conway's Game of Life. These are the instructions:
The game of Life is intended to model life in a society of organisms. Consider a rectangular
array of cells, each of which may contain an organism. If the array is considered to extend
indefinitely in both directions, then each cell has eight neighbors, the eight cells surrounding it.
Births and deaths occur according to the following rules:
An organism is born in any empty cell having exactly three neighbors.
An organism dies from isolation if it has fewer than two neighbors.
An organism dies from overcrowding if it has more than three neighbors.
All other organisms survive to the next generation.
Write a program to play the game of Life and investigate the patterns produced by various initial
configurations. Some configurations die off rather rapidly; others repeat after a certain number of
generations; others change shape and size and may move across the array.
NOTE:
For representing each organism, use "@" characters.
For an array of cells, use 30x30 two-dimensional array.
Each generation should be displayed on the screen and should be paused.
(You can use cin.get( ) library function to pause running your program.)
4. The source file should be called life.cpp
5. All assignments are expected to be INDIVIDUAL work. All work handed in must be original.
Duplicate or very similar programs receive zero points.
Input
A set of initial cells will be given using the interactive way using a keyboard.
The followings are the prompt for the input:
Please Enter the number of initial cells: 4
The position of cell is 10 10
The position of cell is 10 11
The position of cell is 10 12
The position of cell is 11 11
How many generations do you want to display? 3
Output
The program then display each generation of organisms at a time.
The 1-generation
@@@
@
Press any key to continue!!
(This picture should be displayed on the new screen.)
The 2-generation
@
@@@
@@@
Press any key to continue!!
The 3-generation
@@@
@ @
@
Do you want to do it again?(Yes/No) N
Solution
Note: User given template is used.
Answer:
#include
#include
#include
#include
#include
using namespace std;
int orAry[30][30];
void initilaize()
{
for(int kk=0;kk<30;kk++)
{
for(int bb=0;bb<30;bb++)
{
orAry[kk][bb]=0;
}
}
}
void disply()
{
cout<=0 )
{
cc++;
}
if( orAry[kk+1][aa-1]==1 && kk+1<30 && aa-1>=0)
{
cc++;
}
if( orAry[kk+1][aa]==1 && kk+1<30)
{
cc++;
}
if( orAry[kk][aa+1]==1 && aa+1<30)
{
cc++;
}
if( orAry[kk-1][aa-1]==1 && kk-1>=0 && aa-1>=0)
{
cc++;
}
if(orAry[kk+1][aa+1]==1 && kk+1<30 && aa+1<30)
{
cc++;
}
if(orAry[kk-1][aa]==1 && kk-1>=0)
{
cc++;
}
if( orAry[kk-1][aa+1]==1 && kk-1>=0 && aa+1<30)
{
cc++;
}
return cc;
}
void runLife()
{
int bCnt=0;
int dCnt=0;
for(int kk=0;kk<30;kk++)
{
for(int bb=0;bb<30;bb++)
{
if(orAry[kk][bb]==0)
{
bCnt=ChechNeighBourCount(kk,bb);
if(bCnt==3)
{
orAry[kk][bb]=1;
}
}
else if(orAry[kk][bb]==1)
{
dCnt=ChechNeighBourCount(kk,bb);
if(dCnt>3)
{
orAry[kk][bb]=0;
}
if(dCnt<2)
{
orAry[kk][bb]=0;
}
}
}
}
}
int main()
{
int rr,cc;
int npos=0;
int ngen=0;
int xv,yv;
char re;
srand(time(NULL));
do
{
initilaize();
cout<<"Please Enter the number of initial cells:";
cin>>npos;
for(int kk=0;kk>xv>>yv;
if(orAry[xv][yv]==0)
{
orAry[xv][yv]=1;
}
}
cout<<"How many generations do you want to display?";
cin>>ngen;
for(int kk=0;kk>re;
}while(re!='N');
return 0;
}
Sample Output:
Please Enter the number of initial cells:4
The position of cell is
10 10
The position of cell is
10 11
The position of cell is
10 12
The position of cell is
11 11
How many generations do you want to display?3
1 - generation
@@@
@
Press any key to continue
2 - generation
@@
@ @
@
Press any key to continue
3 - generation
@@
@ @
@
Press any key to continue
Do you want to do it again?(Yes/No) N
Exit code: 0 (normal program termination)

More Related Content

Similar to Need help writing Conways Game of Life. These are the instructions.pdf

Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
ESWARANM92
 
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
BANSALANKIT1077
 

Similar to Need help writing Conways Game of Life. These are the instructions.pdf (7)

Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
Amcat automata questions
Amcat   automata questionsAmcat   automata questions
Amcat automata questions
 
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf## Part B- Conway's Game of Life   ### Introduction   John Conway's Ga.pdf
## Part B- Conway's Game of Life ### Introduction John Conway's Ga.pdf
 
Python programming
Python  programmingPython  programming
Python programming
 
Cs in science_guides
Cs in science_guidesCs in science_guides
Cs in science_guides
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
5. conditionals
5. conditionals5. conditionals
5. conditionals
 

More from santanadenisesarin13

Thomas Lewis said “the capacity to blunder slightly is the real marv.pdf
Thomas Lewis said “the capacity to blunder slightly is the real marv.pdfThomas Lewis said “the capacity to blunder slightly is the real marv.pdf
Thomas Lewis said “the capacity to blunder slightly is the real marv.pdf
santanadenisesarin13
 
Q1. An individual who accepts the risks and opportunities entailed b.pdf
Q1. An individual who accepts the risks and opportunities entailed b.pdfQ1. An individual who accepts the risks and opportunities entailed b.pdf
Q1. An individual who accepts the risks and opportunities entailed b.pdf
santanadenisesarin13
 
Question 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdf
Question 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdfQuestion 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdf
Question 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdf
santanadenisesarin13
 
please help i have 40 minsItem 1In the case below, the original .pdf
please help i have 40 minsItem 1In the case below, the original .pdfplease help i have 40 minsItem 1In the case below, the original .pdf
please help i have 40 minsItem 1In the case below, the original .pdf
santanadenisesarin13
 
JAVA Write a class called F.pdf
JAVA  Write a class called F.pdfJAVA  Write a class called F.pdf
JAVA Write a class called F.pdf
santanadenisesarin13
 
I need help with these two questions 4.12 and 4.13 dealing with MATL.pdf
I need help with these two questions 4.12 and 4.13 dealing with MATL.pdfI need help with these two questions 4.12 and 4.13 dealing with MATL.pdf
I need help with these two questions 4.12 and 4.13 dealing with MATL.pdf
santanadenisesarin13
 

More from santanadenisesarin13 (20)

What does it mean by mRNA coded for by the Operon What does it.pdf
What does it mean by mRNA coded for by the Operon What does it.pdfWhat does it mean by mRNA coded for by the Operon What does it.pdf
What does it mean by mRNA coded for by the Operon What does it.pdf
 
Variability of a sample can he measured use the following statistic(s.pdf
Variability of a sample can he measured use the following statistic(s.pdfVariability of a sample can he measured use the following statistic(s.pdf
Variability of a sample can he measured use the following statistic(s.pdf
 
What are the advantages of using a compiled language over an interpr.pdf
What are the advantages of using a compiled language over an interpr.pdfWhat are the advantages of using a compiled language over an interpr.pdf
What are the advantages of using a compiled language over an interpr.pdf
 
Unbiased estimators Let theta be an estimator of a parameter theta..pdf
Unbiased estimators  Let theta be an estimator of a parameter theta..pdfUnbiased estimators  Let theta be an estimator of a parameter theta..pdf
Unbiased estimators Let theta be an estimator of a parameter theta..pdf
 
Thomas Lewis said “the capacity to blunder slightly is the real marv.pdf
Thomas Lewis said “the capacity to blunder slightly is the real marv.pdfThomas Lewis said “the capacity to blunder slightly is the real marv.pdf
Thomas Lewis said “the capacity to blunder slightly is the real marv.pdf
 
The strongest attractive forces between molecules of H_2O are ionic.pdf
The strongest attractive forces between molecules of H_2O are  ionic.pdfThe strongest attractive forces between molecules of H_2O are  ionic.pdf
The strongest attractive forces between molecules of H_2O are ionic.pdf
 
Q1. An individual who accepts the risks and opportunities entailed b.pdf
Q1. An individual who accepts the risks and opportunities entailed b.pdfQ1. An individual who accepts the risks and opportunities entailed b.pdf
Q1. An individual who accepts the risks and opportunities entailed b.pdf
 
Question 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdf
Question 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdfQuestion 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdf
Question 3 (24 markS) Westcock Shipbuilding Ltd. has a December 31 y.pdf
 
Place the following formulas in their proper order A. ALE, residu.pdf
Place the following formulas in their proper order A. ALE, residu.pdfPlace the following formulas in their proper order A. ALE, residu.pdf
Place the following formulas in their proper order A. ALE, residu.pdf
 
please help i have 40 minsItem 1In the case below, the original .pdf
please help i have 40 minsItem 1In the case below, the original .pdfplease help i have 40 minsItem 1In the case below, the original .pdf
please help i have 40 minsItem 1In the case below, the original .pdf
 
Non-Euclidean GeometryWhat statement, if any, can be made about th.pdf
Non-Euclidean GeometryWhat statement, if any, can be made about th.pdfNon-Euclidean GeometryWhat statement, if any, can be made about th.pdf
Non-Euclidean GeometryWhat statement, if any, can be made about th.pdf
 
Java ProgrammingA Swing button can have more than one action liste.pdf
Java ProgrammingA Swing button can have more than one action liste.pdfJava ProgrammingA Swing button can have more than one action liste.pdf
Java ProgrammingA Swing button can have more than one action liste.pdf
 
JAVA Write a class called F.pdf
JAVA  Write a class called F.pdfJAVA  Write a class called F.pdf
JAVA Write a class called F.pdf
 
In the adult, red bone marrow would normally be found in the sternu.pdf
In the adult, red bone marrow would normally be found in the  sternu.pdfIn the adult, red bone marrow would normally be found in the  sternu.pdf
In the adult, red bone marrow would normally be found in the sternu.pdf
 
I need help with these two questions 4.12 and 4.13 dealing with MATL.pdf
I need help with these two questions 4.12 and 4.13 dealing with MATL.pdfI need help with these two questions 4.12 and 4.13 dealing with MATL.pdf
I need help with these two questions 4.12 and 4.13 dealing with MATL.pdf
 
I dont understand the min and max Find the smallest positive value.pdf
I dont understand the min and max Find the smallest positive value.pdfI dont understand the min and max Find the smallest positive value.pdf
I dont understand the min and max Find the smallest positive value.pdf
 
How can the activation of effector molecules within cells be restric.pdf
How can the activation of effector molecules within cells be restric.pdfHow can the activation of effector molecules within cells be restric.pdf
How can the activation of effector molecules within cells be restric.pdf
 
Explain how the skin of reptiles adaptive for terrestial existence. .pdf
Explain how the skin of reptiles adaptive for terrestial existence. .pdfExplain how the skin of reptiles adaptive for terrestial existence. .pdf
Explain how the skin of reptiles adaptive for terrestial existence. .pdf
 
Distinguish the roles of the four economic actors in economicsSo.pdf
Distinguish the roles of the four economic actors in economicsSo.pdfDistinguish the roles of the four economic actors in economicsSo.pdf
Distinguish the roles of the four economic actors in economicsSo.pdf
 
Explain the term liquidity and how it relates to the classified bala.pdf
Explain the term liquidity and how it relates to the classified bala.pdfExplain the term liquidity and how it relates to the classified bala.pdf
Explain the term liquidity and how it relates to the classified bala.pdf
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
中 央社
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
BỘ LUYỆN NGHE TIẾNG ANH 8 GLOBAL SUCCESS CẢ NĂM (GỒM 12 UNITS, MỖI UNIT GỒM 3...
 

Need help writing Conways Game of Life. These are the instructions.pdf

  • 1. Need help writing Conway's Game of Life. These are the instructions: The game of Life is intended to model life in a society of organisms. Consider a rectangular array of cells, each of which may contain an organism. If the array is considered to extend indefinitely in both directions, then each cell has eight neighbors, the eight cells surrounding it. Births and deaths occur according to the following rules: An organism is born in any empty cell having exactly three neighbors. An organism dies from isolation if it has fewer than two neighbors. An organism dies from overcrowding if it has more than three neighbors. All other organisms survive to the next generation. Write a program to play the game of Life and investigate the patterns produced by various initial configurations. Some configurations die off rather rapidly; others repeat after a certain number of generations; others change shape and size and may move across the array. NOTE: For representing each organism, use "@" characters. For an array of cells, use 30x30 two-dimensional array. Each generation should be displayed on the screen and should be paused. (You can use cin.get( ) library function to pause running your program.) 4. The source file should be called life.cpp 5. All assignments are expected to be INDIVIDUAL work. All work handed in must be original. Duplicate or very similar programs receive zero points. Input A set of initial cells will be given using the interactive way using a keyboard. The followings are the prompt for the input: Please Enter the number of initial cells: 4 The position of cell is 10 10 The position of cell is 10 11 The position of cell is 10 12 The position of cell is 11 11 How many generations do you want to display? 3 Output The program then display each generation of organisms at a time. The 1-generation @@@ @ Press any key to continue!!
  • 2. (This picture should be displayed on the new screen.) The 2-generation @ @@@ @@@ Press any key to continue!! The 3-generation @@@ @ @ @ Do you want to do it again?(Yes/No) N Solution Note: User given template is used. Answer: #include #include #include #include #include using namespace std; int orAry[30][30]; void initilaize() { for(int kk=0;kk<30;kk++) { for(int bb=0;bb<30;bb++) { orAry[kk][bb]=0; } } } void disply() {
  • 3. cout<=0 ) { cc++; } if( orAry[kk+1][aa-1]==1 && kk+1<30 && aa-1>=0) { cc++; } if( orAry[kk+1][aa]==1 && kk+1<30) { cc++; } if( orAry[kk][aa+1]==1 && aa+1<30) { cc++; } if( orAry[kk-1][aa-1]==1 && kk-1>=0 && aa-1>=0) { cc++; } if(orAry[kk+1][aa+1]==1 && kk+1<30 && aa+1<30) { cc++; } if(orAry[kk-1][aa]==1 && kk-1>=0) { cc++; } if( orAry[kk-1][aa+1]==1 && kk-1>=0 && aa+1<30) { cc++; } return cc; } void runLife()
  • 4. { int bCnt=0; int dCnt=0; for(int kk=0;kk<30;kk++) { for(int bb=0;bb<30;bb++) { if(orAry[kk][bb]==0) { bCnt=ChechNeighBourCount(kk,bb); if(bCnt==3) { orAry[kk][bb]=1; } } else if(orAry[kk][bb]==1) { dCnt=ChechNeighBourCount(kk,bb); if(dCnt>3) { orAry[kk][bb]=0; } if(dCnt<2) { orAry[kk][bb]=0; } } } } } int main() { int rr,cc;
  • 5. int npos=0; int ngen=0; int xv,yv; char re; srand(time(NULL)); do { initilaize(); cout<<"Please Enter the number of initial cells:"; cin>>npos; for(int kk=0;kk>xv>>yv; if(orAry[xv][yv]==0) { orAry[xv][yv]=1; } } cout<<"How many generations do you want to display?"; cin>>ngen; for(int kk=0;kk>re; }while(re!='N'); return 0; } Sample Output: Please Enter the number of initial cells:4 The position of cell is 10 10 The position of cell is 10 11 The position of cell is 10 12 The position of cell is 11 11 How many generations do you want to display?3 1 - generation
  • 6. @@@ @ Press any key to continue 2 - generation
  • 7. @@ @ @ @ Press any key to continue 3 - generation
  • 8. @@ @ @ @ Press any key to continue Do you want to do it again?(Yes/No) N Exit code: 0 (normal program termination)