-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapenv.cpp
More file actions
254 lines (254 loc) · 6.39 KB
/
mapenv.cpp
File metadata and controls
254 lines (254 loc) · 6.39 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
///**
// * $Id: mapenv.cpp,v 1.2 2006/09/18 06:20:50 nathanst Exp $
// *
// * Using the pathfinding library, this class will extend the environment
// * class so that the various pathfinding methods can be used.
// *
// * Uses Nathan's graph class as a base.
// *
// * Copyright (c) Brandon Blanck
// * May 7, 2004
// */
//
//#include "mapenv.h"
//#include "pathfind.h"
//
//using namespace std;
//
//#define COST_ONE 10000000
//#define COST_SQRT2 14142135
//#define MULTIPLY_CONST 10000000
//
///**
// * Checks whether or not the given node is an obstacle
// *
// * Returns true if it's an obstacle, false otherwise.
// */
//bool MapEnv::isObstacle(node* n) const
//{
// int x = n->getLabelL(kFirstData);
// int y = n->getLabelL(kFirstData+1);
//
// int terrain = m_map->getTerrainType(x, y);
// if (terrain == kGround)
// return false;
//
// terrain = m_map->getTerrainType(x, y, kLeftSide);
// if (terrain == kGround)
// return false;
//
// terrain = m_map->getTerrainType(x, y, kRightSide);
// if (terrain == kGround)
// return false;
//
// return true;
//}
//
//
///**
// * When finished, start and target will hold two valid, possibly
// * pathable positions. That is, the positions will not be an obstacle.
// */
//void MapEnv::getStartTarget(int* start, int* target) const
//{
// node* s;
// node* t;
//
// do {
// s = m_graph->getRandomNode();
// t = m_graph->getRandomNode();
//
// } while(isObstacle(s) || isObstacle(t)
// || !isValidNodeId(s->getNum())
// || !isValidNodeId(t->getNum())
// || s->getNum() == t->getNum());
//
// *start = s->getNum();
// *target = t->getNum();
//}
//
//
///**
// * Returns the heuristic of the graph.
// *
// * This is based off of an Octile graph.
// */
//int MapEnv::getHeuristic(int start, int target) const
//{
// if (m_abstrMap) {
// node* a = m_graph->getNode(start);
// node* b = m_graph->getNode(target);
//
// return (int) (m_abstrMap->h(a, b) * MULTIPLY_CONST);
// }
//
// int colStart = start % m_columns;
// int colTarget = target % m_columns;
// int rowStart = start / m_columns;
// int rowTarget = target / m_columns;
// int diffCol = abs(colTarget - colStart);
// int diffRow = abs(rowTarget - rowStart);
//
// int maxDiff;
// int minDiff;
// if (diffCol > diffRow)
// {
// maxDiff = diffCol;
// minDiff = diffRow;
// }
// else
// {
// maxDiff = diffRow;
// minDiff = diffCol;
// }
// return minDiff * COST_SQRT2 + (maxDiff - minDiff) * COST_ONE;
//}
//
///**
// * Returns the maximum cost of an edge.
// *
// * At the moment, this is COST_SQRT2, since the terrain isn't taken into count.
// * If terrain is taken into effect, this will change depending on terrain type.
// */
//int MapEnv::getMaxCost() const
//{
// return COST_SQRT2;
//}
//
//
///**
// * Returns the minimum cost of an edge.
// *
// * At the moment, this is COST_ONE, since the terrain isn't taken into count.
// * If terrain is taken into effect, this will change depending on terrain type.
// */
//int MapEnv::getMinCost() const
//{
// return COST_ONE;
//}
//
//
///**
// * Returns the number of nodes in the graph.
// */
//int MapEnv::getNumberNodes() const
//{
// return m_graph->getNumNodes();
//}
//
//
//void MapEnv::getSuccessors(int nodeId, int lastNodeId, vector<Successor>& result,
// bool /*usePruning*/) const
//{
// //result.reserve(8); // maximum 8 edges
// result.clear();
// node* n = m_graph->getNode(nodeId);
//
// if (isObstacle(n))
// {
// assert(result.size() == 0);
// return;
// }
//
//// edge_iterator i = n->getOutgoingEdgeIter();
////
//// for (edge* e = n->edgeIterNextOutgoing(i); e; e = n->edgeIterNextOutgoing(i))
//// {
//// int targetNodeId = e->getTo();
//// assert(isValidNodeId(targetNodeId));
//// node* targetNode = m_graph->getNode(targetNodeId);
////
//// if ((targetNodeId == lastNodeId) || // don't revisit departed node.
//// (isObstacle(targetNode))) // Obstacles are not passable
//// continue;
////
//// result.push_back(Successor(targetNodeId, (int)(e->getWidth() * MULTIPLY_CONST)));
//// }
//
// edge_iterator i = n->getEdgeIter();
//
// for (edge* e = n->edgeIterNext(i); e; e = n->edgeIterNext(i))
// {
// int targetNodeId;
// if (e->getTo() == n->getNum())
// targetNodeId = e->getFrom();
// else
// targetNodeId = e->getTo();
//
// //int targetNodeId = e->getTo();
// assert(isValidNodeId(targetNodeId));
// node* targetNode = m_graph->getNode(targetNodeId);
//
// if ((targetNodeId == lastNodeId) || // don't revisit departed node.
// (isObstacle(targetNode))) // Obstacles are not passable
// continue;
//
// result.push_back(Successor(targetNodeId, (int)(e->getWeight() * MULTIPLY_CONST)));
// }
//
//
//
// //if (result.size() <= 0)
// // printf("Successor size: %d, Number outgoing edges: %d, Incoming: %d\n", result.size(), n->getNumOutgoingEdges(), n->getNumIncomingEdges());
//}
//
//
//bool MapEnv::isValidNodeId(int nodeId) const
//{
// return m_graph->getNode(nodeId);
//}
//
//
//
///**
// * A series of functions to print out the map/path.
// * These are not perfect, and should really only
// * be used for debugging.
// */
//vector<char> MapEnv::getCharVector() const
//{
// vector<char> result;
// int numberNodes = getNumberNodes();
// result.reserve(numberNodes);
// for (int i = 0; i < numberNodes; ++i)
// {
// if (isObstacle(m_graph->getNode(i)))
// result.push_back('@');
// else
// result.push_back('.');
// }
// return result;
//}
//
//
//void MapEnv::printFormatted(ostream& o, const vector<char>& chars) const
//{
// int i = 0;
//
// for (int row = 0; row < m_rows; ++row)
// {
// for (int col = 0; col < m_columns; ++col)
// {
// //int nodeId = getNodeId(row, col);
// //o << chars[nodeId];
// o << chars[i];
// i++;
// }
// o << '\n';
// }
//}
//
//
//void MapEnv::printFormatted(ostream& o, const vector<int>& path) const
//{
// vector<char> chars = getCharVector();
// if (path.size() > 0)
// {
// for (vector<int>::const_iterator i = path.begin();
// i != path.end(); ++i)
// chars[*i] = 'x';
// chars[*path.begin()] = 'T';
// chars[*(path.end() - 1)] = 'S';
// }
// printFormatted(o, chars);
//}