HOG2
SteeringEnvironment.h
Go to the documentation of this file.
1 /*
2  * SteeringEnvironment.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 4/12/11.
6  * Copyright 2011 University of Denver. All rights reserved.
7  *
8  */
9 
10 #ifndef STEERINGENVIRONMENT_H
11 #define STEERINGENVIRONMENT_H
12 
13 #include "SearchEnvironment.h"
14 #include "UnitSimulation.h"
15 #include "FPUtil.h"
16 
17 struct steeringState {
18 public:
19  float x, y;
20  float v;
21  float heading;
22 };
23 
24 static bool operator==(const steeringState &l1, const steeringState &l2)
25 {
26  return ((fequal(l1.x, l2.x)) &&
27  (fequal(l1.y, l2.y)) &&
28  (fequal(l1.v, l2.v)) &&
29  (fequal(l1.heading, l2.heading)));
30 }
31 
32 //struct steeringAction {
33 //public:
34 // steeringAction(float xVel=0.0f, float yVel=0.0f, float hVel=0.0f) :dx(xVel), dy(yVel), dh(hVel) {}
35 // float dx, dy, dh;
36 //};
37 // state
38 
40 public:
41  steeringAction(float d_v=0.0f, float d_h=0.0f) :dv(d_v), dh(d_h) {}
42  float dv, dh;
43 };
44 
45 extern float maxSpeed;
46 extern float worldRadius;
47 
48 class SteeringEnvironment : public SearchEnvironment<steeringState, steeringAction>
49 {
50 public:
52  virtual void GetSuccessors(const steeringState &nodeID, std::vector<steeringState> &neighbors) const;
53  virtual void GetActions(const steeringState &nodeID, std::vector<steeringAction> &actions) const;
54  //virtual int GetNumSuccessors(const steeringState &stateID) const;
55  virtual steeringAction GetAction(const steeringState &s1, const steeringState &s2) const;
56  virtual void ApplyAction(steeringState &s, steeringAction a) const;
57 
58  virtual void GetNextState(const steeringState &, steeringAction , steeringState &) const;
59 
60  virtual bool InvertAction(steeringAction &a) const;
61 
63  virtual double HCost(const steeringState &node1, const steeringState &node2) const;
64 
67  virtual double HCost(const steeringState &node) const
68  { assert(bValidSearchGoal); return HCost(node, searchGoal); }
69 
70  virtual double GCost(const steeringState &node1, const steeringState &node2) const;
71  virtual double GCost(const steeringState &node, const steeringAction &act) const;
72  virtual bool GoalTest(const steeringState &node, const steeringState &goal) const;
73 
75  virtual bool GoalTest(const steeringState &node) const
76  { return bValidSearchGoal&&(node == searchGoal); }
77 
78  virtual uint64_t GetStateHash(const steeringState &node) const;
79  virtual uint64_t GetActionHash(steeringAction act) const;
80 
81  //virtual double GetPathLength(std::vector<steeringState> &neighbors);
82 
83  virtual void OpenGLDraw() const;
84  virtual void OpenGLDraw(const steeringState&) const;
86  virtual void OpenGLDraw(const steeringState&, const steeringState&, float) const;
87  virtual void OpenGLDraw(const steeringState&, const steeringAction&) const;
88 private:
89 };
90 
92 
93 #endif
SteeringEnvironment::OpenGLDraw
virtual void OpenGLDraw() const
Definition: SteeringEnvironment.cpp:113
SteeringEnvironment::GCost
virtual double GCost(const steeringState &node1, const steeringState &node2) const
Definition: SteeringEnvironment.cpp:98
steeringAction
Definition: SteeringEnvironment.h:39
UnitSimulation.h
steeringState
Definition: SteeringEnvironment.h:17
worldRadius
float worldRadius
Definition: SteeringEnvironment.cpp:13
SteeringEnvironment::GetAction
virtual steeringAction GetAction(const steeringState &s1, const steeringState &s2) const
Definition: SteeringEnvironment.cpp:41
SteeringEnvironment::GetActions
virtual void GetActions(const steeringState &nodeID, std::vector< steeringAction > &actions) const
Definition: SteeringEnvironment.cpp:27
SteeringEnvironment::GetNextState
virtual void GetNextState(const steeringState &, steeringAction, steeringState &) const
Definition: SteeringEnvironment.cpp:85
SteeringEnvironment::GoalTest
virtual bool GoalTest(const steeringState &node) const
Goal Test if the goal is stored.
Definition: SteeringEnvironment.h:75
FPUtil.h
SteeringEnvironment
Definition: SteeringEnvironment.h:48
SteeringEnvironment::InvertAction
virtual bool InvertAction(steeringAction &a) const
Definition: SteeringEnvironment.cpp:91
SteeringEnvironment::HCost
virtual double HCost(const steeringState &node) const
Heuristic value between node and the stored goal.
Definition: SteeringEnvironment.h:67
steeringState::v
float v
Definition: SteeringEnvironment.h:20
steeringState::heading
float heading
Definition: SteeringEnvironment.h:21
SearchEnvironment< steeringState, steeringAction >::searchGoal
steeringState searchGoal
Definition: SearchEnvironment.h:113
SteeringEnvironment::GetSuccessors
virtual void GetSuccessors(const steeringState &nodeID, std::vector< steeringState > &neighbors) const
Definition: SteeringEnvironment.cpp:15
SearchEnvironment< steeringState, steeringAction >::bValidSearchGoal
bool bValidSearchGoal
Definition: SearchEnvironment.h:112
steeringAction::dh
float dh
Definition: SteeringEnvironment.h:42
steeringState::y
float y
Definition: SteeringEnvironment.h:19
SteeringEnvironment::GetActionHash
virtual uint64_t GetActionHash(steeringAction act) const
Definition: SteeringEnvironment.cpp:109
steeringAction::steeringAction
steeringAction(float d_v=0.0f, float d_h=0.0f)
Definition: SteeringEnvironment.h:41
UnitSteeringSimulation
UnitSimulation< steeringState, steeringAction, SteeringEnvironment > UnitSteeringSimulation
Definition: SteeringEnvironment.h:91
SteeringEnvironment::GoalTest
virtual bool GoalTest(const steeringState &node, const steeringState &goal) const
Definition: SteeringEnvironment.cpp:102
SteeringEnvironment::HCost
virtual double HCost(const steeringState &node1, const steeringState &node2) const
Heuristic value between two arbitrary nodes.
Definition: SteeringEnvironment.cpp:95
SteeringEnvironment::SteeringEnvironment
SteeringEnvironment()
Definition: SteeringEnvironment.h:51
UnitSimulation
The basic simulation class for the world.
Definition: UnitSimulation.h:85
steeringState::x
float x
Definition: SteeringEnvironment.h:19
maxSpeed
float maxSpeed
Definition: SteeringEnvironment.cpp:12
SteeringEnvironment::ApplyAction
virtual void ApplyAction(steeringState &s, steeringAction a) const
Definition: SteeringEnvironment.cpp:47
fequal
bool fequal(double a, double b, double tolerance=TOLERANCE)
Definition: FPUtil.h:32
SearchEnvironment
Definition: SearchEnvironment.h:30
SteeringEnvironment::GetStateHash
virtual uint64_t GetStateHash(const steeringState &node) const
Definition: SteeringEnvironment.cpp:106
steeringAction::dv
float dv
Definition: SteeringEnvironment.h:42
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h
operator==
static bool operator==(const steeringState &l1, const steeringState &l2)
Definition: SteeringEnvironment.h:24