Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends
Gridworld Class Reference

#include <gridworld.hh>

List of all members.

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 > > &parallel, Random &rng)

Private Member Functions

bool isClear (unsigned i, unsigned j, std::vector< std::vector< bool > > &parallel, 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)

Detailed Description

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.


Constructor & Destructor Documentation

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.

Parameters:
heightHeight of the gridworld.
widthWidth of the gridworld.
northsouthWhether each interior wall blocking NS movement exists, organized first by [w] columns and then by [h-1] rows.
eastwestWhether 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.


Member Function Documentation

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.

Parameters:
iAn index into parallel.
jAn index into parallel[i].
parallelOccupancy matrix for walls parallel to the wall under consiration.
perpendicularOccupancy 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.

Parameters:
nsCoordThe coordinate along the NS direction.
ewCoordThe coordinate along the EW direction.
dirThe 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.


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const Gridworld g 
) [friend]

Definition at line 4 of file gridworld.cc.


Member Data Documentation

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.


The documentation for this class was generated from the following files:


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