HOG2
SFBDPancakePuzzle.h
Go to the documentation of this file.
1 /*
2  * SFBDPancakePuzzle.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 1/14/10.
6  * Copyright 2010 NS Software. All rights reserved.
7  *
8  */
9 
10 #ifndef SFBDPANCAKEPUZZLE_H
11 #define SFBDPANCAKEPUZZLE_H
12 
13 #include "PancakePuzzle.h"
14 #include "BurnedPancakePuzzle.h"
15 
17 public:
19  {
20  }
22  :start(s), goal(g)
23  { }
26 };
27 
29 public:
31  pancakeMovePair(uint16_t act, bool start):theAction(act), applyToStart(start) {}
32  uint16_t theAction;
34 };
35 
36 static std::ostream& operator <<(std::ostream & out, const pancakeStatePair &loc)
37 {
38  out << "[" << loc.start << ", " << loc.goal << "]";
39  return out;
40 }
41 
42 static bool operator==(const pancakeMovePair &l1, const pancakeMovePair &l2)
43 {
44  return (l1.theAction == l2.theAction)&&(l1.applyToStart==l2.applyToStart);
45 }
46 
47 static bool operator==(const pancakeStatePair &l1, const pancakeStatePair &l2)
48 {
49  return (l1.start == l2.start)&&(l1.goal==l2.goal);
50 }
51 
52 
53 class SFBDPancakeEnvironment : public SearchEnvironment<pancakeStatePair, pancakeMovePair> {
54 public:
55  SFBDPancakeEnvironment(int theSize);
56  virtual ~SFBDPancakeEnvironment();
57  virtual void GetSuccessors(const pancakeStatePair &stateID, std::vector<pancakeStatePair> &neighbors) const;
58  virtual void GetActions(const pancakeStatePair &stateID, std::vector<pancakeMovePair> &actions) const;
59  virtual pancakeMovePair GetAction(const pancakeStatePair &s1, const pancakeStatePair &s2) const;
60  virtual void ApplyAction(pancakeStatePair &s, pancakeMovePair a) const;
61  virtual bool InvertAction(pancakeMovePair &a) const;
62 // void SetUseBidirectional(bool use) { swap = use; }
63 
65  virtual double HCost(const pancakeStatePair &state1, const pancakeStatePair &state2) const;
66  virtual double GCost(const pancakeStatePair &state1, const pancakeStatePair &state2) const;
67  virtual double GCost(const pancakeStatePair &state1, const pancakeMovePair &state2) const;
68  virtual bool GoalTest(const pancakeStatePair &state, const pancakeStatePair &goal) const;
69  virtual uint64_t GetStateHash(const pancakeStatePair &state) const;
70  virtual uint64_t GetActionHash(pancakeMovePair act) const;
71  virtual void OpenGLDraw() const;
72  virtual void OpenGLDraw(const pancakeStatePair &s) const;
73  virtual void OpenGLDraw(const pancakeStatePair &s, const pancakeMovePair &gm) const;
74  virtual void OpenGLDraw(const pancakeStatePair &s, const pancakeStatePair&, float) const { OpenGLDraw(s); }
75 
76  virtual void StoreGoal(pancakeStatePair &) {}
77  virtual void ClearGoal() {}
78  virtual bool IsGoalStored() const {return false;}
79 
80  virtual double HCost(const pancakeStatePair &) const {
81  fprintf(stderr, "ERROR: Single State HCost not implemented for SFBDPancakeEnvironment\n");
82  exit(1); return -1.0;}
83 
84  virtual bool GoalTest(const pancakeStatePair &) const {
85  fprintf(stderr, "ERROR: Single State Goal Test not implemented for SFBDPancakeEnvironment\n");
86  exit(1); return false;
87  }
88 
89 protected:
92 };
93 
94 
95 #endif
SFBDPancakeEnvironment::OpenGLDraw
virtual void OpenGLDraw() const
Definition: SFBDPancakePuzzle.cpp:188
SFBDPancakeEnvironment::ClearGoal
virtual void ClearGoal()
Clears the goal from memory.
Definition: SFBDPancakePuzzle.h:77
pancakeStatePair::pancakeStatePair
pancakeStatePair()
Definition: SFBDPancakePuzzle.h:18
pancakeMovePair::pancakeMovePair
pancakeMovePair()
Definition: SFBDPancakePuzzle.h:30
SFBDPancakeEnvironment::SFBDPancakeEnvironment
SFBDPancakeEnvironment(int theSize)
Definition: SFBDPancakePuzzle.cpp:12
SFBDPancakeEnvironment::IsGoalStored
virtual bool IsGoalStored() const
Definition: SFBDPancakePuzzle.h:78
SFBDPancakeEnvironment::GetActionHash
virtual uint64_t GetActionHash(pancakeMovePair act) const
Definition: SFBDPancakePuzzle.cpp:183
SFBDPancakeEnvironment::GetActions
virtual void GetActions(const pancakeStatePair &stateID, std::vector< pancakeMovePair > &actions) const
Definition: SFBDPancakePuzzle.cpp:27
PancakePuzzle.h
SFBDPancakeEnvironment::HCost
virtual double HCost(const pancakeStatePair &state1, const pancakeStatePair &state2) const
Heuristic value between two arbitrary nodes.
Definition: SFBDPancakePuzzle.cpp:158
operator==
static bool operator==(const pancakeMovePair &l1, const pancakeMovePair &l2)
Definition: SFBDPancakePuzzle.h:42
SFBDPancakeEnvironment::GCost
virtual double GCost(const pancakeStatePair &state1, const pancakeStatePair &state2) const
Definition: SFBDPancakePuzzle.cpp:168
SFBDPancakeEnvironment::OpenGLDraw
virtual void OpenGLDraw(const pancakeStatePair &s, const pancakeStatePair &, float) const
Draw the transition at some percentage 0...1 between two states.
Definition: SFBDPancakePuzzle.h:74
loc
Definition: MapGenerators.cpp:296
SFBDPancakeEnvironment::MeasureLocalHeuristic
int MeasureLocalHeuristic(const BurnedPancakePuzzleState &a, const BurnedPancakePuzzleState &b) const
Definition: SFBDPancakePuzzle.cpp:50
SFBDPancakeEnvironment::GetStateHash
virtual uint64_t GetStateHash(const pancakeStatePair &state) const
Definition: SFBDPancakePuzzle.cpp:178
pancakeStatePair::goal
BurnedPancakePuzzleState goal
Definition: SFBDPancakePuzzle.h:25
SFBDPancakeEnvironment::GoalTest
virtual bool GoalTest(const pancakeStatePair &state, const pancakeStatePair &goal) const
Definition: SFBDPancakePuzzle.cpp:173
BurnedPancakePuzzle.h
BurnedPancakePuzzleState
Definition: BurnedPancakePuzzle.h:9
SFBDPancakeEnvironment::GetOccupancyInfo
OccupancyInterface< pancakeStatePair, pancakeMovePair > * GetOccupancyInfo()
Definition: SFBDPancakePuzzle.h:64
SFBDPancakeEnvironment::GoalTest
virtual bool GoalTest(const pancakeStatePair &) const
Goal Test if the goal is stored.
Definition: SFBDPancakePuzzle.h:84
SFBDPancakeEnvironment::ApplyAction
virtual void ApplyAction(pancakeStatePair &s, pancakeMovePair a) const
Definition: SFBDPancakePuzzle.cpp:145
pancakeMovePair::applyToStart
bool applyToStart
Definition: SFBDPancakePuzzle.h:33
pancakeStatePair::start
BurnedPancakePuzzleState start
Definition: SFBDPancakePuzzle.h:24
pancakeStatePair
Definition: SFBDPancakePuzzle.h:16
pancakeMovePair::pancakeMovePair
pancakeMovePair(uint16_t act, bool start)
Definition: SFBDPancakePuzzle.h:31
pancakeMovePair
Definition: SFBDPancakePuzzle.h:28
SFBDPancakeEnvironment::GetSuccessors
virtual void GetSuccessors(const pancakeStatePair &stateID, std::vector< pancakeStatePair > &neighbors) const
Definition: SFBDPancakePuzzle.cpp:22
operator<<
static std::ostream & operator<<(std::ostream &out, const pancakeStatePair &loc)
Definition: SFBDPancakePuzzle.h:36
SFBDPancakeEnvironment::GetAction
virtual pancakeMovePair GetAction(const pancakeStatePair &s1, const pancakeStatePair &s2) const
Definition: SFBDPancakePuzzle.cpp:139
BurnedPancakePuzzle
Definition: BurnedPancakePuzzle.h:41
SFBDPancakeEnvironment::~SFBDPancakeEnvironment
virtual ~SFBDPancakeEnvironment()
Definition: SFBDPancakePuzzle.cpp:17
SFBDPancakeEnvironment::HCost
virtual double HCost(const pancakeStatePair &) const
Heuristic value between node and the stored goal.
Definition: SFBDPancakePuzzle.h:80
pancakeStatePair::pancakeStatePair
pancakeStatePair(BurnedPancakePuzzleState s, BurnedPancakePuzzleState g)
Definition: SFBDPancakePuzzle.h:21
pancakeMovePair::theAction
uint16_t theAction
Definition: SFBDPancakePuzzle.h:32
SFBDPancakeEnvironment::pan
BurnedPancakePuzzle * pan
Definition: SFBDPancakePuzzle.h:91
SearchEnvironment
Definition: SearchEnvironment.h:30
SFBDPancakeEnvironment::StoreGoal
virtual void StoreGoal(pancakeStatePair &)
Stores the goal for use by single-state HCost.
Definition: SFBDPancakePuzzle.h:76
SFBDPancakeEnvironment
Definition: SFBDPancakePuzzle.h:53
OccupancyInterface
Definition: OccupancyInterface.h:36
SFBDPancakeEnvironment::InvertAction
virtual bool InvertAction(pancakeMovePair &a) const
Definition: SFBDPancakePuzzle.cpp:153