-
Notifications
You must be signed in to change notification settings - Fork 1
/
dstar_env.cpp
50 lines (45 loc) · 1.59 KB
/
dstar_env.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
#include "dstar_env.h"
#include <string>
void Environment::generateCells() {
for (int j = 0; j < y_dim; ++j) {//row
vector<grid> colGrids;
for (int i = 0; i < x_dim; ++i) {//col
string id = "R" + to_string(j) + ",C" + to_string(i);
grid currGrid(id);
if (j > 0) {
currGrid.preds[pair<int, int>(j - 1, i)] = linearCost;
currGrid.succs[pair<int, int>(j - 1, i)] = linearCost;
}
if (j + 1 < y_dim) {
currGrid.preds[pair<int, int>(j + 1, i)] = linearCost;
currGrid.succs[pair<int, int>(j + 1, i)] = linearCost;
}
if (i > 0) {
currGrid.preds[pair<int, int>(j, i - 1)] = linearCost;
currGrid.succs[pair<int, int>(j, i - 1)] = linearCost;
}
if (i + 1 < x_dim) {
currGrid.preds[pair<int, int>(j, i + 1)] = linearCost;
currGrid.succs[pair<int, int>(j, i + 1)] = linearCost;
}
if (j > 0 && i + 1 < x_dim) {
currGrid.preds[pair<int, int>(j - 1, i + 1)] = diagonalCost;
currGrid.succs[pair<int, int>(j - 1, i + 1)] = diagonalCost;
}
if (j + 1 < y_dim && i + 1 < x_dim) {
currGrid.preds[pair<int, int>(j + 1, i + 1)] = diagonalCost;
currGrid.succs[pair<int, int>(j + 1, i + 1)] = diagonalCost;
}
if (j + 1 < y_dim && i > 0) {
currGrid.preds[pair<int, int>(j + 1, i - 1)] = diagonalCost;
currGrid.succs[pair<int, int>(j + 1, i - 1)] = diagonalCost;
}
if (j > 0 && i > 0) {
currGrid.preds[pair<int, int>(j - 1, i - 1)] = diagonalCost;
currGrid.succs[pair<int, int>(j - 1, i - 1)] = diagonalCost;
}
colGrids.push_back(currGrid);
}
cells.push_back(colGrids);
}
}