libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


maze.h
1//---------------------------------------------------------------------
2// Algorithmic Conjurings @ http://www.coyotegulch.com
3//
4// maze.h (libcoyotl)
5//
6// Maze generation and exploration tools
7//-----------------------------------------------------------------------
8//
9// Copyright 1990-2005 Scott Robert Ladd
10//
11// This program is free software; you can redistribute it and/or modify
12// it under the terms of the GNU General Public License as published by
13// the Free Software Foundation; either version 2 of the License, or
14// (at your option) any later version.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the
23// Free Software Foundation, Inc.
24// 59 Temple Place - Suite 330
25// Boston, MA 02111-1307, USA.
26//
27//-----------------------------------------------------------------------
28//
29// For more information on this software package, please visit
30// Scott's web site, Coyote Gulch Productions, at:
31//
32// http://www.coyotegulch.com
33//
34//-----------------------------------------------------------------------
35
36#if !defined(LIBCOYOTL_MAZE_H)
37#define LIBCOYOTL_MAZE_H
38
39#include <string>
40#include <iostream>
41#include <cstddef>
42
43namespace libcoyotl
44{
46
55 class maze
56 {
57 public:
59 enum wall
60 {
61 WALL_OPEN,
64 };
65
68 {
69 DIR_NORTH,
73 };
74
76
79 struct position
80 {
82 size_t m_row;
83
85 size_t m_col;
86 };
87
89
94 struct cell
95 {
98
100
105
107
112
114
120
122
126 virtual ~cell();
127 };
128
130
140 {
141 public:
143
148 virtual void create_floor_plan(maze & a_target) = 0;
149
150 protected:
152
159 {
160 return a_target.m_cells;
161 }
162 };
163
164 private:
166 friend class architect;
167
168 public:
170
179
181
186 static maze load(std::istream & a_source);
187
189
194
196
201
203
206 virtual ~maze();
207
209
215 void save(std::ostream & a_receiver);
216
218
222 size_t get_width() const
223 {
224 return m_width;
225 }
226
228
232 size_t get_height() const
233 {
234 return m_height;
235 }
236
238
243 {
244 return m_entrance;
245 }
246
248
253 {
254 return m_exit;
255 }
256
258
264 cell get_cell(size_t a_col, size_t a_row) const;
265
266 protected:
268
275 maze(size_t a_width, size_t a_height);
276
278
282 void construct();
283
285
288 void release();
289
291
295 void deep_copy(const maze & a_source);
296
298
302 void read(std::istream & a_source);
303
304 protected:
306 size_t m_width;
307
309 size_t m_height;
310
313
316
319 };
320
321} // end namespace
322
323#endif
A STL-compatible array class.
Definition array.h:73
Defines the data structure of a maze.
Definition maze.h:56
position get_exit_cell_position() const
Get the exit cell position.
Definition maze.h:252
void read(std::istream &a_source)
Utility method to read a maze.
size_t get_width() const
Return the width of the maze.
Definition maze.h:222
position get_entrance_cell_position() const
Get the entrance cell position.
Definition maze.h:242
void deep_copy(const maze &a_source)
Deep copy utility.
direction
Wall identifiers for the four cardinal directions.
Definition maze.h:68
@ DIR_WEST
‍South (down)
Definition maze.h:72
@ DIR_EAST
‍North (up)
Definition maze.h:70
@ DIR_SOUTH
‍East (right)
Definition maze.h:71
maze(size_t a_width, size_t a_height)
Constructor without an architect (for use by load)
maze(const maze &a_source)
Copy constructor.
size_t m_height
Height of the maze in cells.
Definition maze.h:309
static maze generate(size_t a_width, size_t a_height, architect &a_architect)
Constructor.
static maze load(std::istream &a_source)
A "named constructor" to load a maze from an istream.
position m_entrance
Position of the entrance cell.
Definition maze.h:312
void construct()
Allocates memory and sets intial values for a maze.
void save(std::ostream &a_receiver)
Store a maze to a stream.
maze & operator=(const maze &a_source)
Assignment operator.
position m_exit
Position of the exit cell.
Definition maze.h:315
cell ** m_cells
The cell data.
Definition maze.h:318
void release()
Utility method to delete all data buffers.
virtual ~maze()
Destructor.
size_t m_width
Width of the maze in cells.
Definition maze.h:306
size_t get_height() const
Return the height of the maze.
Definition maze.h:232
cell get_cell(size_t a_col, size_t a_row) const
Get cell data.
wall
The state of a wall.
Definition maze.h:60
@ WALL_CLOSED
‍Wall is open
Definition maze.h:62
@ WALL_SOLID
‍Wall is closed
Definition maze.h:63
A row-column position in the maze.
Definition maze.h:80
size_t m_col
Column coordinate.
Definition maze.h:85
size_t m_row
Row coordinate.
Definition maze.h:82
A cell in a 2D maze grid.
Definition maze.h:95
cell(const cell &a_source)
Copy constructor.
cell & operator=(const cell &a_source)
Assignment operator.
wall * m_walls[4]
Pointers to four walls, indexed by wall values.
Definition maze.h:97
virtual ~cell()
Destructor.
cell()
Constructor.
Pluggable object to randomize a maze.
Definition maze.h:140
static cell ** get_cells(maze &a_target)
Get cell map for a maze.
Definition maze.h:158
virtual void create_floor_plan(maze &a_target)=0
Creates a floor plan for a maze.

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.