1 /***********************************************************************
2  *
3  * Copyright (C) 2009 Graeme Gott <graeme@gottcode.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  ***********************************************************************/
19 
20 #ifndef PATH_H
21 #define PATH_H
22 
23 #include <QList>
24 #include <QPoint>
25 #include <QVector>
26 class Cell;
27 class Maze;
28 
29 class Path
30 {
31 public:
32 	Path(Maze* maze, const QPoint& start, const QPoint& end);
33 
end()34 	QPoint end() const
35 		{ return m_end; }
36 
37 	QPoint hint(const QPoint& cell) const;
38 
39 	int length(const QPoint& start) const;
40 
41 private:
42 	void findNextCell(QPoint& pos);
43 	bool leftWall(const QPoint& pos) const;
44 	bool rightWall(const QPoint& pos) const;
45 	bool topWall(const QPoint& pos) const;
46 	bool bottomWall(const QPoint& pos) const;
cellWalls(const QPoint & pos)47 	int cellWalls(const QPoint& pos) const
48 		{ return leftWall(pos) + rightWall(pos) + topWall(pos) + bottomWall(pos); }
49 
50 	Maze* m_maze;
51 	QPoint m_start;
52 	QPoint m_end;
53 	QVector< QVector<bool> > m_cells;
54 	QList<QPoint> m_solution;
55 };
56 
57 #endif // PATH_H
58