-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboggle_main.cxx
More file actions
50 lines (45 loc) · 1.47 KB
/
boggle_main.cxx
File metadata and controls
50 lines (45 loc) · 1.47 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
/* Filename: boggle_main.cxx
* Author: Peter Piech
* Date Created: 07/29/2016
* Date Modified: 08/01/2016
* Description: Boggle game solver
*/
#include "boggle.h"
#include <iostream>
#include <cstdlib>
#include <cstring>
void print_usage(const char* argv0) {
std::cout << "USAGE:\n\t" << argv0 << " <board file> <dictionary file> [-v|--verbose]";
std::cout << std::endl;
exit(0); // exit program
}
int main(int argc, char* argv[])
{
bool verbose = false;
if (argc < 3 || argc > 4) {
std::cout << "Incorrect number of arguments given: " << argc << std::endl;
print_usage(argv[0]); // print usage string and quit
} else if (argc == 4) {
verbose = true; // assume extra argument is good and check below
// check if optional third argument is neither "-v" nor "--verbose"
if (!(std::strcmp(argv[3], "-v") == 0) && !(std::strcmp(argv[3], "--verbose") == 0)) {
std::cout << "Invalid argument: " << argv[3] << std::endl;
print_usage(argv[0]); // print usage string and quit
}
}
if (verbose) {
std::cout << "Initializing boggle..." << std::endl;
}
Boggle game = Boggle(argv[1], argv[2]);
if (verbose) {
game.print_board();
std::cout << "Solving boggle..." << std::endl;
}
game.solve();
if (game.isSolved()) {
game.print_solutions();
} else {
std::cerr << "ERROR: boggle board not solved" << std::endl;
}
return EXIT_SUCCESS;
}