Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
99 lines (87 loc) · 3.31 KB
/
Copy pathmain.cpp
File metadata and controls
99 lines (87 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "GameOfLifeHeader.h"
#include <iostream>
#include <fstream> //be able to read in from a file and print into another file
#include <string>
#include <cmath>
using namespace std;
int main (int argc, char** argv)
{
cout<< "Welcome to the game of life!"<< endl;
cout<<"The rules are: "<<endl;
cout<< "1. A location that has one or fewer neighbors will be empty in the next generation. If a cell was in that location, it dies of loneliness."<<endl;
cout<< "2. A location with two neighbors remains stable. If there was a cell, there’s still a cell. If it was empty, it’s still empty. "<< endl;
cout<< "3. A location with three neighbors will contain a cell in the next generation. If it currently has a cell, the cell lives on. If it’s empty, a new cell is born." << endl;
cout<< "4.A location with four or more neighbors will be empty in the next generation due to overcrowding." << endl;
cout<< "Do you want to start with a random configuration, or provide a map for configuration?"<< endl;
GameOfLife myLife;
while (true)
{
cout<< "Enter 'r' for random and ‘f’ for a flatline and ’e’ to exit game" << endl;
char configAnswer;
cin>> configAnswer;
configAnswer = tolower(configAnswer);
if (configAnswer == 'r')
{
cout<< "Choose the random configuration" << endl;
int height;
int width;
double popDens;
cout<< "Please input the height: " << endl;
cin>> height;
cout<< "Please input the width: " << endl;
cin>> width;
cout << "Please input a number between 0-1 for the population density: " << endl;
cin>> popDens;
char gameMode=myLife.getGameMode();
gameMode= tolower(gameMode);
if(gameMode=='c')
{
cout<< "You choose to play the classic mode!"<< endl;
myLife.classicMode(height, width, popDens);
}
else if(gameMode=='d')
{
cout<< "You choose to play the doughnut mode!" << endl;
myLife.doughnutMode(height, width, popDens);
}
else
{
cout<< "You choose to play the mirror mode!" << endl;
myLife.mirrorMode(height, width, popDens);
}
break;
}
else if(configAnswer=='f')
{
string line;
int lineCount=0;
int height;
int width;
string fileName;
cout<< "Please input the file name: " << endl;
cin>> fileName;
ifstream infile(fileName + ".txt");
while (getline(infile,line))
{
lineCount++;
if(lineCount==1)
{
height=stoi(line);
}
else if(lineCount==2)
{
width=stoi(line);
}
else
break;
}
break;
}
else if(configAnswer =='e')
{
break;
}
else
cout<< "Incorrect input /n Please try again" << endl;
}
}