-
Notifications
You must be signed in to change notification settings - Fork 0
/
findPath.h
116 lines (88 loc) · 3.07 KB
/
findPath.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// Created by Debraj Ray on 2021-12-30.
//
#ifndef EXAMPLE_FINDPATH_H
#define EXAMPLE_FINDPATH_H
#include <iostream>
#include "vector"
#include <set>
#include <map>
#include "gameConstants.h"
#include "AStar_.h"
#include "gameConstants.h"
#include "Logger.h"
using namespace std;
using namespace RTS;
class findPath {
const LOG_LEVEL LogLevel = LOG_LEVEL::INFO;
int current_x;
int current_y;
int next_x;
int next_y;
/// Real World
AStar_ aStar;
/// Abstract World
std::unique_ptr<AStar_> aStarAbs;
vector<std::vector<int>> gridAbstract;
int source_x;
int source_y;
int destination_x;
int destination_y;
node_ destAbsCenter;
node_ nextAbstractCenterSaved;
bool isAbstractSearchInUse = false;
vector<std::pair<int, int>> path;
std::unique_ptr<Logger> logger;
/**
* Compare two nodes in the A* path
* @return +1 if first > second, -1 is first < second, 0 otherwise
*/
int compareNodeOrders(int location1_x, int location1_y, int location2_x, int location2_y);
node_ getAbstractCenterOfCoordinate(int x, int y);
void replenishNodesFromRealWorldAStar(int x, int y);
public:
int visited_x_onpath = -1;
int visited_y_onpath = -1;
int knownOnTrackX = -1;
int knownOnTrackY = -1;
findPath(std::vector<std::vector<int>> &grid, int src_x, int src_y, int dest_x, int dest_y) : aStar(grid, src_x, src_y, dest_x, dest_y){
logger = std::make_unique<Logger>(LogLevel);
current_x = src_x;
current_y = src_y;
source_x = src_x;
source_y = src_y;
destination_x = dest_x;
destination_y = dest_y;
destAbsCenter = getAbstractCenterOfCoordinate(destination_x, destination_y);
createAbstractWorldGrid();
}
findPath(std::vector<std::vector<int>> &grid) : aStar(grid){
logger = std::make_unique<Logger>(LogLevel);
destAbsCenter = getAbstractCenterOfCoordinate(destination_x, destination_y);
createAbstractWorldGrid();
}
bool findPathToDestination();
bool findPathToDestinationDeferred();
void calculateNextPosition();
void getNextPositionAfterGivenLocation(int &given_x, int &given_y, int &next_x, int &next_y);
int getNext_x();
int getNext_y();
bool isOnTrack(int current_x, int current_y);
bool isOnTrackNoMemorizing(int current_x, int current_y);
int pathDirection(int current_x, int current_y);
int inferDirection(int x, int y, int next_x, int next_y);
void changeSourceAndDestination(int startX, int startY, int endX, int endY);
void changeMap(vector<vector<int>> &grid);
int getCountOfNodesToDestination();
void stitchNewPathIntoExistingAtNode(findPath &fp_, int xOnTrack, int yOnTrack, int newSourceX, int newSourceY);
int getShortestDistance(int x1, int y1, int x2, int y2);
/**
* Abstract A*
*/
void createAbstractWorldGrid();
int getNodeOrder(int &x, int &y);
void printTrack(int startX, int startY);
void getCurrentStartOfPath(int &x, int &y);
int getMaxMemoryUsed();
};
#endif //EXAMPLE_FINDPATH_H