/usr/include/libcoyotl/maze.h is in libcoyotl-dev 3.1.0-6ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | //---------------------------------------------------------------------
// Algorithmic Conjurings @ http://www.coyotegulch.com
//
// maze.h (libcoyotl)
//
// Maze generation and exploration tools
//-----------------------------------------------------------------------
//
// Copyright 1990-2005 Scott Robert Ladd
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the
// Free Software Foundation, Inc.
// 59 Temple Place - Suite 330
// Boston, MA 02111-1307, USA.
//
//-----------------------------------------------------------------------
//
// For more information on this software package, please visit
// Scott's web site, Coyote Gulch Productions, at:
//
// http://www.coyotegulch.com
//
//-----------------------------------------------------------------------
#if !defined(LIBCOYOTL_MAZE_H)
#define LIBCOYOTL_MAZE_H
#include <string>
#include <iostream>
#include <cstddef>
namespace libcoyotl
{
//! Defines the data structure of a maze
/*!
A maze object contains the definition of a rectangular maze, including
dimensions, wall placement, and entrance and exit locations. The maze
class does not include intrinsic support for rendering images or
genetic algorithms; instead, it contains a generated set of
tables used by algorithms implementing those features. As such, the
class implements a variety of interrogation functions meant to provide
read-only access to internal data.
*/
class maze
{
public:
//! The state of a wall
enum wall
{
WALL_OPEN, //!> Wall is open
WALL_CLOSED, //!> Wall is closed
WALL_SOLID //!> Walls is solid and can never be open (outside boundary)
};
//! Wall identifiers for the four cardinal directions
enum direction
{
DIR_NORTH, //!> North (up)
DIR_EAST, //!> East (right)
DIR_SOUTH, //!> South (down)
DIR_WEST //!> West (left)
};
//! A row-column position in the maze
/*!
A simple structure defining a row-column coordinate in a maze.
*/
struct position
{
//! Row coordinate
size_t m_row;
//! Column coordinate
size_t m_col;
};
//! A cell in a 2D maze grid
/*!
Each cell knows the state of its four walls. A cell references its
walls by pointer; that way, two adjoining cells share the same pointer
to the wall that they share.
*/
struct cell
{
//! Pointers to four walls, indexed by <i>wall</i> values.
wall * m_walls[4];
//! Constructor
/*!
Creates a new cell. The wall references are initially NULL (they
do not point to any walls).
*/
cell();
//! Copy constructor
/*!
Creates a new cell with the same state as an existing one.
\param a_source - The object to be copied.
*/
cell(const cell & a_source);
//! Assignment operator
/*!
Assigns the state of one cell to another.
\param a_source - The object to be copied.
\return A reference to the target object.
*/
cell & operator = (const cell & a_source);
//! Destructor
/*!
Destroys an existing cell; does nothing in this class, but
might be required for a derived cell type.
*/
virtual ~cell();
};
//! Pluggable object to randomize a maze
/*!
Since several different algorithms can carve mazes with different
characteristics, <i>architect</i> implements a polymorphic
class, thus divorcing the carving algorithm from the data it
generates. The abstract architect class is tightly bound to the
maze data structures, and I defined it within the scope of <i>maze</i>,
as a friend; it implements protected static methods that access the
internal data of a maze.
*/
class architect
{
public:
//! Creates a floor plan for a maze
/*!
This method "draws" in the given <i>maze</i> object, creating
the floor plan.
\param a_target - The <i>maze</i> that will be "architected".
*/
virtual void create_floor_plan(maze & a_target) = 0;
protected:
//! Get cell map for a maze
/*!
Retrieves the two-dimensional maze containing the cells for a maze.
This function provides direct read-write access to the cell data.
\param a_target - The target maze
\return A two-dimensional pointer to the cell grid
*/
static cell ** get_cells(maze & a_target)
{
return a_target.m_cells;
}
};
private:
//! This is a friend so derived types can access maze elements
friend class architect;
public:
//! Constructor
/*!
Creates a new maze with the specified dimensions and a floor plan
defined by the given architect.
\param a_width - Width, in cells, of the new maze
\param a_height - Height, in cells, of the new maze
\param a_architect - Architect to design a floorplan
\return A new <i>maze</i> object
*/
static maze generate(size_t a_width, size_t a_height, architect & a_architect);
//! A "named constructor" to load a maze from an istream
/*!
Loads a maze from a binary file created using <i>maze::save</i>.
\param a_source - Input stream containing the binary maze
\return A new <i>maze</i> object
*/
static maze load(std::istream & a_source);
//! Copy constructor
/*!
Creates a new maze with a state matching an existing maze.
\param a_source - Source object
*/
maze(const maze & a_source);
//! Assignment operator
/*!
Sets the state of a new maze to match the state of an existing maze.
\param a_source - Source object
*/
maze & operator = (const maze & a_source);
//! Destructor
/*!
Destroys a maze objet and releases all of its resources.
*/
virtual ~maze();
//! Store a maze to a stream
/*!
Saves a maze to an output stream in binary format. This stream
can later be used to reconstitute the maze via the <i>load</i>
named constructor.
\param a_receiver - Output stream to hold the binary maze object
*/
void save(std::ostream & a_receiver);
//! Return the width of the maze
/*!
Returns the width of a maze.
\return Width of the maze
*/
size_t get_width() const
{
return m_width;
}
//! Return the height of the maze
/*!
Returns the height of a maze.
\return Height of the maze
*/
size_t get_height() const
{
return m_height;
}
//! Get the entrance cell position
/*!
Returns the position of the entrance cell for a maze.
\return Coordinates of the entrance cell of the maze
*/
position get_entrance_cell_position() const
{
return m_entrance;
}
//! Get the exit cell position
/*!
Returns the position of the exit cell for a maze.
\return Coordinates of the exit cell of the maze
*/
position get_exit_cell_position() const
{
return m_exit;
}
//! Get cell data
/*!
Returns data for a specific cell in a maze.
\param a_col - Column of the requested cell
\param a_row - Row of the requested cell
\return Cell data
*/
cell get_cell(size_t a_col, size_t a_row) const;
protected:
//! Constructor without an architect (for use by load)
/*!
This constructor sets parameters, and then calls <i>construct</i>
to allocate memory and assign default walls.
\param a_width - Width, in cells, of the new maze
\param a_height - Height, in cells, of the new maze
\sa maze::generate
*/
maze(size_t a_width, size_t a_height);
//! Allocates memory and sets intial values for a maze
/*!
This constructor creates the raw maze, with all walls solid or closed.
It is used by the named constructor <i>generate</i>
*/
void construct();
//! Utility method to delete all data buffers
/*!
Releases resources allocated to a maze.
*/
void release();
//! Deep copy utility
/*!
Performs a deep copy of one maze to another.
\param a_source - Source object
*/
void deep_copy(const maze & a_source);
//! Utility method to read a maze
/*!
Read a maze's data from a binary stream.
\param a_source - Input stream containing the binary maze
*/
void read(std::istream & a_source);
protected:
//! Width of the maze in cells
size_t m_width;
//! Height of the maze in cells
size_t m_height;
//! Position of the entrance cell
position m_entrance;
//! Position of the exit cell
position m_exit;
//! The cell data
cell ** m_cells;
};
} // end namespace
#endif
|