#include <gridworld.hh>
Public Member Functions | |
Gridworld (unsigned height, unsigned width, const std::vector< std::vector< bool > > &northsouth, const std::vector< std::vector< bool > > &eastwest) | |
Gridworld (unsigned width, unsigned height, Random &rng) | |
unsigned | height () const |
bool | wall (unsigned nsCoord, unsigned ewCoord, unsigned dir) const |
unsigned | width () const |
Protected Member Functions | |
void | add_obstacle (Random &rng) |
void | chooseSegment (unsigned first, unsigned last, unsigned j, std::vector< std::vector< bool > > ¶llel, Random &rng) |
Private Member Functions | |
bool | isClear (unsigned i, unsigned j, std::vector< std::vector< bool > > ¶llel, std::vector< std::vector< bool > > &perpendicular) const |
Private Attributes | |
std::vector< std::vector< bool > > | ew |
const unsigned | h |
std::vector< std::vector< bool > > | ns |
const unsigned | w |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Gridworld &g) |
A representation of a rectangular grid with interior walls that allows users easily to determine available directions of travel in each cell.
Definition at line 15 of file gridworld.hh.
Gridworld::Gridworld | ( | unsigned | height, |
unsigned | width, | ||
const std::vector< std::vector< bool > > & | northsouth, | ||
const std::vector< std::vector< bool > > & | eastwest | ||
) |
Creates a gridworld using the given wall occupancy matrices.
height | Height of the gridworld. |
width | Width of the gridworld. |
northsouth | Whether each interior wall blocking NS movement exists, organized first by [w] columns and then by [h-1] rows. |
eastwest | Whether each interior wall blocking EW movement exists, organized first by [h] rows and then by [w-1] columns. |
Definition at line 32 of file gridworld.cc.
Gridworld::Gridworld | ( | unsigned | width, |
unsigned | height, | ||
Random & | rng | ||
) |
Creates a random gridworld with the desired dimensions.
Definition at line 38 of file gridworld.cc.
void Gridworld::add_obstacle | ( | Random & | rng | ) | [protected] |
Attempts to add a random wall that must not touch any other interior wall.
Definition at line 64 of file gridworld.cc.
void Gridworld::chooseSegment | ( | unsigned | first, |
unsigned | last, | ||
unsigned | j, | ||
std::vector< std::vector< bool > > & | parallel, | ||
Random & | rng | ||
) | [protected] |
Given a segment of wall that could be built, builds a subset of it of random length. Always builds from one of the two ends.
Definition at line 82 of file gridworld.cc.
unsigned Gridworld::height | ( | ) | const [inline] |
Definition at line 33 of file gridworld.hh.
bool Gridworld::isClear | ( | unsigned | i, |
unsigned | j, | ||
std::vector< std::vector< bool > > & | parallel, | ||
std::vector< std::vector< bool > > & | perpendicular | ||
) | const [inline, private] |
Determines if the "smaller" endpoint of the given line segment is clear: none of the four possible walls using that endpoint exist.
i | An index into parallel. |
j | An index into parallel[i]. |
parallel | Occupancy matrix for walls parallel to the wall under consiration. |
perpendicular | Occupancy matrix for walls perpendicular to the wall under consiration. |
Definition at line 69 of file gridworld.hh.
bool Gridworld::wall | ( | unsigned | nsCoord, |
unsigned | ewCoord, | ||
unsigned | dir | ||
) | const |
Checks if a wall blocks movement in a given direction from a given coordinate.
nsCoord | The coordinate along the NS direction. |
ewCoord | The coordinate along the EW direction. |
dir | The direction in which to check movement. 0 is north, 1 is south, 2 is east, 3 is west. |
Definition at line 48 of file gridworld.cc.
unsigned Gridworld::width | ( | ) | const [inline] |
Definition at line 34 of file gridworld.hh.
std::ostream& operator<< | ( | std::ostream & | out, |
const Gridworld & | g | ||
) | [friend] |
Definition at line 4 of file gridworld.cc.
std::vector<std::vector<bool> > Gridworld::ew [private] |
The same as for ns but different.
Definition at line 99 of file gridworld.hh.
const unsigned Gridworld::h [private] |
Definition at line 90 of file gridworld.hh.
std::vector<std::vector<bool> > Gridworld::ns [private] |
The occupancy matrix for the walls that obstruct NS movement. Element i,j is true if in the ith column the jth east-west wall from the bottom is present.
Definition at line 96 of file gridworld.hh.
const unsigned Gridworld::w [private] |
Definition at line 91 of file gridworld.hh.