HOG2
Sample.cpp
Go to the documentation of this file.
1 /*
2  * $Id: sample.cpp
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 5/31/05.
6  * Modified by Nathan Sturtevant on 02/29/20.
7  *
8  * This file is part of HOG2. See https://github.com/nathansttt/hog2 for licensing information.
9  *
10  */
11 
12 #include "Common.h"
13 #include "Sample.h"
14 #include "UnitSimulation.h"
15 #include "EpisodicSimulation.h"
16 #include "Map2DEnvironment.h"
17 #include "RandomUnits.h"
18 #include "TemplateAStar.h"
19 #include "GraphEnvironment.h"
20 //#include "MapSectorAbstraction.h"
21 //#include "ContractionHierarchy.h"
22 #include "MapGenerators.h"
23 
24 bool mouseTracking = false;
25 bool runningSearch1 = false;
26 bool runningSearch2 = false;
27 bool bSaveAndQuit = false;
28 int px1, py1, px2, py2;
29 int absType = 0;
30 int mazeSize = 512;
32 
33 std::vector<UnitMapSimulation *> unitSims;
40 
41 //MapSectorAbstraction *msa;
42 
43 std::vector<xyLoc> path;
44 
45 int main(int argc, char* argv[])
46 {
48  RunHOGGUI(argc, argv);
49 }
50 
51 //ContractionHierarchy *ch;
56 void CreateSimulation(int id)
57 {
58  Map *map;
59  if (gDefaultMap[0] == 0)
60  {
61  map = new Map(mazeSize/2, mazeSize/2);
62  MakeMaze(map, 1);
63  map->Scale(mazeSize, mazeSize);
64  }
65  else {
66  map = new Map(gDefaultMap);
67 // map->Scale(512, 512);
68  }
69  map->SetTileSet(kWinter);
70 // msa = new MapSectorAbstraction(map, 2);
71 // msa->ToggleDrawAbstraction(0);
72 // msa->ToggleDrawAbstraction(1);
73 // msa->ToggleDrawAbstraction(3);
74 // msa->ToggleDrawAbstraction(4);
75  unitSims.resize(id+1);
77  unitSims[id]->SetStepType(kMinTime);
78 
79  //ch = new ContractionHierarchy(map, GraphSearchConstants::GetGraph(map));
80 }
81 
86 {
87  InstallKeyboardHandler(MyDisplayHandler, "Toggle Abstraction", "Toggle display of the ith level of the abstraction", kAnyModifier, '0', '9');
88  InstallKeyboardHandler(MyDisplayHandler, "Cycle Abs. Display", "Cycle which group abstraction is drawn", kAnyModifier, '\t');
89  InstallKeyboardHandler(MyDisplayHandler, "Pause Simulation", "Pause simulation execution.", kNoModifier, 'p');
90  InstallKeyboardHandler(MyDisplayHandler, "Step Simulation", "If the simulation is paused, step forward .1 sec.", kNoModifier, 'o');
91  InstallKeyboardHandler(MyDisplayHandler, "Step History", "If the simulation is paused, step forward .1 sec in history", kAnyModifier, '}');
92  InstallKeyboardHandler(MyDisplayHandler, "Step History", "If the simulation is paused, step back .1 sec in history", kAnyModifier, '{');
93  InstallKeyboardHandler(MyDisplayHandler, "Step Abs Type", "Increase abstraction type", kAnyModifier, ']');
94  InstallKeyboardHandler(MyDisplayHandler, "Step Abs Type", "Decrease abstraction type", kAnyModifier, '[');
95 
96  InstallKeyboardHandler(MyPathfindingKeyHandler, "Mapbuilding Unit", "Deploy unit that paths to a target, building a map as it travels", kNoModifier, 'd');
97  InstallKeyboardHandler(MyRandomUnitKeyHandler, "Add A* Unit", "Deploys a simple a* unit", kNoModifier, 'a');
98  InstallKeyboardHandler(MyRandomUnitKeyHandler, "Add simple Unit", "Deploys a randomly moving unit", kShiftDown, 'a');
99  InstallKeyboardHandler(MyRandomUnitKeyHandler, "Add simple Unit", "Deploys a right-hand-rule unit", kControlDown, '1');
100 
101  InstallCommandLineHandler(MyCLHandler, "-map", "-map filename", "Selects the default map to be loaded.");
102  InstallCommandLineHandler(MyCLHandler, "-convert", "-map file1 file2", "Converts a map and saves as file2, then exits");
103  InstallCommandLineHandler(MyCLHandler, "-size", "-batch integer", "If size is set, we create a square maze with the x and y dimensions specified.");
104 
105 
107 
109 }
110 
111 void MyWindowHandler(unsigned long windowID, tWindowEventType eType)
112 {
113  if (eType == kWindowDestroyed)
114  {
115  printf("Window %ld destroyed\n", windowID);
116  RemoveFrameHandler(MyFrameHandler, windowID, 0);
117 
118  delete ma1;
119  ma1 = 0;
120  delete ma2;
121  ma2 = 0;
122  delete gdh;
123  gdh = 0;
124  delete gdh2;
125  gdh2 = 0;
126  delete unitSims[windowID];
127  unitSims[windowID] = 0;
128  runningSearch1 = false;
129  runningSearch2 = false;
130  mouseTracking = false;
131  }
132  else if (eType == kWindowCreated)
133  {
134  printf("Window %ld created\n", windowID);
135  InstallFrameHandler(MyFrameHandler, windowID, 0);
136  CreateSimulation(windowID);
137  SetNumPorts(windowID, 1);
138  }
139 }
140 
141 void MyFrameHandler(unsigned long windowID, unsigned int viewport, void *)
142 {
143  if (viewport == 0)
144  {
145  unitSims[windowID]->StepTime(1.0/30.0);
146 
147  // ch->OpenGLDraw();
148 // ch->Contract();
149 // return;
150  }
151  unitSims[windowID]->GetEnvironment()->GetMap()->OpenGLDraw();
152  //if (msa) msa->OpenGLDraw();
153 
154  if (mouseTracking)
155  {
156  glBegin(GL_LINES);
157  glColor3f(1.0f, 0.0f, 0.0f);
158  Map *m = unitSims[windowID]->GetEnvironment()->GetMap();
159  GLdouble x, y, z, r;
160  m->GetOpenGLCoord(px1, py1, x, y, z, r);
161  glVertex3f(x, y, z-3*r);
162  m->GetOpenGLCoord(px2, py2, x, y, z, r);
163  glVertex3f(x, y, z-3*r);
164  glEnd();
165  }
166 
167  if ((gdh) && (gdh2))
168  {
169  if (viewport == 0)
170  gdh->OpenGLDraw();
171  if (viewport == 1)
172  gdh2->OpenGLDraw();
173  }
174 
175  if ((ma1) && (viewport == 0)) // only do this once...
176  {
177  ma1->SetColor(0.0, 0.5, 0.0, 0.75);
178  if (runningSearch1)
179  {
180  ma1->SetColor(0.0, 0.0, 1.0, 0.75);
181  for (int x = 0; x < gStepsPerFrame; x++)
182  {
183  if (a1.DoSingleSearchStep(path))
184  {
185  printf("Solution: moves %d, length %f, %lld nodes\n",
186  (int)path.size(), ma1->GetPathLength(path), a1.GetNodesExpanded());
187  runningSearch1 = false;
188  break;
189  }
190  }
191  }
192  a1.OpenGLDraw();
193  }
194  if ((ma2) && (GetNumPorts(windowID) == 1 || (viewport == 1)))
195  {
196  ma2->SetColor(1.0, 0.0, 0.0, 0.5);
197  if (runningSearch2)
198  {
199  ma2->SetColor(1.0, 0.0, 1.0, 0.5);
200  for (int x = 0; x < gStepsPerFrame; x++)
201  {
202  if (a2.DoSingleSearchStep(path))
203  {
204  printf("Solution: moves %d, length %f, %lld nodes\n",
205  (int)path.size(), ma2->GetPathLength(path), a2.GetNodesExpanded());
206  runningSearch2 = false;
207  break;
208  }
209  }
210  }
211  a2.OpenGLDraw();
212  }
213 
214  if (bSaveAndQuit)
215  {
216  SaveScreenshot(windowID, gDefaultMap);
217  exit(0);
218  }
219 }
220 
221 void doExport()
222 {
223  exit(0);
224 }
225 
226 int MyCLHandler(char *argument[], int maxNumArgs)
227 {
228  if (strcmp(argument[0], "-map") == 0)
229  {
230  if (maxNumArgs <= 1)
231  return 0;
232  strncpy(gDefaultMap, argument[1], 1024);
233 
234  doExport();
235  return 2;
236  }
237  else if (strcmp(argument[0], "-convert") == 0)
238  {
239  if (maxNumArgs <= 2)
240  return 0;
241  Map m(argument[1]);
242  m.Save(argument[2]);
243  strncpy(gDefaultMap, argument[1], 1024);
244  bSaveAndQuit = true;
245  return 3;
246  }
247  else if (strcmp(argument[0], "-size" ) == 0)
248  {
249  if (maxNumArgs <= 1)
250  return 0;
251  mazeSize = atoi(argument[1]);
252  assert( mazeSize > 0 );
253  return 2;
254  }
255  return 2; //ignore typos
256 }
257 
258 void MyDisplayHandler(unsigned long windowID, tKeyboardModifier mod, char key)
259 {
260  switch (key)
261  {
262  case '0': case '1': case '2': case '3': case '4': case '5':
263  case '6': case '7': case '8': case '9':
264  //msa->ToggleDrawAbstraction(key);
265  break;
266  case '[': if (gStepsPerFrame > 2) gStepsPerFrame /= 2; break;
267  case ']': gStepsPerFrame *= 2; break;
268  case '\t':
269  if (mod != kShiftDown)
270  SetActivePort(windowID, (GetActivePort(windowID)+1)%GetNumPorts(windowID));
271  else
272  {
273  SetNumPorts(windowID, 1+(GetNumPorts(windowID)%MAXPORTS));
274  }
275  break;
276  case 'p': unitSims[windowID]->SetPaused(!unitSims[windowID]->GetPaused()); break;
277  case 'o':
278  {
279  //ch->Contract();
280  }
281  break;
282  default:
283  break;
284  }
285 }
286 
287 void MyRandomUnitKeyHandler(unsigned long windowID, tKeyboardModifier , char)
288 {
289  if (gdh == 0)
290  {
291  gdh = new GraphDistanceHeuristic(GraphSearchConstants::GetGraph(unitSims[windowID]->GetEnvironment()->GetMap()));
293  }
294  if (gdh2 == 0)
295  {
296  gdh2 = new GraphDistanceHeuristic(GraphSearchConstants::GetGraph(unitSims[windowID]->GetEnvironment()->GetMap()));
298  }
299  if (gdh != 0)
300  {
301  gdh->AddHeuristic();
302  }
303  if (gdh2 != 0)
304  {
305  gdh2->AddHeuristic();
306  }
307 
308  if ((gdh != 0) && (gdh2 != 0))
309  {
310  int larger = 0;
311  int smaller = 0;
312  int same = 0;
313  double sum1 = 0, sum2 = 0;
314  for (int x = 0; x < 10000; x++)
315  {
316  Graph *g = gdh->GetGraph();
317 // xyLoc a(random()%m->GetMapWidth(), random()%m->GetMapHeight());
318 // xyLoc b(random()%m->GetMapWidth(), random()%m->GetMapHeight());
319 // while ((m->GetTerrainType(a.x, a.y) != kGround) &&
320 // (m->GetTerrainType(b.x, b.y) != kGround))
321 // {
322 // a.x = random()%m->GetMapWidth();
323 // b.x = random()%m->GetMapWidth();
324 // a.y = random()%m->GetMapHeight();
325 // b.y = random()%m->GetMapHeight();
326 // }
327 
328  graphState a, b;
329  a = g->GetRandomNode()->GetNum();
330  b = g->GetRandomNode()->GetNum();
331  double h1 = gdh->HCost(a, b);
332  sum1+= h1;
333  double h2 = gdh2->HCost(a, b);
334  sum2+= h2;
335  if (fequal(h1, h2))
336  same++;
337  if (fgreater(h1, h2))
338  larger++;
339  if (fless(h1, h2))
340  smaller++;
341  }
342  printf("Far larger: %d, Avoid larger: %d, equal: %d\n", larger, smaller, same);
343  printf("Far: %1.3f; Avoid: %1.3f\n", sum1, sum2);
344  }
345 // if (ma == 0)
346 // return;
347 // if (gdh == 0)
348 // {
349 // gdh = new GraphDistanceHeuristic(GraphSearchConstants::GetGraph(ma->GetMap()));
350 // gdh->SetPlacement(kAvoidPlacement);
351 // ma->SetGraphHeuristic(gdh);
352 // for (int x = 0; x < 10; x++)
353 // gdh->AddHeuristic();
354 // }
355 // if (mod == kShiftDown)
356 // ma->SetGraphHeuristic(0);
357 // else if (ma->GetGraphHeuristic() == 0)
358 // {
359 // ma->SetGraphHeuristic(gdh);
360 // }
361 // else {
362 // gdh->AddHeuristic();
363 // }
364 
365 // Map *m = unitSims[windowID]->GetEnvironment()->GetMap();
366 //
367 // int x1, y1, x2, y2;
368 // x2 = random()%m->GetMapWidth();
369 // y2 = random()%m->GetMapHeight();
370 // x1 = random()%m->GetMapWidth();
371 // y1 = random()%m->GetMapHeight();
372 // SearchUnit *su1 = new SearchUnit(x1, y1, 0, 0);
373 // SearchUnit *su2 = new SearchUnit(x2, y2, su1, new TemplateAStar<xyLoc, tDirection, MapEnvironment>());
374 // //unitSim->AddUnit(su1);
375 // unitSims[windowID]->AddUnit(su2);
376 //
377 }
378 
379 void MyPathfindingKeyHandler(unsigned long windowID, tKeyboardModifier , char)
380 {
381  std::vector<graphState> thePath;
382  MapEnvironment *env = unitSims[windowID]->GetEnvironment();
383  Map *m = env->GetMap();
385 
386 // GraphDistanceHeuristic diffHeuristic(g);
387 // diffHeuristic.SetPlacement(kAvoidPlacement);
388 // for (int x = 0; x < 20; x++)
389 // diffHeuristic.AddHeuristic();
390 
391  GraphMapInconsistentHeuristic diffHeuristic(m, g);
392  diffHeuristic.SetPlacement(kAvoidPlacement);
393  for (int x = 0; x < 20; x++)
394  diffHeuristic.AddHeuristic();
395 
396  GraphEnvironment gEnv(g, &diffHeuristic);
397  gEnv.SetDirected(true);
398 
399  diffHeuristic.SetMode(kRandom);
400  diffHeuristic.SetNumUsedHeuristics(2);
401 
404  Timer t;
405 
406  for (int x = 0; x < 500; x++)
407  {
408  graphState s1, g1;
409  do {
410  s1 = g->GetRandomNode()->GetNum();
411  g1 = g->GetRandomNode()->GetNum();
412  } while (gEnv.HCost(s1, g1) < 100);
413  double firstLength;
414 
415  taNew.SetUseBPMX(false);
416  t.StartTimer();
417  taNew.GetPath(&gEnv, s1, g1, thePath);
418  t.EndTimer();
419  printf("old: %lld nodes expanded. Path length %d / %f. Time: %f\nrate0: %lld %f\n",
420  taNew.GetNodesExpanded(), (int)thePath.size(), gEnv.GetPathLength(thePath), t.GetElapsedTime(),
421  taNew.GetNodesExpanded(), taNew.GetNodesExpanded()/t.GetElapsedTime());
422  firstLength = gEnv.GetPathLength(thePath);
423 
424  for (int y = 1; y < 5; y++)
425  {
426  taNew.SetUseBPMX(y);
427  t.StartTimer();
428  taNew.GetPath(&gEnv, s1, g1, thePath);
429  t.EndTimer();
430  printf("new: %lld nodes expanded. Path length %d / %f. Time: %f\nrate%d: %lld %f\n",
431  taNew.GetNodesExpanded(), (int)thePath.size(), gEnv.GetPathLength(thePath), t.GetElapsedTime(),
432  y, taNew.GetNodesExpanded(), taNew.GetNodesExpanded()/t.GetElapsedTime());
433 
434  if (gEnv.GetPathLength(thePath) != firstLength)
435  printf("\n\n\n!!!!!!!!!!!!!!!!!! IT FAILED!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n\n");
436  }
437  printf("--\n");
438  }
439  delete g;
440 }
441 
442 bool MyClickHandler(unsigned long windowID, int, int, point3d loc, tButtonType button, tMouseEventType mType)
443 {
444  mouseTracking = false;
445  if (button == kRightButton)
446  {
447  switch (mType)
448  {
449  case kMouseDown:
450  unitSims[windowID]->GetEnvironment()->GetMap()->GetPointFromCoordinate(loc, px1, py1);
451  //printf("Mouse down at (%d, %d)\n", px1, py1);
452  break;
453  case kMouseDrag:
454  mouseTracking = true;
455  unitSims[windowID]->GetEnvironment()->GetMap()->GetPointFromCoordinate(loc, px2, py2);
456  //printf("Mouse tracking at (%d, %d)\n", px2, py2);
457  break;
458  case kMouseUp:
459  {
460  if ((px1 == -1) || (px2 == -1))
461  break;
462  unitSims[windowID]->GetEnvironment()->GetMap()->GetPointFromCoordinate(loc, px2, py2);
463  printf("Searching from (%d, %d) to (%d, %d)\n", px1, py1, px2, py2);
464 
465  if (ma1 == 0)
466  {
467  ma1 = new MapEnvironment(unitSims[windowID]->GetEnvironment()->GetMap());
468  }
469 // gdh = new GraphMapInconsistentHeuristic(ma1->GetMap(), GraphSearchConstants::GetGraph(ma1->GetMap()));
470 // gdh->SetPlacement(kAvoidPlacement);
471 // ma1->SetGraphHeuristic(gdh);
472 // for (int x = 0; x < 10; x++)
473 // gdh->AddHeuristic();
474 // ((GraphMapInconsistentHeuristic*)gdh)->SetNumUsedHeuristics(10);
475 // ((GraphMapInconsistentHeuristic*)gdh)->SetMode(kMax);
476  if (ma2 == 0)
477  ma2 = new MapEnvironment(unitSims[windowID]->GetEnvironment()->GetMap());
478 
479  a1.SetStopAfterGoal(true);
480  a2.SetStopAfterGoal(true);
481 // a2.SetWeight(2.0);
482  xyLoc s1;
483  xyLoc g1;
484  s1.x = px1; s1.y = py1;
485  g1.x = px2; g1.y = py2;
486 
487  a1.InitializeSearch(ma1, s1, g1, path);
488  a2.InitializeSearch(ma2, s1, g1, path);
489 // a2.SetUseBPMX(false);
490  //runningSearch1 = true;
491  runningSearch2 = true;
492 
493  }
494  break;
495  }
496  return true;
497  }
498  return false;
499 }
mouseTracking
bool mouseTracking
Definition: Sample.cpp:24
kFarPlacement
@ kFarPlacement
Definition: GraphEnvironment.h:217
GraphMapInconsistentHeuristic::SetMode
void SetMode(tHeuristicCombination mode)
Definition: GraphEnvironment.h:268
GraphDistanceHeuristic::AddHeuristic
void AddHeuristic(node *n=0)
Definition: GraphEnvironment.cpp:1564
UnitSimulation.h
kWindowCreated
@ kWindowCreated
Definition: Common.h:159
MyRandomUnitKeyHandler
void MyRandomUnitKeyHandler(unsigned long windowID, tKeyboardModifier, char)
Definition: Sample.cpp:287
RandomUnits.h
MyFrameHandler
void MyFrameHandler(unsigned long windowID, unsigned int viewport, void *)
Definition: Sample.cpp:141
graphState
unsigned long graphState
Definition: GraphEnvironment.h:32
runningSearch2
bool runningSearch2
Definition: Sample.cpp:26
TemplateAStar::GetNodesExpanded
uint64_t GetNodesExpanded() const
Definition: TemplateAStar.h:134
xyLoc::y
uint16_t y
Definition: Map2DEnvironment.h:42
MapEnvironment::GetMap
Map * GetMap() const
Definition: Map2DEnvironment.h:200
tKeyboardModifier
tKeyboardModifier
Definition: Common.h:136
Common.h
Timer::StartTimer
void StartTimer()
Definition: Timer.cpp:9
GraphDistanceHeuristic
Definition: GraphEnvironment.h:222
kNoModifier
@ kNoModifier
Definition: Common.h:137
kShiftDown
@ kShiftDown
Definition: Common.h:139
unitSims
std::vector< UnitMapSimulation * > unitSims
Definition: Sample.cpp:33
ma1
MapEnvironment * ma1
Definition: Sample.cpp:36
kWinter
@ kWinter
Definition: Map.h:32
xyLoc
Definition: Map2DEnvironment.h:37
GraphMapInconsistentHeuristic
Definition: GraphEnvironment.h:264
runningSearch1
bool runningSearch1
Definition: Sample.cpp:25
InstallKeyboardHandler
void InstallKeyboardHandler(KeyboardCallback kf, const char *title, const char *description, tKeyboardModifier mod, unsigned char firstKey, unsigned char lastKey)
Definition: Common.cpp:73
kControlDown
@ kControlDown
Definition: Common.h:140
MyClickHandler
bool MyClickHandler(unsigned long windowID, int, int, point3d loc, tButtonType button, tMouseEventType mType)
Definition: Sample.cpp:442
Map2DEnvironment.h
GraphMapInconsistentHeuristic::SetNumUsedHeuristics
void SetNumUsedHeuristics(int count)
Definition: GraphEnvironment.h:271
InstallCommandLineHandler
void InstallCommandLineHandler(CommandLineCallback CLC, const char *arg, const char *param, const char *usage)
Definition: Common.cpp:207
Graph
A generic Graph class.
Definition: Graph.h:66
bSaveAndQuit
bool bSaveAndQuit
Definition: Sample.cpp:27
xyLoc::x
uint16_t x
Definition: Map2DEnvironment.h:41
TemplateAStar::GetPath
void GetPath(environment *env, const state &from, const state &to, std::vector< state > &thePath)
Perform an A* search between two states.
Definition: TemplateAStar.h:214
viewport
Definition: Common.h:56
gdh
GraphDistanceHeuristic * gdh
Definition: Sample.cpp:38
gStepsPerFrame
int gStepsPerFrame
Definition: Sample.cpp:31
GraphEnvironment::SetDirected
void SetDirected(bool b)
Definition: GraphEnvironment.h:303
GraphDistanceHeuristic::HCost
virtual double HCost(const graphState &state1, const graphState &state2) const
Definition: GraphEnvironment.cpp:1526
SearchEnvironment::SetColor
virtual void SetColor(const rgbColor &r) const
Definition: SearchEnvironment.h:102
MapEnvironment
Definition: Map2DEnvironment.h:133
SetNumPorts
void SetNumPorts(unsigned long windowID, int count)
Definition: Common.cpp:903
loc
Definition: MapGenerators.cpp:296
InstallWindowHandler
void InstallWindowHandler(WindowCallback wC)
Definition: Common.cpp:634
Map::Scale
void Scale(long newWidth, long newHeight)
Definition: Map.cpp:177
tWindowEventType
tWindowEventType
Definition: Common.h:158
kMouseDrag
@ kMouseDrag
Definition: Common.h:154
RemoveFrameHandler
void RemoveFrameHandler(FrameCallback glCall, unsigned long windowID, void *userdata)
Definition: Common.cpp:148
MyDisplayHandler
void MyDisplayHandler(unsigned long windowID, tKeyboardModifier mod, char key)
Definition: Sample.cpp:258
point3d
#define point3d
Definition: GLUtil.h:123
SearchEnvironment::GetPathLength
virtual double GetPathLength(std::vector< state > &neighbors)
Definition: SearchEnvironment.h:144
kAvoidPlacement
@ kAvoidPlacement
Definition: GraphEnvironment.h:219
kAnyModifier
@ kAnyModifier
Definition: Common.h:138
kRandom
@ kRandom
Definition: GraphEnvironment.h:257
SetActivePort
void SetActivePort(unsigned long windowID, int which)
Definition: Common.cpp:935
fless
bool fless(double a, double b)
Definition: FPUtil.h:28
kMouseDown
@ kMouseDown
Definition: Common.h:152
MyCLHandler
int MyCLHandler(char *argument[], int maxNumArgs)
Definition: Sample.cpp:226
py2
int py2
Definition: Sample.cpp:28
TemplateAStar
A templated version of A*, based on HOG genericAStar.
Definition: TemplateAStar.h:73
Map::SetTileSet
void SetTileSet(tTileset ts)
Choose the tileset used for land colors.
Definition: Map.cpp:1747
kRightButton
@ kRightButton
Definition: Common.h:146
TemplateAStar.h
CreateSimulation
void CreateSimulation(int id)
This function is used to allocate the unit simulated that you want to run.
Definition: Sample.cpp:56
SaveScreenshot
void SaveScreenshot(unsigned long windowID, const char *filename)
Definition: Common.cpp:970
Timer::GetElapsedTime
double GetElapsedTime()
Definition: Timer.cpp:25
EpisodicSimulation.h
a1
TemplateAStar< xyLoc, tDirection, MapEnvironment > a1
Definition: Sample.cpp:34
GraphDistanceHeuristic::SetPlacement
void SetPlacement(placementScheme s)
Definition: GraphEnvironment.h:229
MAXPORTS
const int MAXPORTS
Definition: Common.h:23
fgreater
bool fgreater(double a, double b)
Definition: FPUtil.h:29
ma2
MapEnvironment * ma2
Definition: Sample.cpp:37
Sample.h
GraphEnvironment::HCost
virtual double HCost(const graphState &state1, const graphState &state2) const
Heuristic value between two arbitrary nodes.
Definition: GraphEnvironment.cpp:157
absType
int absType
Definition: Sample.cpp:29
InstallFrameHandler
void InstallFrameHandler(FrameCallback glCall, unsigned long windowID, void *userdata)
Definition: Common.cpp:143
path
std::vector< xyLoc > path
Definition: Sample.cpp:43
kWindowDestroyed
@ kWindowDestroyed
Definition: Common.h:160
tMouseEventType
tMouseEventType
Definition: Common.h:151
MapGenerators.h
UnitSimulation
The basic simulation class for the world.
Definition: UnitSimulation.h:85
MyPathfindingKeyHandler
void MyPathfindingKeyHandler(unsigned long windowID, tKeyboardModifier, char)
Definition: Sample.cpp:379
RunHOGGUI
void RunHOGGUI(int argc, char *argv[], int windowDimension=1000)
GetNumPorts
int GetNumPorts(unsigned long windowID)
Definition: Common.cpp:923
Graph::GetRandomNode
node * GetRandomNode()
Definition: Graph.cpp:281
MakeMaze
void MakeMaze(Map *map, int corridorWidth, int startx, int starty)
MakeMaze(map)
Definition: MapGenerators.cpp:96
node::GetNum
unsigned int GetNum() const
Definition: Graph.h:176
TemplateAStar::SetUseBPMX
void SetUseBPMX(int depth)
Definition: TemplateAStar.h:122
MyWindowHandler
void MyWindowHandler(unsigned long windowID, tWindowEventType eType)
Definition: Sample.cpp:111
a2
TemplateAStar< xyLoc, tDirection, MapEnvironment > a2
Definition: Sample.cpp:35
kMinTime
@ kMinTime
Definition: UnitSimulation.h:78
px2
int px2
Definition: Sample.cpp:28
doExport
void doExport()
Definition: Sample.cpp:221
Timer
Definition: Timer.h:19
GraphDistanceHeuristic::GetGraph
Graph * GetGraph()
Definition: GraphEnvironment.h:230
Map::GetOpenGLCoord
bool GetOpenGLCoord(int _x, int _y, GLdouble &x, GLdouble &y, GLdouble &z, GLdouble &radius) const
Get the openGL coordinates of a given tile.
Definition: Map.cpp:1826
GraphSearchConstants::GetGraph
Graph * GetGraph(Map *m)
Definition: GraphEnvironment.cpp:851
py1
int py1
Definition: Sample.cpp:28
GetActivePort
int GetActivePort(unsigned long windowID)
Definition: Common.cpp:929
path
A linked list of nodes which form a continuous path.
Definition: Path.h:20
kMouseUp
@ kMouseUp
Definition: Common.h:153
main
int main(int argc, char *argv[])
Definition: Sample.cpp:45
tButtonType
tButtonType
Definition: Common.h:144
fequal
bool fequal(double a, double b, double tolerance=TOLERANCE)
Definition: FPUtil.h:32
gdh2
GraphDistanceHeuristic * gdh2
Definition: Sample.cpp:39
InstallMouseClickHandler
void InstallMouseClickHandler(MouseCallback mC, tMouseEventType which)
Definition: Common.cpp:255
GraphDistanceHeuristic::OpenGLDraw
virtual void OpenGLDraw() const
Definition: GraphEnvironment.cpp:1477
mazeSize
int mazeSize
Definition: Sample.cpp:30
Timer::EndTimer
double EndTimer()
Definition: Timer.cpp:15
Map::Save
void Save(std::stringstream &data)
unimplemented.
Definition: Map.cpp:831
InstallHandlers
void InstallHandlers()
Allows you to install any keyboard handlers needed for program interaction.
Definition: Sample.cpp:85
GraphEnvironment
Definition: GraphEnvironment.h:291
gDefaultMap
char gDefaultMap[1024]
Definition: Common.cpp:29
Map
A tile-based representation of the world.
Definition: Map.h:142
GraphEnvironment.h
px1
int px1
Definition: Sample.cpp:28