gridworld.hh
Go to the documentation of this file.
00001 #ifndef _GRIDWORLD_H_
00002 #define _GRIDWORLD_H_
00003 
00004 #include <rl_common/Random.h>
00005 
00006 #include <iostream>
00007 #include <vector>
00008 
00015 class Gridworld {
00016 public:
00026   Gridworld(unsigned height, unsigned width,
00027             const std::vector<std::vector<bool> > &northsouth,
00028             const std::vector<std::vector<bool> > &eastwest);
00029 
00031   Gridworld(unsigned width, unsigned height, Random &rng);
00032 
00033   unsigned height() const { return h; }
00034   unsigned width() const { return w; }
00035 
00042   bool wall(unsigned nsCoord, unsigned ewCoord, unsigned dir) const;
00043 
00044   friend std::ostream &operator<<(std::ostream &out, const Gridworld &g);
00045 
00046 protected:
00049   void add_obstacle(Random &rng);
00050 
00053   void chooseSegment(unsigned first,
00054                      unsigned last,
00055                      unsigned j,
00056                      std::vector<std::vector<bool> > &parallel,
00057                      Random &rng);
00058 
00059 private:
00069   bool isClear(unsigned i, unsigned j,
00070                std::vector<std::vector<bool> > &parallel,
00071                std::vector<std::vector<bool> > &perpendicular) const
00072   {
00073     if (i > parallel.size())
00074       return false;
00075     if (i < parallel.size() && parallel[i][j])
00076       return false;
00077     if (i > 0 && parallel[i - 1][j])
00078       return false;
00079     if (i > 0
00080         && i <= perpendicular[j].size()
00081         && perpendicular[j][i - 1])
00082       return false;
00083     if (i > 0
00084         && i <= perpendicular[j + 1].size()
00085         && perpendicular[j + 1][i - 1])
00086       return false;
00087     return true;
00088   }
00089 
00090   const unsigned h;
00091   const unsigned w;
00092 
00096   std::vector<std::vector<bool> > ns;
00097 
00099   std::vector<std::vector<bool> > ew;
00100 };
00101 
00102 #endif


rl_env
Author(s):
autogenerated on Thu Jun 6 2019 22:00:24