forked from AlexIzydorczyk/sudoku
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
112 lines (92 loc) · 3.17 KB
/
main.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
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
100
101
102
103
104
105
106
107
108
109
110
111
/*
Matt Olson
Alex Izydorczyk
Main driver of Sudoku game
*/
#include <iostream>
#include <regex>
#include <sstream>
#include "solver.hpp"
#include "altproj.hpp"
#include "game.hpp"
#include "tests.hpp"
using namespace std;
int main(int argc, char* argv[]){
int seed; //random seed
int gamesize = 9; // default size of game
int nobs = 10; // default number of prefilled spaces
int sim = 0; // number of simulation runs (if running speed tests)
bool verbose = false; // print each simulation result for speed tests
string method = "backtrace"; //choose solving method
// Handle command line args
for (int i = 1; i < argc; ++i) {
if ((std::string(argv[i]) == "--seed") ||
(std::string(argv[i]) == "-s")) {
if (i + 1 < argc) {
istringstream ss(argv[++i]);
if (!(ss >> seed))
cerr << "Invalid number " << argv[i++] << endl;
} else {
std::cerr << "--seed option requires one argument."
<< std::endl;
return 1;
}
}
if ((std::string(argv[i]) == "--gamesize") ||
(std::string(argv[i]) == "-g")) {
if (i + 1 < argc) {
istringstream ss(argv[++i]);
if (!(ss >> gamesize))
cerr << "Invalid number " << argv[i++] << endl;
} else {
std::cerr << "--gamesize option requires one argument."
<< std::endl;
return 1;
}
}
if ((std::string(argv[i]) == "--nobs") ||
(std::string(argv[i]) == "-n")) {
if (i + 1 < argc) {
istringstream ss(argv[++i]);
if (!(ss >> nobs))
cerr << "Invalid number " << argv[i++] << endl;
} else {
std::cerr << "--nobs option requires one argument."
<< std::endl;
return 1;
}
}
if ((std::string(argv[i]) == "--Unittest") ||
(std::string(argv[i]) == "-u")) {
if (i + 1 < argc) {
istringstream ss(argv[++i]);
if (!(ss >> sim))
cerr << "Invalid number " << argv[i++] << endl;
} else {
std::cerr << "--Unittest option requires one argument."
<< std::endl;
return 1;
}
}
if ((std::string(argv[i]) == "--Verbose") ||
(std::string(argv[i]) == "-v")) {
verbose = true;
}
if ((std::string(argv[i]) == "--RP") ||
(std::string(argv[i]) == "-rp")) {
method = "RP";
}
}
srand(seed); // set random seed
// Welcome message
cout << "===========================================" << endl;
cout << "============ Welcome to Sudoku! ===========" << endl;
cout << "===========================================" << endl;
// Play game or run simulations
if (sim == 0){
playGame(gamesize, nobs);
} else {
unitTest(gamesize, nobs, sim, verbose);
}
return 0;
}