-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (46 loc) · 1.55 KB
/
main.cpp
File metadata and controls
56 lines (46 loc) · 1.55 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
#include "helper.h"
int main(int argc , char** argv) {
string userInput;
string moves[3] = {"rock","paper","scissors"};
int HumanFinal = -1; //Assume is wrong input for human
int AIFinal;
bool quit = false;
bool tie = false;
std::minstd_rand rng;
if (argc < 2) {
rng.seed(time(nullptr));
// srand(time(nullptr));
}
else{
rng.seed(std::stoi(argv[1]));
}
do{
do{
tie = false;
do{
cout << "Enter (R)ock, (P)aper, or (S)cissors for your move: ";
getline(cin,userInput);
HumanFinal = strip(userInput);
// cout << endl;
}while(HumanFinal == -1);
//Generate AI ouput
AIFinal = getAIInput(rng);
if(winner(HumanFinal,AIFinal) == 1) cout << "You win!" << endl;
else if(winner(HumanFinal,AIFinal) == 0) cout << "The AI wins :(" << endl;
else{
cout << "You and the AI both played " << moves[AIFinal] << "." << endl;
tie = true;
cout << "Keep playing until someone wins." << endl;
}
}while(tie == true);
HumanFinal = -1; //Reset to use for quit game indication
do{
cout << "Would you like to replay the game?" << endl;
cout << "Enter (Y)es or (N)o: ";
getline(cin,userInput);
HumanFinal = strip(userInput);
}while(HumanFinal == -1);
if(HumanFinal == 5) quit = true;
}while(quit == false);
return 0;
}