-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathISearcherSolverAdapter.h
70 lines (60 loc) · 1.47 KB
/
ISearcherSolverAdapter.h
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
//
// Created by matan on 1/16/20.
//
#ifndef HW4_SEARCHALGORITHMS_ISEARCHERSOLVERADAPTER_H_
#define HW4_SEARCHALGORITHMS_ISEARCHERSOLVERADAPTER_H_
#include "interfaces.h"
#include "../searchAlgorithms/interfaces.h"
string solToStringInstructions(vector<State<pair<int,int>>*> solMoves)
{
bool first = true;
int prevX;
int prevY;
string sol;
for(auto state : solMoves)
{
if(first)
{
first = false;
}
else
{
if(state->getState().first < prevX)
{
sol += "up, ";
}
else if(state->getState().first > prevX)
{
sol += "down, ";
}
else if(state->getState().second > prevY)
{
sol += "right, ";
}
else if(state->getState().second < prevY)
{
sol += "left, ";
}
}
prevX = state->getState().first;
prevY = state->getState().second;
}
return sol.substr(0, sol.length()-2);
}
class ISearcherSolverAdopter : public Solver<ISearchable<pair<int, int>>*, string>{
ISearcher<pair<int, int>>* searcher;
public:
explicit ISearcherSolverAdopter(ISearcher<pair<int, int>>* searcher1)
{
searcher = searcher1;
}
string solve(ISearchable<pair<int, int>>* problem) override
{
return solToStringInstructions(searcher->search(problem).getMoves());
}
Solver<ISearchable<pair<int, int>>*, string>* clone() override
{
return new ISearcherSolverAdopter(searcher->clone());
}
};
#endif //HW4_SEARCHALGORITHMS_ISEARCHERSOLVERADAPTER_H_