HOG2
Airplane.h
Go to the documentation of this file.
1 //
2 // Airplane.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 5/4/16.
6 // Copyright © 2016 University of Denver. All rights reserved.
7 //
8 
9 #ifndef Airplane_h
10 #define Airplane_h
11 
12 #include <vector>
13 #include <cassert>
14 #include "SearchEnvironment.h"
15 
16 // turn type:
17 // 45, 90, 0, shift
18 // speed:
19 // faster, slower
20 // height:
21 // up / down
22 
23 const uint8_t k45 = 1;
24 const uint8_t k90 = 2;
25 const uint8_t kShift = 3;
26 
28 public:
29  airplaneAction(int8_t t=0, int8_t s=0, int8_t h=0)
30  :turn(t), speed(s), height(h) {}
31  int8_t turn;
32  int8_t speed;
33  int8_t height;
34 };
35 
36 // state
37 struct airplaneState {
38 public:
39  airplaneState() { x = y = heading = 0; speed = 1; height = 20; }
40  uint8_t x;
41  uint8_t y;
42  uint8_t height;
43  int speed : 2;
44  int heading : 6;
45 };
46 
47 bool operator==(const airplaneState &s1, const airplaneState &s2);
48 
49 //class GoalTester {
50 //public:
51 // virtual ~GoalTester() {}
52 // virtual bool goalTest(const airplaneState &i1) const = 0;
53 //};
54 
55 class AirplaneEnvironment : public SearchEnvironment<airplaneState, airplaneAction>
56 {
57 public:
59  void GetSuccessors(const airplaneState &nodeID, std::vector<airplaneState> &neighbors) const;
60  void GetActions(const airplaneState &nodeID, std::vector<airplaneAction> &actions) const;
61  virtual void ApplyAction(airplaneState &s, airplaneAction dir) const;
62  virtual void UndoAction(airplaneState &s, airplaneAction dir) const;
63  virtual void GetNextState(const airplaneState &currents, airplaneAction dir, airplaneState &news) const;
64 
66  virtual bool InvertAction(airplaneAction &a) const { return false; }
67 
68  virtual double HCost(const airplaneState &node1, const airplaneState &node2) const;
69  virtual double HCost(const airplaneState &) const { assert(false); return 0; }
70  virtual double GCost(const airplaneState &node1, const airplaneState &node2) const;
71  virtual double GCost(const airplaneState &node1, const airplaneAction &act) const;
72 
73 // void SetGoalTest(GoalTester *t) {test = t;}
74  bool GoalTest(const airplaneState &node, const airplaneState &goal) const;
75  bool GoalTest(const airplaneState &) const { assert(false); return false; }
76  uint64_t GetStateHash(const airplaneState &node) const;
77  uint64_t GetActionHash(airplaneAction act) const;
78  virtual void OpenGLDraw() const;
79  virtual void OpenGLDraw(const airplaneState &l) const;
80  virtual void OpenGLDraw(const airplaneState& oldState, const airplaneState &newState, float perc) const;
81  virtual void OpenGLDraw(const airplaneState &, const airplaneAction &) const;
82  void GLDrawLine(const airplaneState &a, const airplaneState &b) const;
83  recVec GetCoordinate(int x, int y, int z) const;
84 private:
85  void SetGround(int x, int y, uint8_t val);
86  uint8_t GetGround(int x, int y) const;
87  bool Valid(int x, int y);
88  recVec &GetNormal(int x, int y);
89  recVec GetNormal(int x, int y) const;
90  void RecurseGround(int x1, int y1, int x2, int y2);
91  const int width = 80;
92  const int length = 80;
93  const int height = 20;
94  std::vector<uint8_t> ground;
95  std::vector<recVec> groundNormals;
96  void DoNormal(recVec pa, recVec pb) const;
97  mutable std::vector<airplaneAction> internalActions;
98 };
99 
100 #endif /* Airplane_h */
AirplaneEnvironment::Valid
bool Valid(int x, int y)
Definition: Airplane.cpp:169
AirplaneEnvironment::DoNormal
void DoNormal(recVec pa, recVec pb) const
AirplaneEnvironment
Definition: Airplane.h:55
AirplaneEnvironment::GoalTest
bool GoalTest(const airplaneState &node, const airplaneState &goal) const
Definition: Airplane.cpp:309
AirplaneEnvironment::GLDrawLine
void GLDrawLine(const airplaneState &a, const airplaneState &b) const
Definition: Airplane.cpp:431
recVec
A generic vector (essentially the same as a point, but offers normalization)
Definition: GLUtil.h:78
AirplaneEnvironment::AirplaneEnvironment
AirplaneEnvironment()
Definition: Airplane.cpp:18
AirplaneEnvironment::RecurseGround
void RecurseGround(int x1, int y1, int x2, int y2)
Definition: Airplane.cpp:185
AirplaneEnvironment::GoalTest
bool GoalTest(const airplaneState &) const
Goal Test if the goal is stored.
Definition: Airplane.h:75
airplaneAction::turn
int8_t turn
Definition: Airplane.h:31
AirplaneEnvironment::GetNormal
recVec & GetNormal(int x, int y)
Definition: Airplane.cpp:175
AirplaneEnvironment::height
const int height
Definition: Airplane.h:93
airplaneAction
Definition: Airplane.h:27
k45
const uint8_t k45
Definition: Airplane.h:23
AirplaneEnvironment::GetStateHash
uint64_t GetStateHash(const airplaneState &node) const
Definition: Airplane.cpp:314
AirplaneEnvironment::ApplyAction
virtual void ApplyAction(airplaneState &s, airplaneAction dir) const
Definition: Airplane.cpp:239
AirplaneEnvironment::internalActions
std::vector< airplaneAction > internalActions
Definition: Airplane.h:97
AirplaneEnvironment::GetSuccessors
void GetSuccessors(const airplaneState &nodeID, std::vector< airplaneState > &neighbors) const
Definition: Airplane.cpp:203
AirplaneEnvironment::GetNextState
virtual void GetNextState(const airplaneState &currents, airplaneAction dir, airplaneState &news) const
Definition: Airplane.cpp:285
airplaneState::y
uint8_t y
Definition: Airplane.h:41
airplaneState::x
uint8_t x
Definition: Airplane.h:40
airplaneState::speed
int speed
Definition: Airplane.h:43
airplaneAction::height
int8_t height
Definition: Airplane.h:33
AirplaneEnvironment::HCost
virtual double HCost(const airplaneState &node1, const airplaneState &node2) const
Heuristic value between two arbitrary nodes.
Definition: Airplane.cpp:293
AirplaneEnvironment::ground
std::vector< uint8_t > ground
Definition: Airplane.h:94
airplaneState::airplaneState
airplaneState()
Definition: Airplane.h:39
AirplaneEnvironment::SetGround
void SetGround(int x, int y, uint8_t val)
Definition: Airplane.cpp:159
AirplaneEnvironment::GetCoordinate
recVec GetCoordinate(int x, int y, int z) const
Definition: Airplane.cpp:324
operator==
bool operator==(const airplaneState &s1, const airplaneState &s2)
Definition: Airplane.cpp:12
airplaneState
Definition: Airplane.h:37
AirplaneEnvironment::UndoAction
virtual void UndoAction(airplaneState &s, airplaneAction dir) const
Definition: Airplane.cpp:279
AirplaneEnvironment::GetOccupancyInfo
virtual OccupancyInterface< airplaneState, airplaneAction > * GetOccupancyInfo()
Definition: Airplane.h:65
AirplaneEnvironment::GetActions
void GetActions(const airplaneState &nodeID, std::vector< airplaneAction > &actions) const
Definition: Airplane.cpp:214
k90
const uint8_t k90
Definition: Airplane.h:24
AirplaneEnvironment::HCost
virtual double HCost(const airplaneState &) const
Heuristic value between node and the stored goal.
Definition: Airplane.h:69
AirplaneEnvironment::GetGround
uint8_t GetGround(int x, int y) const
Definition: Airplane.cpp:164
AirplaneEnvironment::OpenGLDraw
virtual void OpenGLDraw() const
Definition: Airplane.cpp:329
airplaneState::height
uint8_t height
Definition: Airplane.h:42
AirplaneEnvironment::InvertAction
virtual bool InvertAction(airplaneAction &a) const
Definition: Airplane.h:66
AirplaneEnvironment::GetActionHash
uint64_t GetActionHash(airplaneAction act) const
Definition: Airplane.cpp:319
AirplaneEnvironment::GCost
virtual double GCost(const airplaneState &node1, const airplaneState &node2) const
Definition: Airplane.cpp:298
kShift
const uint8_t kShift
Definition: Airplane.h:25
AirplaneEnvironment::length
const int length
Definition: Airplane.h:92
airplaneState::heading
int heading
Definition: Airplane.h:44
airplaneAction::airplaneAction
airplaneAction(int8_t t=0, int8_t s=0, int8_t h=0)
Definition: Airplane.h:29
SearchEnvironment
Definition: SearchEnvironment.h:30
AirplaneEnvironment::width
const int width
Definition: Airplane.h:91
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h
airplaneAction::speed
int8_t speed
Definition: Airplane.h:32
OccupancyInterface
Definition: OccupancyInterface.h:36
AirplaneEnvironment::groundNormals
std::vector< recVec > groundNormals
Definition: Airplane.h:95