-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
62 lines (58 loc) · 2.02 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.cpp :+: :+: */
/* +:+ */
/* By: pacovali <[email protected]> +#+ */
/* +#+ */
/* Created: 2020/08/15 02:33:11 by pacovali #+# #+# */
/* Updated: 2020/08/24 20:56:17 by pacovali ######## odam.nl */
/* */
/* ************************************************************************** */
#include "Solver.class.hpp"
using namespace std;
int checkSearchType( const string& type ) {
int searchType = -1;
if ( type == "-astar" ) {
searchType = 3;
} else if ( type == "-greedy" ) {
searchType = 1;
} else if ( type == "-costuniform" ) {
searchType = 2;
}
if ( searchType < 0 ) {
throw runtime_error("Unknown argument");
}
return (searchType);
}
int main ( int ac, char **av ) {
try {
if ( ac < 3 || ac > 4 ) {
cerr << "Usage: ./rubik -astar/-greedy/-costuniform [command_list] [-r random_command_list_length]" << endl;
exit (1);
}
int searchType = checkSearchType( av[1] );
if ( ac == 4 ) {
if ( string(av[2]) != "-r" ) {
throw runtime_error("Unknown argument");
}
int length = -1;
try {
length = stoi(av[3]);
} catch (const exception& e) {
cerr << "Error: " << e.what() << endl;
}
if ( length < 1 ) {
throw range_error("Length of random command list must be a positive integer");
}
Solver s( length );
s.solve( searchType );
} else {
Solver s( av[2] );
s.solve( searchType );
}
} catch (const exception& e) {
cerr << "Error: " << e.what() << endl;
}
return (0);
}