-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (56 loc) · 1.56 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
#include <iostream>
#include <cassert>
#include "HanoiTowerBFS.hpp"
#include "HanoiTowerAStar.hpp"
#include <chrono>
#include <memory>
int main(int argc, char *argv[])
{
int numberOfPoles = 3;
int towerHeight = 8;
std::string algo = "ASTAR";
int opt_ind = 1;
while (opt_ind < argc)
{
if(argv[opt_ind] == "--algorithm")
{
algo=argv[opt_ind+1];
opt_ind+=2;
continue;
}
if(argv[opt_ind] == "--pegs")
{
numberOfPoles=std::stoi(argv[opt_ind+1]);
opt_ind+=2;
continue;
}
if(argv[opt_ind] == "--towers")
{
towerHeight=std::stoi(argv[opt_ind+1]);
opt_ind+=2;
continue;
}
opt_ind++;
}
std::unique_ptr<HanoiTowerAlgorithm> hta;
if (algo == "BFS")
{
hta = std::unique_ptr<HanoiTowerAlgorithm>(new HanoiTowerBFS(towerHeight, numberOfPoles));
}
else if (algo == "ASTAR")
{
hta = std::unique_ptr<HanoiTowerAlgorithm>(new HanoiTowerAStar(towerHeight, numberOfPoles));
}
else
{
std::cout << "Unrecognized algoritm: " << algo << std::endl;
return 1;
}
auto start = std::chrono::steady_clock::now();
HanoiState solution = hta->solve();
auto duration = std::chrono::duration_cast<std::chrono::seconds>
(std::chrono::steady_clock::now() - start);
printPathToState(solution);
std::cout << "It took " << duration.count() << "s to find the solution" << std::endl;
return 0;
}