HOG2
Map2DConstrainedEnvironment.h
Go to the documentation of this file.
1 //
2 // Map2DConstrainedEnvironment.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 8/3/12.
6 // Copyright (c) 2012 University of Denver. All rights reserved.
7 //
8 
9 #ifndef __hog2_glut__Map2DConstrainedEnvironment__
10 #define __hog2_glut__Map2DConstrainedEnvironment__
11 
12 #include <iostream>
13 
14 #include "Map2DEnvironment.h"
15 
16 struct xytLoc {
17  xytLoc(xyLoc loc, int time) :l(loc), t(time) {}
18  xytLoc() { t = 0; }
20  uint32_t t;
21 };
22 
23 struct constraint {
26 };
27 
28 static std::ostream& operator <<(std::ostream & out, const xytLoc &loc)
29 {
30  out << "(" << loc.l.x << ", " << loc.l.y << ": " << loc.t << ")";
31  return out;
32 }
33 
34 bool operator==(const xytLoc &l1, const xytLoc &l2);
35 
36 
37 class Map2DConstrainedEnvironment : public SearchEnvironment<xytLoc, tDirection>
38 {
39 public:
41  void AddConstraint(constraint c);
42  void AddConstraint(xytLoc loc);
44  void ClearConstraints();
45 
46  virtual void GetSuccessors(const xytLoc &nodeID, std::vector<xytLoc> &neighbors) const;
47  virtual void GetActions(const xytLoc &nodeID, std::vector<tDirection> &actions) const;
48  virtual tDirection GetAction(const xytLoc &s1, const xytLoc &s2) const;
49  virtual void ApplyAction(xytLoc &s, tDirection a) const;
50  virtual void UndoAction(xytLoc &s, tDirection a) const;
51 
52  virtual bool InvertAction(tDirection &a) const;
53 
55  virtual double HCost(const xytLoc &node1, const xytLoc &node2) const;
56  virtual double GCost(const xytLoc &node1, const xytLoc &node2) const { return 1; }
57  virtual double GCost(const xytLoc &node, const tDirection &act) const { return 1; }
58  virtual bool GoalTest(const xytLoc &node, const xytLoc &goal) const;
59 
60  virtual uint64_t GetStateHash(const xytLoc &node) const;
61  virtual uint64_t GetActionHash(tDirection act) const;
62 
63  virtual void OpenGLDraw() const;
64  virtual void OpenGLDraw(const xytLoc&) const;
65  virtual void OpenGLDraw(const xytLoc&, const tDirection&) const;
66  virtual void GLDrawLine(const xytLoc &x, const xytLoc &y) const;
67 private:
68  bool ViolatesConstraint(const xyLoc &from, const xyLoc &to, int time) const;
69 
70  std::vector<constraint> constraints;
72 };
73 
74 #endif /* defined(__hog2_glut__Map2DConstrainedEnvironment__) */
loc::x
int x
Definition: MapGenerators.cpp:296
Map2DConstrainedEnvironment::ApplyAction
virtual void ApplyAction(xytLoc &s, tDirection a) const
Definition: Map2DConstrainedEnvironment.cpp:109
Map2DConstrainedEnvironment::GetStateHash
virtual uint64_t GetStateHash(const xytLoc &node) const
Definition: Map2DConstrainedEnvironment.cpp:143
loc::y
int y
Definition: MapGenerators.cpp:296
Map2DConstrainedEnvironment::GCost
virtual double GCost(const xytLoc &node, const tDirection &act) const
Definition: Map2DConstrainedEnvironment.h:57
constraint::loc
xytLoc loc
Definition: Map2DConstrainedEnvironment.h:24
Map2DConstrainedEnvironment::UndoAction
virtual void UndoAction(xytLoc &s, tDirection a) const
Definition: Map2DConstrainedEnvironment.cpp:115
Map2DConstrainedEnvironment::GLDrawLine
virtual void GLDrawLine(const xytLoc &x, const xytLoc &y) const
Definition: Map2DConstrainedEnvironment.cpp:191
Map2DConstrainedEnvironment::ViolatesConstraint
bool ViolatesConstraint(const xyLoc &from, const xyLoc &to, int time) const
Definition: Map2DConstrainedEnvironment.cpp:79
xytLoc::t
uint32_t t
Definition: Map2DConstrainedEnvironment.h:20
xyLoc
Definition: Map2DEnvironment.h:37
Map2DEnvironment.h
Map2DConstrainedEnvironment::ClearConstraints
void ClearConstraints()
Definition: Map2DConstrainedEnvironment.cpp:43
Map2DConstrainedEnvironment::AddConstraint
void AddConstraint(constraint c)
Definition: Map2DConstrainedEnvironment.cpp:25
Map2DConstrainedEnvironment::GoalTest
virtual bool GoalTest(const xytLoc &node, const xytLoc &goal) const
Definition: Map2DConstrainedEnvironment.cpp:137
constraint
Definition: Map2DConstrainedEnvironment.h:23
Map2DConstrainedEnvironment::HCost
virtual double HCost(const xytLoc &node1, const xytLoc &node2) const
Heuristic value between two arbitrary nodes.
Definition: Map2DConstrainedEnvironment.cpp:129
MapEnvironment
Definition: Map2DEnvironment.h:133
Map2DConstrainedEnvironment::InvertAction
virtual bool InvertAction(tDirection &a) const
Definition: Map2DConstrainedEnvironment.cpp:122
loc
Definition: MapGenerators.cpp:296
operator<<
static std::ostream & operator<<(std::ostream &out, const xytLoc &loc)
Definition: Map2DConstrainedEnvironment.h:28
Map2DConstrainedEnvironment::GetAction
virtual tDirection GetAction(const xytLoc &s1, const xytLoc &s2) const
Definition: Map2DConstrainedEnvironment.cpp:104
xytLoc::xytLoc
xytLoc()
Definition: Map2DConstrainedEnvironment.h:18
operator==
bool operator==(const xytLoc &l1, const xytLoc &l2)
Definition: Map2DConstrainedEnvironment.cpp:14
Map2DConstrainedEnvironment::GCost
virtual double GCost(const xytLoc &node1, const xytLoc &node2) const
Definition: Map2DConstrainedEnvironment.h:56
tDirection
tDirection
Definition: Map2DEnvironment.h:77
xytLoc::l
xyLoc l
Definition: Map2DConstrainedEnvironment.h:19
Map2DConstrainedEnvironment::GetActionHash
virtual uint64_t GetActionHash(tDirection act) const
Definition: Map2DConstrainedEnvironment.cpp:154
xytLoc
Definition: Map2DConstrainedEnvironment.h:16
Map2DConstrainedEnvironment::constraints
std::vector< constraint > constraints
Definition: Map2DConstrainedEnvironment.h:70
Map2DConstrainedEnvironment
Definition: Map2DConstrainedEnvironment.h:37
xytLoc::xytLoc
xytLoc(xyLoc loc, int time)
Definition: Map2DConstrainedEnvironment.h:17
Map2DConstrainedEnvironment::GetActions
virtual void GetActions(const xytLoc &nodeID, std::vector< tDirection > &actions) const
Definition: Map2DConstrainedEnvironment.cpp:97
Map2DConstrainedEnvironment::mapEnv
MapEnvironment * mapEnv
Definition: Map2DConstrainedEnvironment.h:71
Map2DConstrainedEnvironment::OpenGLDraw
virtual void OpenGLDraw() const
Definition: Map2DConstrainedEnvironment.cpp:160
SearchEnvironment
Definition: SearchEnvironment.h:30
Map2DConstrainedEnvironment::Map2DConstrainedEnvironment
Map2DConstrainedEnvironment(Map *m)
Definition: Map2DConstrainedEnvironment.cpp:19
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
Map
A tile-based representation of the world.
Definition: Map.h:142
constraint::dir
tDirection dir
Definition: Map2DConstrainedEnvironment.h:25
Map2DConstrainedEnvironment::GetSuccessors
virtual void GetSuccessors(const xytLoc &nodeID, std::vector< xytLoc > &neighbors) const
Definition: Map2DConstrainedEnvironment.cpp:48