-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaze.h
102 lines (76 loc) · 2.4 KB
/
maze.h
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
#ifndef MAZE_H_
#define MAZE_H_
#include <memory>
#define MAZESIZE 16
#include "mouse.h"
class Mouse;
class Maze
{
private:
// Maze is represented as set of cells/node. Each node can be
// 4-connected with its neighbors. The last 4 bits of the char
// value store its LRUD connectivity as 0b0000LRUD.
std::unique_ptr<char[]> walls;
// helper method to set wall bit masks
void setBits(char& node, const char& wallMask);
char getBits(char const& node, const char& wallMask) const;
// Same convention as outlined here
// https://github.com/micromouseonline/micromouse_maze_tool
const char leftWallMask = 0x08 ;
const char rightWallMask = 0x02 ;
const char upWallMask = 0x01 ;
const char downWallMask = 0x04 ;
protected:
int size;
public:
/**
Return a reference to the node at (x,y).
The nodes are arranged in row-major order from bottom-left node
which is the origin at (0,0), X-axis points right, Y axis
points up.
\param x: x position >
\param y: y position of cell ^
\returns char indicating wall bits
*/
char& at(int x, int y) const;
void setLeftWall(int x, int y);
char getLeftWall(int x, int y) const;
void setRightWall(int x, int y);
char getRightWall(int x, int y) const;
void setUpWall(int x, int y);
char getUpWall(int x, int y) const;
void setDownWall(int x, int y);
char getDownWall(int x, int y) const;
bool isWall(char const& maskedNode) const;
bool isRightWall(int x, int y) const;
bool isLeftWall(int x, int y) const;
bool isUpWall(int x, int y) const;
bool isDownWall(int x, int y) const;
void makeBoundaryWalls(void);
void randomizeWalls(void);
void fromMazeFile(std::string const& mazeFileName);
// To be removed
std::string drawCell(int x, int y);
void draw(bool drawMouse = true);
/// Return the number of cells along one dimension
int getSize(void) const {return size;};
// Constructors
Maze(int _size);
Maze(const Maze& other);
};
class FloodMaze : public Maze
{
public:
FloodMaze(int _size);
FloodMaze(const FloodMaze& other);
FloodMaze(const Maze& other);
void setXGoal(int x) {xGoal = x;};
void setYGoal(int y) {yGoal = y;};
int& operator()(int x, int y);
void flood();
void clear();
private:
std::unique_ptr<int[]> floodVal;
int xGoal, yGoal;
};
#endif