HOG2
CanonicalGrid.cpp
Go to the documentation of this file.
1 //
2 // CanonicalGrid.cpp
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 7/30/15.
6 // Copyright (c) 2015 University of Denver. All rights reserved.
7 //
8 
9 #include "CanonicalGrid.h"
10 #include "SVGUtil.h"
11 #include "Graphics.h"
12  #include <string.h>
13 
14 namespace CanonicalGrid {
15 
16  using namespace Graphics;
17 
19  {
20  DIAGONAL_COST = ROOT_TWO;
21  map = _m;
22  fourConnected = false;
23  grid.resize(_m->GetMapWidth()*_m->GetMapHeight());
24  for (int x = 0; x < _m->GetMapWidth(); x++)
25  {
26  for (int y = 0; y < _m->GetMapHeight(); y++)
27  {
28  if ((_m->GetTerrainType(x, y)>>terrainBits) == (kGround>>terrainBits))
29  grid[x+y*_m->GetMapWidth()] = true;
30  else
31  grid[x+y*_m->GetMapWidth()] = false;
32  }
33  }
34  }
35 
36  void CanonicalGrid::GetSuccessors(const xyLoc &loc, std::vector<xyLoc> &neighbors) const
37  {
38  neighbors.resize(0);
39  bool n1 = false, s1 = false, e1 = false, w1 = false;
40 
41  int w = map->GetMapWidth();
42  int h = map->GetMapHeight();
43  if (fourConnected)
44  {
45  printf("Four connected not implemented!\n");
46  assert(false);
47  }
48  else {
49  if (loc.parent&kN) // action that got me here
50  {
51  if (loc.y != 0 && grid[loc.x+(loc.y-1)*w])
52  {
53  bool a = false, b = false;
54  if (loc.x != 0 && !grid[loc.x-1+(loc.y)*w] && grid[loc.x-1+(loc.y-1)*w])
55  a = true;
56  if (loc.x != w-1 && !grid[loc.x+1+(loc.y)*w] && grid[loc.x+1+(loc.y-1)*w])
57  b = true;
58 
59  if (a && b)
60  neighbors.push_back(xyLoc(loc.x, loc.y-1, tDirection(kNW|kE)));
61  else if (a)
62  neighbors.push_back(xyLoc(loc.x, loc.y-1, kNW));
63  else if (b)
64  neighbors.push_back(xyLoc(loc.x, loc.y-1, kNE));
65  else
66  neighbors.push_back(xyLoc(loc.x, loc.y-1, kN));
67  n1 = true;
68  }
69  }
70  if (loc.parent&kW) // action that got me here
71  {
72  if (loc.x != 0 && grid[loc.x-1+(loc.y)*w])
73  {
74  bool a = false, b = false;
75  if (loc.y != 0 && !grid[loc.x+(loc.y-1)*w] && grid[loc.x-1+(loc.y-1)*w])
76  a = true;
77  if (loc.y != h-1 && !grid[loc.x+(loc.y+1)*w] && grid[loc.x-1+(loc.y+1)*w])
78  b = true;
79 
80  if (a && b)
81  neighbors.push_back(xyLoc(loc.x-1, loc.y, tDirection(kNW|kS)));
82  else if (a)
83  neighbors.push_back(xyLoc(loc.x-1, loc.y, kNW));
84  else if (b)
85  neighbors.push_back(xyLoc(loc.x-1, loc.y, kSW));
86  else
87  neighbors.push_back(xyLoc(loc.x-1, loc.y, kW));
88  e1 = true;
89  }
90  }
91  if (loc.parent&kS) // action that got me here
92  {
93  if (loc.y != h-1 && grid[loc.x+(loc.y+1)*w])
94  {
95  bool a = false, b = false;
96  if (loc.x != 0 && !grid[loc.x-1+(loc.y)*w] && grid[loc.x-1+(loc.y+1)*w])
97  a = true;
98  if (loc.x != w-1 && !grid[loc.x+1+(loc.y)*w] && grid[loc.x+1+(loc.y+1)*w])
99  b = true;
100 
101  if (a && b)
102  neighbors.push_back(xyLoc(loc.x, loc.y+1, tDirection(kSE|kW)));
103  else if (a)
104  neighbors.push_back(xyLoc(loc.x, loc.y+1, kSW));
105  else if (b)
106  neighbors.push_back(xyLoc(loc.x, loc.y+1, kSE));
107  else
108  neighbors.push_back(xyLoc(loc.x, loc.y+1, kS));
109  s1 = true;
110  }
111  }
112  if (loc.parent&kE) // action that got me here
113  {
114  if (loc.x != w-1 && grid[loc.x+1+(loc.y)*w])
115  {
116  bool a = false, b = false;
117 
118  if (loc.y != 0 && !grid[loc.x+(loc.y-1)*w] && grid[loc.x+1+(loc.y-1)*w])
119  a = true;
120  if (loc.y != h-1 && !grid[loc.x+(loc.y+1)*w] && grid[loc.x+1+(loc.y+1)*w])
121  b = true;
122 
123  if (a && b)
124  neighbors.push_back(xyLoc(loc.x+1, loc.y, tDirection(kNE|kS)));
125  else if (a)
126  neighbors.push_back(xyLoc(loc.x+1, loc.y, kNE));
127  else if (b)
128  neighbors.push_back(xyLoc(loc.x+1, loc.y, kSE));
129  else
130  neighbors.push_back(xyLoc(loc.x+1, loc.y, kE));
131  w1 = true;
132  }
133  }
134  if (loc.parent&kNW)
135  {
136  if (loc.x != 0 && loc.y != 0 && grid[loc.x-1+(loc.y-1)*w] && n1 && e1)
137  {
138  neighbors.push_back(xyLoc(loc.x-1, loc.y-1, kNW));
139  }
140  }
141  if (loc.parent&kNE)
142  {
143  if (loc.x != w-1 && loc.y != 0 && grid[loc.x+1+(loc.y-1)*w] && n1 && w1)
144  {
145  neighbors.push_back(xyLoc(loc.x+1, loc.y-1, kNE));
146  }
147  }
148  if (loc.parent&kSW)
149  {
150  if (loc.x != 0 && loc.y != h-1 && grid[loc.x-1+(loc.y+1)*w] && s1 && e1)
151  {
152  neighbors.push_back(xyLoc(loc.x-1, loc.y+1, kSW));
153  }
154  }
155  if (loc.parent&kSE)
156  {
157  if (loc.x != w-1 && loc.y != h-1 && grid[loc.x+1+(loc.y+1)*w] && s1 && w1)
158  {
159  neighbors.push_back(xyLoc(loc.x+1, loc.y+1, kSE));
160  }
161  }
162  }
163  }
164 
165  void CanonicalGrid::GetFirstJumpPoints(const xyLoc &loc, std::vector<xyLoc> &neighbors) const
166  {
167  neighbors.resize(0);
168  std::vector<xyLoc> oneSuccessor;
169  std::vector<xyLoc> multipleSuccessors;
170  std::vector<xyLoc> succ;
171 
172  multipleSuccessors.push_back(loc);
173  while (multipleSuccessors.size() > 0)
174  {
175  xyLoc tmp = multipleSuccessors.back();
176  multipleSuccessors.pop_back();
177  GetSuccessors(tmp, succ);
178  if (succ.size() == 1)
179  {
180  oneSuccessor.push_back(succ[0]);
181  }
182  else if (succ.size() > 0) {
183  multipleSuccessors.insert( multipleSuccessors.end(), succ.begin(),succ.end());
184  }
185  }
186  while (oneSuccessor.size() > 0)
187  {
188  xyLoc tmp = oneSuccessor.back();
189  oneSuccessor.pop_back();
190  GetSuccessors(tmp, succ);
191  if (succ.size() == 1)
192  {
193  oneSuccessor.push_back(succ[0]);
194  }
195  else if (succ.size() > 0){ // it's a jump point
196  neighbors.push_back(tmp);
197  }
198  }
199  }
200 
201  void CanonicalGrid::GetBasicSuccessors(const xyLoc &loc, std::vector<xyLoc> &neighbors) const
202  {
203  neighbors.resize(0);
204  bool n1 = false, s1 = false, e1 = false, w1 = false;
205 
206  int w = map->GetMapWidth();
207  int h = map->GetMapHeight();
208  if (fourConnected)
209  {
210  printf("Four connected not implemented!\n");
211  assert(false);
212  }
213  else {
214  if (loc.parent&kN) // action that got me here
215  {
216  if (loc.y != 0 && grid[loc.x+(loc.y-1)*w])
217  {
218  neighbors.push_back(xyLoc(loc.x, loc.y-1, kN));
219  n1 = true;
220  }
221  }
222  if (loc.parent&kW) // action that got me here
223  {
224  if (loc.x != 0 && grid[loc.x-1+(loc.y)*w])
225  {
226  neighbors.push_back(xyLoc(loc.x-1, loc.y, kW));
227  e1 = true;
228  }
229  }
230  if (loc.parent&kS) // action that got me here
231  {
232  if (loc.y != h-1 && grid[loc.x+(loc.y+1)*w])
233  {
234  neighbors.push_back(xyLoc(loc.x, loc.y+1, kS));
235  s1 = true;
236  }
237  }
238  if (loc.parent&kE) // action that got me here
239  {
240  if (loc.x != w-1 && grid[loc.x+1+(loc.y)*w])
241  {
242  neighbors.push_back(xyLoc(loc.x+1, loc.y, kE));
243  w1 = true;
244  }
245  }
246  if (loc.parent&kNW)
247  {
248  if (loc.x != 0 && loc.y != 0 && grid[loc.x-1+(loc.y-1)*w] && n1 && e1)
249  {
250  neighbors.push_back(xyLoc(loc.x-1, loc.y-1, kNW));
251  }
252  }
253  if (loc.parent&kNE)
254  {
255  if (loc.x != w-1 && loc.y != 0 && grid[loc.x+1+(loc.y-1)*w] && n1 && w1)
256  {
257  neighbors.push_back(xyLoc(loc.x+1, loc.y-1, kNE));
258  }
259  }
260  if (loc.parent&kSW)
261  {
262  if (loc.x != 0 && loc.y != h-1 && grid[loc.x-1+(loc.y+1)*w] && s1 && e1)
263  {
264  neighbors.push_back(xyLoc(loc.x-1, loc.y+1, kSW));
265  }
266  }
267  if (loc.parent&kSE)
268  {
269  if (loc.x != w-1 && loc.y != h-1 && grid[loc.x+1+(loc.y+1)*w] && s1 && w1)
270  {
271  neighbors.push_back(xyLoc(loc.x+1, loc.y+1, kSE));
272  }
273  }
274  }
275 
276  }
277  void CanonicalGrid::GetActions(const xyLoc &loc, std::vector<tDirection> &actions) const
278  {
279  actions.clear();
280  bool up=false, down=false;
281  if ((map->CanStep(loc.x, loc.y, loc.x, loc.y+1)))
282  {
283  down = true;
284  actions.push_back(kS);
285  }
286  if ((map->CanStep(loc.x, loc.y, loc.x, loc.y-1)))
287  {
288  up = true;
289  actions.push_back(kN);
290  }
291  if ((map->CanStep(loc.x, loc.y, loc.x-1, loc.y)))
292  {
293  if (!fourConnected)
294  {
295  if ((up && (map->CanStep(loc.x, loc.y, loc.x-1, loc.y-1))))
296  actions.push_back(kNW);
297  if ((down && (map->CanStep(loc.x, loc.y, loc.x-1, loc.y+1))))
298  actions.push_back(kSW);
299  }
300  actions.push_back(kW);
301  }
302  if ((map->CanStep(loc.x, loc.y, loc.x+1, loc.y)))
303  {
304  if (!fourConnected)
305  {
306  if ((up && (map->CanStep(loc.x, loc.y, loc.x+1, loc.y-1))))
307  actions.push_back(kNE);
308  if ((down && (map->CanStep(loc.x, loc.y, loc.x+1, loc.y+1))))
309  actions.push_back(kSE);
310  }
311  actions.push_back(kE);
312  }
313  }
314 
315  tDirection CanonicalGrid::GetAction(const xyLoc &s1, const xyLoc &s2) const
316  {
317  int result = kStay;
318  switch (s1.x-s2.x)
319  {
320  case -1: result = kE; break;
321  case 0: break;
322  case 1: result = kW; break;
323  }
324 
325  // Tack the vertical move onto it
326  // Notice the exploit of particular encoding of kStay, kE, etc. labels
327  switch (s1.y-s2.y)
328  {
329  case -1: result = result|kS; break;
330  case 0: break;
331  case 1: result = result|kN; break;
332  }
333  return (tDirection)result;
334  }
335 
337  {
338  switch (a)
339  {
340  case kN: a = kS; break;
341  case kNE: a = kSW; break;
342  case kE: a = kW; break;
343  case kSE: a = kNW; break;
344  case kS: a = kN; break;
345  case kSW: a = kNE; break;
346  case kW: a = kE; break;
347  case kNW: a = kSE; break;
348  default: break;
349  }
350  return true;
351  }
352 
354  {
355  //xyLoc old = s;
356  switch (dir)
357  {
358  case kN: s.y-=1; break;
359  case kS: s.y+=1; break;
360  case kE: s.x+=1; break;
361  case kW: s.x-=1; break;
362  case kNW: s.y-=1; s.x-=1; break;
363  case kSW: s.y+=1; s.x-=1; break;
364  case kNE: s.y-=1; s.x+=1; break;
365  case kSE: s.y+=1; s.x+=1; break;
366  default: break;
367  }
368  }
369 
370  double CanonicalGrid::HCost(const xyLoc &l1, const xyLoc &l2) const
371  {
372  double h1;//, h2;
373  if (fourConnected)
374  {
375  h1 = abs(l1.x-l2.x)+abs(l1.y-l2.y);
376  }
377  else {
378  double a = ((l1.x>l2.x)?(l1.x-l2.x):(l2.x-l1.x));
379  double b = ((l1.y>l2.y)?(l1.y-l2.y):(l2.y-l1.y));
380  //return sqrt(a*a+b*b);
381  h1 = (a>b)?(b*DIAGONAL_COST+a-b):(a*DIAGONAL_COST+b-a);
382  }
383 
384  return h1;
385  }
386 
387  double CanonicalGrid::GCost(const xyLoc &l, const tDirection &act) const
388  {
389  const double multiplier = 1.0;
390  switch (act)
391  {
392  case kN: return 1.0*multiplier;
393  case kS: return 1.0*multiplier;
394  case kE: return 1.0*multiplier;
395  case kW: return 1.0*multiplier;
396  case kNW: return DIAGONAL_COST*multiplier;
397  case kSW: return DIAGONAL_COST*multiplier;
398  case kNE: return DIAGONAL_COST*multiplier;
399  case kSE: return DIAGONAL_COST*multiplier;
400  default: return 0;
401  }
402  return 0;
403  }
404 
405  double CanonicalGrid::GCost(const xyLoc &l1, const xyLoc &l2) const
406  {
407  const double multiplier = 1.0;
408  if (l1.x == l2.x) return 1.0*multiplier;
409  if (l1.y == l2.y) return 1.0*multiplier;
410  if (l1 == l2) return 0.0;
411  return DIAGONAL_COST*multiplier;
412  }
413 
414  bool CanonicalGrid::GoalTest(const xyLoc &node, const xyLoc &goal) const
415  {
416  return ((node.x == goal.x) && (node.y == goal.y));
417  }
418 
419  uint64_t CanonicalGrid::GetMaxHash() const
420  {
421  return map->GetMapHeight()*map->GetMapWidth();
422 
423  }
424 
425  uint64_t CanonicalGrid::GetStateHash(const xyLoc &node) const
426  {
427  return node.y*map->GetMapWidth()+node.x;
428  //return (((uint64_t)node.x)<<16)|node.y;
429  // return (node.x<<16)|node.y;
430  }
431 
433  {
434  return (uint32_t) act;
435  }
436 
438  {
439  map->OpenGLDraw();
440  }
441 
442  void CanonicalGrid::OpenGLDraw(const xyLoc &l) const
443  {
444  GLdouble xx, yy, zz, rad;
445  map->GetOpenGLCoord(l.x, l.y, xx, yy, zz, rad);
446  GLfloat r, g, b, t;
447  GetColor(r, g, b, t);
448  glColor4f(r, g, b, t);
449  //glColor3f(0.5, 0.5, 0.5);
450  //DrawSphere(xx, yy, zz, rad);
451  //DrawSquare(xx, yy, zz+rad, rad);
452  DrawSquare(xx, yy, zz-rad, rad);
453  }
454 
455  void CanonicalGrid::OpenGLDraw(const xyLoc &l1, const xyLoc &l2, float v) const
456  {
457  GLdouble xx, yy, zz, rad;
458  GLdouble xx2, yy2, zz2;
459  map->GetOpenGLCoord(l1.x, l1.y, xx, yy, zz, rad);
460  map->GetOpenGLCoord(l2.x, l2.y, xx2, yy2, zz2, rad);
461  xx = (1-v)*xx+v*xx2;
462  yy = (1-v)*yy+v*yy2;
463  zz = (1-v)*zz+v*zz2;
464  GLfloat r, g, b, t;
465  GetColor(r, g, b, t);
466  glColor4f(r, g, b, t);
467  DrawSquare(xx, yy, zz+rad, rad);
468  //DrawSphere(xx, yy, zz, rad);
469  }
470 
471  void CanonicalGrid::OpenGLDraw(const xyLoc& initial, const tDirection &dir) const
472  {
473 
474  xyLoc s = initial;
475  GLdouble xx, yy, zz, rad;
476  map->GetOpenGLCoord(s.x, s.y, xx, yy, zz, rad);
477 
478  glColor3f(0.5, 0.5, 0.5);
479  glBegin(GL_LINE_STRIP);
480  glVertex3f(xx, yy, zz-rad/2);
481 
482  switch (dir)
483  {
484  case kN: s.y-=1; break;
485  case kS: s.y+=1; break;
486  case kE: s.x+=1; break;
487  case kW: s.x-=1; break;
488  case kNW: s.y-=1; s.x-=1; break;
489  case kSW: s.y+=1; s.x-=1; break;
490  case kNE: s.y-=1; s.x+=1; break;
491  case kSE: s.y+=1; s.x+=1; break;
492  default: break;
493  }
494 
495 
496  map->GetOpenGLCoord(s.x, s.y, xx, yy, zz, rad);
497  glVertex3f(xx, yy, zz-rad/2);
498  glEnd();
499 
500  }
501 
502  void CanonicalGrid::GLDrawLine(const xyLoc &a, const xyLoc &b) const
503  {
504  GLdouble xx1, yy1, zz1, rad;
505  GLdouble xx2, yy2, zz2;
506  map->GetOpenGLCoord(a.x, a.y, xx1, yy1, zz1, rad);
507  map->GetOpenGLCoord(b.x, b.y, xx2, yy2, zz2, rad);
508 
509  double angle = atan2(yy1-yy2, xx1-xx2);
510  double xoff = sin(2*PI-angle)*rad*0.1;
511  double yoff = cos(2*PI-angle)*rad*0.1;
512 
513 
514 
515  GLfloat rr, gg, bb, t;
516  GetColor(rr, gg, bb, t);
517  glColor4f(rr, gg, bb, t);
518 
519  glBegin(GL_TRIANGLE_STRIP);
520 
521  glVertex3f(xx1+xoff, yy1+yoff, zz1-rad/2);
522  glVertex3f(xx2+xoff, yy2+yoff, zz2-rad/2);
523  glVertex3f(xx1-xoff, yy1-yoff, zz1-rad/2);
524  glVertex3f(xx2-xoff, yy2-yoff, zz2-rad/2);
525  glEnd();
526  }
527 
528  void CanonicalGrid::GLLabelState(const xyLoc &s, const char *str, double scale) const
529  {
530  glPushMatrix();
531 
532  GLdouble xx, yy, zz, rad;
533  map->GetOpenGLCoord(s.x, s.y, xx, yy, zz, rad);
534  GLfloat r, g, b, t;
535  GetColor(r, g, b, t);
536  glColor4f(r, g, b, t);
537 
538  glTranslatef(xx-rad, yy+rad/2, zz-2*rad);
539  glScalef(scale*rad/(300.0), scale*rad/300.0, 1);
540  glRotatef(180, 0.0, 0.0, 1.0);
541  glRotatef(180, 0.0, 1.0, 0.0);
542  glDisable(GL_LIGHTING);
543  auto len = strlen(str);
544  //for (int which = 0; which < len; which++)
545  // glutStrokeCharacter(GLUT_STROKE_ROMAN, str[which]);
546  glEnable(GL_LIGHTING);
547  glPopMatrix();
548  }
549 
550  void CanonicalGrid::GLLabelState(const xyLoc &s, const char *str) const
551  {
552  glPushMatrix();
553 
554  GLdouble xx, yy, zz, rad;
555  map->GetOpenGLCoord(s.x, s.y, xx, yy, zz, rad);
556  GLfloat r, g, b, t;
557  GetColor(r, g, b, t);
558  glColor4f(r, g, b, t);
559 
560  glTranslatef(xx-rad, yy+rad/2, zz-rad);
561  glScalef(rad/(300.0), rad/300.0, 1);
562  glRotatef(180, 0.0, 0.0, 1.0);
563  glRotatef(180, 0.0, 1.0, 0.0);
564  glDisable(GL_LIGHTING);
565  //for (int which = 0; which < strlen(str); which++)
566  // glutStrokeCharacter(GLUT_STROKE_ROMAN, str[which]);
567  glEnable(GL_LIGHTING);
568  glPopMatrix();
569  }
570 
572  {
573  std::string s;
574  // 10% margin on all sides of image
575  s = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" width = \""+std::to_string(10*map->GetMapWidth())+"\" height = \""+std::to_string(10*map->GetMapHeight())+"\" ";
576  s += "viewBox=\""+std::to_string(-map->GetMapWidth())+" "+std::to_string(-map->GetMapHeight())+" ";
577  s += std::to_string(12*map->GetMapWidth())+" "+std::to_string(12*map->GetMapHeight())+"\" ";
578  s += "preserveAspectRatio = \"none\" ";
579  s += ">\n";
580  return s;
581  }
582 
584  {
585  std::string s;
586  rgbColor black = {0.0, 0.0, 0.0};
587 
588  // draw tiles
589  for (int y = 0; y < map->GetMapHeight(); y++)
590  {
591  for (int x = 0; x < map->GetMapWidth(); x++)
592  {
593  bool draw = true;
594  if (map->GetTerrainType(x, y) == kGround)
595  {
596  rgbColor c = {0.9, 0.9, 0.9};
597  s += SVGDrawRect(x+1, y+1, 1, 1, c);
598  s += "\n";
599  }
600  else if (map->GetTerrainType(x, y) == kTrees)
601  {
602  rgbColor c = {0.0, 0.5, 0.0};
603  s += SVGDrawRect(x+1, y+1, 1, 1, c);
604  s += "\n";
605  }
606  else if (map->GetTerrainType(x, y) == kWater)
607  {
608  rgbColor c = {0.0, 0.0, 1.0};
609  s += SVGDrawRect(x+1, y+1, 1, 1, c);
610  s += "\n";
611  }
612  else if (map->GetTerrainType(x, y) == kSwamp)
613  {
614  rgbColor c = {0.0, 0.3, 1.0};
615  s += SVGDrawRect(x+1, y+1, 1, 1, c);
616  s += "\n";
617  }
618  else {
619  draw = false;
620  }
621  }
622  }
623 
624  // draw cell boundaries for open terrain
625  for (int y = 0; y < map->GetMapHeight(); y++)
626  {
627  for (int x = 0; x < map->GetMapWidth(); x++)
628  {
629  // mark cells on map
630  if ((map->GetTerrainType(x, y)>>terrainBits) == (kGround>>terrainBits))
631  {
632  rgbColor c = {0.75, 0.75, 0.75};
633  s += ::SVGFrameRect(x+1, y+1, 1, 1, 1, c);
634  s += "\n";
635  }
636  }
637  }
638 
639  // draw lines between different terrain types
640  for (int y = 0; y < map->GetMapHeight(); y++)
641  {
642  for (int x = 0; x < map->GetMapWidth(); x++)
643  {
644  bool draw = true;
645  if (map->GetTerrainType(x, y) == kGround)
646  {
647  if (x == map->GetMapWidth()-1)
648  s += ::SVGDrawLine(x+1+1, y+1, x+1+1, y+1+1, 1, black, false);
649  if (y == map->GetMapHeight()-1)
650  s += ::SVGDrawLine(x+1, y+1+1, x+1+1, y+1+1, 1, black, false);
651  }
652  else if (map->GetTerrainType(x, y) == kTrees)
653  {
654  if (x == map->GetMapWidth()-1)
655  s += ::SVGDrawLine(x+1+1, y+1, x+1+1, y+1+1, 1, black, false);
656  if (y == map->GetMapHeight()-1)
657  s += ::SVGDrawLine(x+1, y+1+1, x+1+1, y+1+1, 1, black, false);
658  }
659  else if (map->GetTerrainType(x, y) == kWater)
660  {
661  if (x == map->GetMapWidth()-1)
662  s += ::SVGDrawLine(x+1+1, y+1, x+1+1, y+1+1, 1, black, false);
663  if (y == map->GetMapHeight()-1)
664  s += ::SVGDrawLine(x+1, y+1+1, x+1+1, y+1+1, 1, black, false);
665  }
666  else if (map->GetTerrainType(x, y) == kSwamp)
667  {
668  }
669  else {
670  draw = false;
671  }
672 
673  if (draw)
674  {
675  SetColor(0.0, 0.0, 0.0);
676 
677  // Code does error checking, so this works with x == 0
678  if (map->GetTerrainType(x, y) != map->GetTerrainType(x-1, y))
679  {
680  SetColor(0.0, 0.0, 0.0);
681  s += ::SVGDrawLine(x+1, y+1, x+1, y+1+1, 1, black, false);
682  s += "\n";
683  }
684 
685  if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y-1))
686  {
687  s += ::SVGDrawLine(x+1, y+1, x+1+1, y+1, 1, black, false);
688  s += "\n";
689  }
690 
691  if (map->GetTerrainType(x, y) != map->GetTerrainType(x+1, y))
692  {
693  s += ::SVGDrawLine(x+1+1, y+1, x+1+1, y+1+1, 1, black, false);
694  s += "\n";
695  }
696 
697  if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y+1))
698  {
699  s += ::SVGDrawLine(x+1, y+1+1, x+1+1, y+1+1, 1, black, false);
700  s += "\n";
701  }
702  }
703 
704  }
705  }
706  s += "\n";
707 
708  return s;
709  }
710 
711  std::string CanonicalGrid::SVGDraw(const xyLoc &l)
712  {
713  std::string s;
714  if (map->GetTerrainType(l.x, l.y) == kGround)
715  {
716  rgbColor c;// = {0.5, 0.5, 0};
717  GLfloat t;
718  GetColor(c.r, c.g, c.b, t);
719  s += SVGDrawCircle(l.x+0.5+1, l.y+0.5+1, 0.5, c);
720  //stroke-width="1" stroke="pink" />
721  }
722  return s;
723  }
724 
725  std::string CanonicalGrid::SVGFrameRect(int left, int top, int right, int bottom, int width)
726  {
727  std::string s;
728 
729  rgbColor c;// = {0.5, 0.5, 0};
730  GLfloat t;
731  GetColor(c.r, c.g, c.b, t);
732  s += ::SVGFrameRect(left+1, top+1, right-left+1, bottom-top+1, width, c);
733 
734  return s;
735  }
736 
737  std::string CanonicalGrid::SVGLabelState(const xyLoc &l, const char *str, double scale) const
738  {
739  std::string s;
740  rgbColor c;// = {0.5, 0.5, 0};
741  GLfloat t;
742  GetColor(c.r, c.g, c.b, t);
743  s += SVGDrawText(l.x+0.5+1, l.y+0.5+1+1, str, c, scale);
744  return s;
745  // std::string s;
746  // s = "<text x=\"0\" y=\"15\" fill=\"black\">";
747  // s += str;
748  // s += "</text>";
749  // return s;
750  }
751 
752  std::string CanonicalGrid::SVGDrawLine(const xyLoc &p1, const xyLoc &p2, int width) const
753  {
754  //<line x1="0" y1="0" x2="200" y2="200" style="stroke:rgb(255,255,255);stroke-width:1" />
755  //std::string s;
756  rgbColor c;// = {0.5, 0.5, 0};
757  GLfloat t;
758  GetColor(c.r, c.g, c.b, t);
759  return ::SVGDrawLine(p1.x+1, p1.y+1, p2.x+1, p2.y+1, width, c);
760 
761  // s = "<line x1 = \"" + std::to_string(p1.x) + "\" ";
762  // s += "y1 = \"" + std::to_string(p1.y) + "\" ";
763  // s += "x2 = \"" + std::to_string(p2.x) + "\" ";
764  // s += "y2 = \"" + std::to_string(p2.y) + "\" ";
765  // s += "style=\"stroke:"+SVGGetRGB(c)+";stroke-width:"+std::to_string(width)+"\" />";
766  // return s;
767  }
768 
770  {
771  rgbColor c;
772  {
773  GLfloat r,g,b,t;
774  GetColor(r, g, b, t);
775  c = {r, g, b};
776  }
777 
778  std::deque<xyLoc> queue;
779  queue.push_back(l);
780  std::vector<xyLoc> v;
781  std::vector<bool> visited(map->GetMapHeight()*map->GetMapWidth());
782  while (!queue.empty())
783  {
784  GetBasicSuccessors(queue.front(), v);
785  for (auto &s : v)
786  {
787  if (!visited[s.x+s.y*map->GetMapWidth()])
788  {
789  queue.push_back(s);
790  }
791  // else {
792  // ma1->SetColor(1.0, 0.0, 0.0);
793  // }
794  Graphics::point p1, p2;
795  {
796  GLdouble x, y, z, r;
797  map->GetOpenGLCoord(queue.front().x, queue.front().y, x, y, z, r);
798  p1.x = x;
799  p1.y = y;
800  }
801  GLdouble r;
802  {
803  GLdouble x, y, z;
804  map->GetOpenGLCoord(s.x, s.y, x, y, z, r);
805  p2.x = x;
806  p2.y = y;
807  }
808  disp.DrawLine(p1, p2, r*0.1, c);
809  visited[s.x+s.y*map->GetMapWidth()] = true;
810  }
811  queue.pop_front();
812  } }
813 
815  {
816  rgbColor c;
817  {
818  GLfloat r,g,b,t;
819  GetColor(r, g, b, t);
820  c = {r, g, b};
821  }
822 
823 
824 
825  std::deque<xyLoc> queue;
826  queue.push_back(l);
827  std::vector<xyLoc> v;
828  std::vector<bool> visited(map->GetMapHeight()*map->GetMapWidth());
829  while (!queue.empty())
830  {
831  GetSuccessors(queue.front(), v);
832  for (auto &s : v)
833  {
834  if (!visited[s.x+s.y*map->GetMapWidth()])
835  {
836  queue.push_back(s);
837  }
838 // else {
839 // ma1->SetColor(1.0, 0.0, 0.0);
840 // }
841  Graphics::point p1, p2;
842  {
843  GLdouble x, y, z, r;
844  map->GetOpenGLCoord(queue.front().x, queue.front().y, x, y, z, r);
845  p1.x = x;
846  p1.y = y;
847  }
848  GLdouble r;
849  {
850  GLdouble x, y, z;
851  map->GetOpenGLCoord(s.x, s.y, x, y, z, r);
852  p2.x = x;
853  p2.y = y;
854  }
855  disp.DrawLine(p1, p2, r*0.1, c);
856  visited[s.x+s.y*map->GetMapWidth()] = true;
857  }
858  queue.pop_front();
859  }
860  }
861 
863  {
864  //rgbColor black = {0.0, 0.0, 0.0};
865 
866  // s += SVGFrameRect(PointToSVG(o.r.left, width), PointToSVG(o.r.top, height),
867  // PointToSVG(o.r.right, width)-PointToSVG(o.r.left, width),
868  // PointToSVG(o.r.top, height)-PointToSVG(o.r.bottom, height),
869 
870  disp.FillRect({-1, -1, 1, 1}, Colors::black);
871  // std::vector<point> frame;
872  // frame.push_back({-1, -1});
873  // frame.push_back({-1, 1});
874  // frame.push_back({1, 1});
875  // frame.push_back({1, -1});
876  // frame.push_back({-1, -1});
877  // disp.DrawLineSegments(frame, 1, Colors::black);
878 
879  // draw tiles
880  if (1)
881  for (int y = 0; y < map->GetMapHeight(); y++)
882  {
883  for (int x = 0; x < map->GetMapWidth(); x++)
884  {
885  bool draw = true;
886  Graphics::rect r;
887  GLdouble px, py, t, rad;
888  map->GetOpenGLCoord(x, y, px, py, t, rad);
889  r.left = px-rad;
890  r.top = py-rad;
891  r.right = px+rad;
892  r.bottom = py+rad;
893 
894  if (map->GetTerrainType(x, y) == kGround)
895  {
896  rgbColor c = {0.9, 0.9, 0.9};
897  disp.FillRect(r, c);
898  }
899  else if (map->GetTerrainType(x, y) == kTrees)
900  {
901  rgbColor c = {0.0, 0.5, 0.0};
902  disp.FillRect(r, c);
903  }
904  else if (map->GetTerrainType(x, y) == kWater)
905  {
906  rgbColor c = {0.0, 0.0, 1.0};
907  disp.FillRect(r, c);
908  }
909  else if (map->GetTerrainType(x, y) == kSwamp)
910  {
911  rgbColor c = {0.0, 0.3, 1.0};
912  disp.FillRect(r, c);
913  }
914  else {
915  // rgbColor c = {0.0, 0.0, 0.0};
916  // disp.FillRect(r, c);
917  draw = false;
918  }
919  }
920  }
921 
922  // draw cell boundaries for open terrain
923  if (0)
924  for (int y = 0; y < map->GetMapHeight(); y++)
925  {
926  for (int x = 0; x < map->GetMapWidth(); x++)
927  {
928  // mark cells on map
929  if ((map->GetTerrainType(x, y)>>terrainBits) == (kGround>>terrainBits))
930  {
931  rgbColor c = {0.75, 0.75, 0.75};
932  rect r;
933  GLdouble px, py, t, rad;
934  map->GetOpenGLCoord(x, y, px, py, t, rad);
935  r.left = px-rad;
936  r.top = py-rad;
937  r.right = px+rad;
938  r.bottom = py+rad;
939  disp.FrameRect(r, c, 1);
940  }
941  }
942  }
943 
944  // draw lines between different terrain types
945  if (1)
946  {
947  std::vector<std::pair<point, point>> lines;
948  for (int y = 0; y < map->GetMapHeight(); y++)
949  {
950  for (int x = 0; x < map->GetMapWidth(); x++)
951  {
952  GLdouble px1, py1, t1, rad1;
953  map->GetOpenGLCoord(x, y, px1, py1, t1, rad1);
954  float px=static_cast<float>(px1);
955  float py=static_cast<float>(py1);
956  float t=static_cast<float>(t1);
957  float rad=static_cast<float>(rad1);
958 
959  bool draw = true;
960  if ((map->GetTerrainType(x, y) == kGround) ||
961  (map->GetTerrainType(x, y) == kTrees) ||
962  (map->GetTerrainType(x, y) == kWater))
963  {
964  if (x == map->GetMapWidth()-1)
965  {
966  point s = {px+rad, py-rad};
967  point g = {px+rad, py+rad};
968  //disp.DrawLine(s, g, 1, Colors::black);
969  lines.push_back({s, g});
970  }
971  if (y == map->GetMapHeight()-1)
972  {
973  point s = {px-rad, py+rad};
974  point g = {px+rad, py+rad};
975  //disp.DrawLine(s, g, 1, Colors::black);
976  lines.push_back({s, g});
977  }
978  }
979  else if (map->GetTerrainType(x, y) == kSwamp)
980  {
981  }
982  else {
983  draw = false;
984  }
985 
986  if (draw)
987  {
988  // Code does error checking, so this works with x == 0
989  if (map->GetTerrainType(x, y) != map->GetTerrainType(x-1, y))
990  {
991  point s = {px-rad, py-rad};
992  point g = {px-rad, py+rad};
993  //disp.DrawLine(s, g, 1, Colors::black);
994  lines.push_back({s, g});
995  }
996 
997  if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y-1))
998  {
999  point s = {px-rad, py-rad};
1000  point g = {px+rad, py-rad};
1001  //disp.DrawLine(s, g, 1, Colors::black);
1002  lines.push_back({s, g});
1003  }
1004 
1005  if (map->GetTerrainType(x, y) != map->GetTerrainType(x+1, y))
1006  {
1007  point s = {px+rad, py-rad};
1008  point g = {px+rad, py+rad};
1009  //disp.DrawLine(s, g, 1, Colors::black);
1010  lines.push_back({s, g});
1011  }
1012 
1013  if (map->GetTerrainType(x, y) != map->GetTerrainType(x, y+1))
1014  {
1015  point s = {px-rad, py+rad};
1016  point g = {px+rad, py+rad};
1017  //disp.DrawLine(s, g, 1, Colors::black);
1018  lines.push_back({s, g});
1019  }
1020  }
1021 
1022  }
1023  }
1024  std::vector<point> points;
1025  while (lines.size() > 0)
1026  {
1027  points.resize(0);
1028  // Inefficient n^2 algorithm for now
1029  points.push_back(lines.back().first);
1030  points.push_back(lines.back().second);
1031  lines.pop_back();
1032  bool found;
1033  do {
1034  found = false;
1035  for (size_t x = 0; x < lines.size(); x++)
1036  {
1037  if (lines[x].first == points.back())
1038  {
1039  points.push_back(lines[x].second);
1040  lines.erase(lines.begin()+x);
1041  found = true;
1042  break;
1043  }
1044  if (lines[x].second == points.back())
1045  {
1046  points.push_back(lines[x].first);
1047  lines.erase(lines.begin()+x);
1048  found = true;
1049  break;
1050  }
1051  }
1052  } while (found);
1053  disp.DrawLineSegments(points, 1, Colors::black);
1054  }
1055  }
1056  }
1057 
1058  void CanonicalGrid::Draw(Graphics::Display &disp, const xyLoc &l) const
1059  {
1060  GLdouble px, py, pz, rad;
1061  map->GetOpenGLCoord(l.x, l.y, px, py, pz, rad);
1062 
1063  //if (map->GetTerrainType(l.x, l.y) == kGround)
1064  {
1065  rgbColor c;// = {0.5, 0.5, 0};
1066  GLfloat t;
1067  GetColor(c.r, c.g, c.b, t);
1068 
1069 // rect r;
1070 // r.left = px-rad;
1071 // r.top = py-rad;
1072 // r.right = px+rad;
1073 // r.bottom = py+rad;
1074 
1075  //s += SVGDrawCircle(l.x+0.5+1, l.y+0.5+1, 0.5, c);
1076 // disp.FillCircle(r, c);
1077  disp.FillCircle({static_cast<float>(px), static_cast<float>(py)}, rad, c);
1078  //stroke-width="1" stroke="pink" />
1079  }
1080  }
1081 
1082  void CanonicalGrid::Draw(Graphics::Display &disp, const xyLoc &l1, const xyLoc &l2, float v) const
1083  {
1084  rect r1, r2;
1085  rgbColor c;// = {0.5, 0.5, 0};
1086  GLfloat t;
1087  GetColor(c.r, c.g, c.b, t);
1088 
1089  {
1090  GLdouble px, py, t, rad;
1091  map->GetOpenGLCoord(l1.x, l1.y, px, py, t, rad);
1092 
1093  rect r;
1094  r.left = px-rad;
1095  r.top = py-rad;
1096  r.right = px+rad;
1097  r.bottom = py+rad;
1098  r1 = r;
1099  }
1100  {
1101  GLdouble px, py, t, rad;
1102  map->GetOpenGLCoord(l2.x, l2.y, px, py, t, rad);
1103 
1104  rect r;
1105  r.left = px-rad;
1106  r.top = py-rad;
1107  r.right = px+rad;
1108  r.bottom = py+rad;
1109  r2 = r;
1110  }
1111  rect r;
1112  v = 1-v;
1113  r.left = v*r1.left+r2.left*(1-v);
1114  r.right = v*r1.right+r2.right*(1-v);
1115  r.top = v*r1.top+r2.top*(1-v);
1116  r.bottom = v*r1.bottom+r2.bottom*(1-v);
1117  disp.FrameCircle(r, c, 2);
1118  }
1119 
1120 
1122  {
1123  GLdouble px, py, t, rad;
1124  map->GetOpenGLCoord(l.x, l.y, px, py, t, rad);
1125 
1126  //if (map->GetTerrainType(l.x, l.y) == kGround)
1127  {
1128  rgbColor c;// = {0.5, 0.5, 0};
1129  GLfloat t;
1130  GetColor(c.r, c.g, c.b, t);
1131 
1132  rect r;
1133  r.left = px-rad;
1134  r.top = py-rad;
1135  r.right = px+rad;
1136  r.bottom = py+rad;
1137 
1138  disp.FrameCircle(r, c, 2);
1139  }
1140  }
1141 
1142  void CanonicalGrid::DrawStateLabel(Graphics::Display &disp, const xyLoc &l, const char *txt) const
1143  {
1144  GLdouble px, py, t, rad;
1145  map->GetOpenGLCoord(l.x, l.y, px, py, t, rad);
1146 
1147  rgbColor c;
1148  {
1149  GLfloat t;
1150  GetColor(c.r, c.g, c.b, t);
1151  }
1152  disp.DrawText(txt, {static_cast<float>(px), static_cast<float>(py)}, c, rad);
1153  }
1154 
1155  void CanonicalGrid::DrawStateLabel(Graphics::Display &disp, const xyLoc &l1, const xyLoc &l2, float v, const char *txt) const
1156  {
1157  Graphics::point p;
1158  GLdouble rad;
1159  {
1160  GLdouble px, py, t;
1161  map->GetOpenGLCoord(l1.x, l1.y, px, py, t, rad);
1162  p.x = px;
1163  p.y = py;
1164  }
1165  {
1166  GLdouble px, py, t, rad;
1167  map->GetOpenGLCoord(l2.x, l2.y, px, py, t, rad);
1168  p.x = (1-v)*p.x + (v)*px;
1169  p.y = (1-v)*p.y + (v)*py;
1170  }
1171  rgbColor c;
1172  {
1173  GLfloat t;
1174  GetColor(c.r, c.g, c.b, t);
1175  }
1176  disp.DrawText(txt, p, c, rad);
1177  }
1178 
1179 
1180  void CanonicalGrid::DrawLine(Graphics::Display &disp, const xyLoc &a, const xyLoc &b, double width) const
1181  {
1182  GLdouble xx1, yy1, zz1, rad;
1183  GLdouble xx2, yy2, zz2;
1184  map->GetOpenGLCoord(a.x, a.y, xx1, yy1, zz1, rad);
1185  map->GetOpenGLCoord(b.x, b.y, xx2, yy2, zz2, rad);
1186 
1187  rgbColor c;// = {0.5, 0.5, 0};
1188  GLfloat t;
1189  GetColor(c.r, c.g, c.b, t);
1190 
1191  disp.DrawLine({static_cast<float>(xx1), static_cast<float>(yy1)},
1192  {static_cast<float>(xx2), static_cast<float>(yy2)}, width, c);
1193  }
1194 
1195  void CanonicalGrid::DrawArrow(Graphics::Display &disp, const xyLoc &a, const xyLoc &b, double width) const
1196  {
1197  GLdouble xx1, yy1, zz1, rad;
1198  GLdouble xx2, yy2, zz2;
1199  map->GetOpenGLCoord(a.x, a.y, xx1, yy1, zz1, rad);
1200  map->GetOpenGLCoord(b.x, b.y, xx2, yy2, zz2, rad);
1201 
1202  rgbColor c;// = {0.5, 0.5, 0};
1203  GLfloat t;
1204  GetColor(c.r, c.g, c.b, t);
1205 
1206  disp.DrawArrow({static_cast<float>(xx1), static_cast<float>(yy1)},
1207  {static_cast<float>(xx2), static_cast<float>(yy2)}, width, c);
1208  }
1209 
1210  void CanonicalGrid::GetNextState(const xyLoc &currents, tDirection dir, xyLoc &news) const
1211  {
1212  news = currents;
1213  switch (dir)
1214  {
1215  case kN: news.y-=1; break;
1216  case kS: news.y+=1; break;
1217  case kE: news.x+=1; break;
1218  case kW: news.x-=1; break;
1219  case kNW: news.y-=1; news.x-=1; break;
1220  case kSW: news.y+=1; news.x-=1; break;
1221  case kNE: news.y-=1; news.x+=1; break;
1222  case kSE: news.y+=1; news.x+=1; break;
1223  default: break;
1224  }
1225  }
1226 
1227 }
Graphics::Display::DrawLine
void DrawLine(point start, point end, float lineWidth, rgbColor c)
Definition: Graphics.cpp:184
CanonicalGrid::CanonicalGrid::DrawStateLabel
virtual void DrawStateLabel(Graphics::Display &disp, const xyLoc &l1, const char *txt) const
Definition: CanonicalGrid.cpp:1142
Graphics::point
Definition: Graphics.h:32
loc::x
int x
Definition: MapGenerators.cpp:296
Graphics::point::y
float y
Definition: Graphics.h:36
Colors::GetColor
rgbColor GetColor(float v, float vmin, float vmax, int type)
Given min/max values, get a color from a color schema.
Definition: Colors.cpp:24
CanonicalGrid::CanonicalGrid::GetActions
void GetActions(const xyLoc &nodeID, std::vector< tDirection > &actions) const
Definition: CanonicalGrid.cpp:277
DrawSquare
void DrawSquare(GLdouble xx, GLdouble yy, GLdouble zz, GLdouble rad)
Definition: GLUtil.cpp:396
CanonicalGrid::CanonicalGrid::GetActionHash
uint64_t GetActionHash(tDirection act) const
Definition: CanonicalGrid.cpp:432
rgbColor::b
float b
Definition: Colors.h:71
rgbColor
A color; r/g/b are between 0...1.
Definition: Colors.h:17
CanonicalGrid::CanonicalGrid::SVGLabelState
std::string SVGLabelState(const xyLoc &, const char *, double scale) const
Definition: CanonicalGrid.cpp:737
terrainBits
const int terrainBits
Definition: Map.h:49
CanonicalGrid::kW
@ kW
Definition: CanonicalGrid.h:26
CanonicalGrid::kSE
@ kSE
Definition: CanonicalGrid.h:27
loc::y
int y
Definition: MapGenerators.cpp:296
kTrees
@ kTrees
Definition: Map.h:59
CanonicalGrid::CanonicalGrid::GetFirstJumpPoints
void GetFirstJumpPoints(const xyLoc &nodeID, std::vector< xyLoc > &neighbors) const
Definition: CanonicalGrid.cpp:165
CanonicalGrid::kN
@ kN
Definition: CanonicalGrid.h:26
CanonicalGrid::CanonicalGrid::GoalTest
bool GoalTest(const xyLoc &node, const xyLoc &goal) const
Definition: CanonicalGrid.cpp:414
CanonicalGrid::kE
@ kE
Definition: CanonicalGrid.h:26
SVGDrawText
std::string SVGDrawText(float x1, float y1, const char *txt, rgbColor c, double size, const char *typeface, SVG::svgAlignment align, SVG::svgBaseline base)
Definition: SVGUtil.cpp:227
CanonicalGrid::CanonicalGrid::CanonicalGrid
CanonicalGrid(Map *m)
Definition: CanonicalGrid.cpp:18
CanonicalGrid::kSW
@ kSW
Definition: CanonicalGrid.h:27
CanonicalGrid::CanonicalGrid::SVGHeader
std::string SVGHeader()
Definition: CanonicalGrid.cpp:571
SVGDrawRect
std::string SVGDrawRect(float x, float y, float width, float height, const char *gradient)
Definition: SVGUtil.cpp:74
Graphics::rect
Definition: Graphics.h:94
CanonicalGrid::CanonicalGrid::DrawAlternate
virtual void DrawAlternate(Graphics::Display &disp, const xyLoc &l) const
Definition: CanonicalGrid.cpp:1121
width
int width
Definition: SFML_HOG.cpp:54
CanonicalGrid::CanonicalGrid::GetStateHash
uint64_t GetStateHash(const xyLoc &node) const
Definition: CanonicalGrid.cpp:425
CanonicalGrid::tDirection
tDirection
Definition: CanonicalGrid.h:25
rgbColor::g
float g
Definition: Colors.h:71
CanonicalGrid.h
SVGDrawCircle
std::string SVGDrawCircle(double x, double y, double radius, rgbColor c)
Definition: SVGUtil.cpp:60
CanonicalGrid::CanonicalGrid::GCost
double GCost(const xyLoc &node1, const xyLoc &node2) const
Definition: CanonicalGrid.cpp:405
CanonicalGrid::CanonicalGrid::GetAction
tDirection GetAction(const xyLoc &s1, const xyLoc &s2) const
Definition: CanonicalGrid.cpp:315
CanonicalGrid::kNW
@ kNW
Definition: CanonicalGrid.h:26
CanonicalGrid::CanonicalGrid::GetNextState
void GetNextState(const xyLoc &currents, tDirection dir, xyLoc &news) const
Definition: CanonicalGrid.cpp:1210
CanonicalGrid::CanonicalGrid::ApplyAction
void ApplyAction(xyLoc &s, tDirection dir) const
Definition: CanonicalGrid.cpp:353
kGround
@ kGround
Definition: Map.h:55
Graphics::rect::top
float top
Definition: Graphics.h:100
kSwamp
@ kSwamp
Definition: Map.h:56
loc
Definition: MapGenerators.cpp:296
CanonicalGrid::CanonicalGrid::GLLabelState
void GLLabelState(const xyLoc &, const char *) const
Definition: CanonicalGrid.cpp:550
Colors::black
const rgbColor black
Definition: Colors.h:119
CanonicalGrid::CanonicalGrid::SVGFrameRect
std::string SVGFrameRect(int left, int top, int right, int bottom, int width=1)
Definition: CanonicalGrid.cpp:725
SVGUtil.h
PI
static const double PI
Definition: GLUtil.h:66
Graphics::Display
Definition: Graphics.h:146
Graphics
Definition: Graphics.cpp:11
ROOT_TWO
static const double ROOT_TWO
Definition: GLUtil.h:61
Graphics::rect::right
float right
Definition: Graphics.h:100
Map::GetMapWidth
long GetMapWidth() const
return the width of the map
Definition: Map.h:163
CanonicalGrid::CanonicalGrid::GetBasicSuccessors
void GetBasicSuccessors(const xyLoc &nodeID, std::vector< xyLoc > &neighbors) const
Definition: CanonicalGrid.cpp:201
CanonicalGrid::CanonicalGrid::DrawBasicOrdering
void DrawBasicOrdering(::Graphics::Display &disp, const xyLoc l) const
Definition: CanonicalGrid.cpp:769
CanonicalGrid::CanonicalGrid::SVGDrawLine
std::string SVGDrawLine(const xyLoc &x, const xyLoc &y, int width=1) const
Definition: CanonicalGrid.cpp:752
Map::GetTerrainType
long GetTerrainType(long x, long y, tSplitSide split=kWholeTile) const
Get the terrain type of the (split) tile at x, y.
Definition: Map.cpp:1028
CanonicalGrid
Definition: CanonicalGrid.cpp:14
Graphics::Display::FrameCircle
void FrameCircle(rect r, rgbColor c, float lineWidth)
Definition: Graphics.cpp:110
CanonicalGrid::CanonicalGrid::DrawArrow
virtual void DrawArrow(Graphics::Display &disp, const xyLoc &x, const xyLoc &y, double width=1.0) const
Definition: CanonicalGrid.cpp:1195
CanonicalGrid::kS
@ kS
Definition: CanonicalGrid.h:26
Graphics.h
Graphics::Display::DrawArrow
void DrawArrow(point start, point end, float lineWidth, rgbColor c)
Definition: Graphics.cpp:193
rgbColor::r
float r
Definition: Colors.h:71
CanonicalGrid::xyLoc
Definition: CanonicalGrid.h:30
CanonicalGrid::CanonicalGrid::GetMaxHash
uint64_t GetMaxHash() const
Definition: CanonicalGrid.cpp:419
CanonicalGrid::kStay
@ kStay
Definition: CanonicalGrid.h:27
SVGDrawLine
std::string SVGDrawLine(float x1, float y1, float x2, float y2, float width, rgbColor c)
Definition: SVGUtil.cpp:192
CanonicalGrid::CanonicalGrid::Draw
virtual void Draw(Graphics::Display &disp) const
Definition: CanonicalGrid.cpp:862
CanonicalGrid::CanonicalGrid::InvertAction
bool InvertAction(tDirection &a) const
Definition: CanonicalGrid.cpp:336
Graphics::point::x
float x
Definition: Graphics.h:36
CanonicalGrid::kNE
@ kNE
Definition: CanonicalGrid.h:26
kWater
@ kWater
Definition: Map.h:54
Graphics::Display::FillCircle
void FillCircle(rect r, rgbColor c)
Definition: Graphics.cpp:128
Graphics::Display::FrameRect
void FrameRect(rect r, rgbColor c, float lineWidth)
Definition: Graphics.cpp:73
Map::GetMapHeight
long GetMapHeight() const
return the height of the map
Definition: Map.h:165
CanonicalGrid::CanonicalGrid::GLDrawLine
void GLDrawLine(const xyLoc &x, const xyLoc &y) const
Definition: CanonicalGrid.cpp:502
CanonicalGrid::xyLoc::y
uint16_t y
Definition: CanonicalGrid.h:35
CanonicalGrid::CanonicalGrid::OpenGLDraw
void OpenGLDraw() const
Definition: CanonicalGrid.cpp:437
CanonicalGrid::CanonicalGrid::DrawOrdering
void DrawOrdering(::Graphics::Display &disp, const xyLoc l) const
Definition: CanonicalGrid.cpp:814
Graphics::rect::left
float left
Definition: Graphics.h:100
Graphics::Display::DrawLineSegments
void DrawLineSegments(const std::vector< point > &points, float lineWidth, rgbColor c)
Definition: Graphics.cpp:230
CanonicalGrid::CanonicalGrid::DrawLine
virtual void DrawLine(Graphics::Display &disp, const xyLoc &x, const xyLoc &y, double width=1.0) const
Definition: CanonicalGrid.cpp:1180
py1
int py1
Definition: Sample.cpp:28
CanonicalGrid::CanonicalGrid::GetSuccessors
void GetSuccessors(const xyLoc &nodeID, std::vector< xyLoc > &neighbors) const
Definition: CanonicalGrid.cpp:36
Graphics::Display::DrawText
void DrawText(const char *text, point location, rgbColor c, float height, const char *typeface=0)
Definition: Graphics.cpp:221
Graphics::rect::bottom
float bottom
Definition: Graphics.h:100
Graphics::Display::FillRect
void FillRect(rect r, rgbColor c)
Definition: Graphics.cpp:101
CanonicalGrid::CanonicalGrid::SVGDraw
std::string SVGDraw()
Definition: CanonicalGrid.cpp:583
CanonicalGrid::CanonicalGrid::HCost
double HCost(const xyLoc &) const
Definition: CanonicalGrid.h:64
CanonicalGrid::xyLoc::x
uint16_t x
Definition: CanonicalGrid.h:34
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
Map
A tile-based representation of the world.
Definition: Map.h:142
SVGFrameRect
std::string SVGFrameRect(float x, float y, float width, float height, float border, rgbColor c)
Definition: SVGUtil.cpp:99
px1
int px1
Definition: Sample.cpp:28