-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm.h
59 lines (57 loc) · 1.66 KB
/
algorithm.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
#ifndef ALGORITHM_H
#define ALGORITHM_H
#include <vector>
#include <queue>
#include <string>
#include <iostream>
#include <cmath>
class algorithm
{
public:
struct Node {
int i, j, g, h;
std::string val;
Node(int i, int j) {
this->i = i;
this->j = j;
g = -1;
h = 0;
}
bool operator<(const Node &a) const {
if ((a.g + a.h) == (g + h)) {
if (a.h == h) {
return a.g < g;
}
return a.h < h;
}
return (a.g + a.h) < (g + h);
}
};
typedef std::vector<std::vector<Node>> nodeMap;
algorithm(nodeMap &p);
class distance {
public:
int manhattan(int i, int j, int x2, int y2);
int euclidean(int i, int j, int x2, int y2);
int chebyshev(int i, int j, int x2, int y2);
int bfs(int i, int j, int x2, int y2);
};
void setAlgo(int (algorithm::distance::*algo)(int, int, int, int));
nodeMap start();
private:
const int diri[4] = {0, 1, 0, -1};
const int dirj[4] = {1, 0, -1, 0};
const char dir[4][4] = {"←", "↑", "→", "↓"};
int x1, x2, y1, y2;
int (distance::*algo)(int, int, int, int) = NULL;
nodeMap p;
std::vector<std::vector<int>> g;
std::vector<std::vector<int>> s;
void print(nodeMap &p, int x2, int y2);
nodeMap astar(int x1, int y1, int x2, int y2,
nodeMap p,
const std::vector<std::vector<int>> g, std::vector<std::vector<int>> s,
int(distance::*algo)(int, int, int, int));
bool overflow(int a, int b, int m, int n);
};
#endif // ALGORITHM_H