-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterMind.cpp
49 lines (45 loc) · 1.24 KB
/
MasterMind.cpp
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
//============================================================================
// Name : MasterMind.cpp
// Author : Jørgen Edelbo
// Version :
// Copyright : Copyright 2013 Jørgen Edelbo
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#include "row.h"
int main() {
Row secret;
string line;
vector<Row> guesses;
cout << "Sequence of " << ROW_SIZE << " random values has been generated" << endl;
cout << " ? ? ? ?" << endl;
cout << "-> ";
while (getline(cin, line)) {
try {
Row guess(line);
guesses.push_back(guess);
int i = 1;
cout << "==================" << endl;
for (Row r : guesses) {
cout << i++ << ": " << r.rep() << "- " << secret.compare(r).rep() << endl;
}
if (guess == secret) {
cout << "Code broken !!!" << endl;
break;
}
if (i == 10) {
cout << "No more guesses !!!" << endl;
cout << "Code was: " << secret.rep() << endl;
break;
}
}
catch (const InvalidInput& e) {
cout << e.what() << endl;
}
cout << "-> ";
}
return 0;
}