-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmazebinary.h
More file actions
57 lines (44 loc) · 1.89 KB
/
mazebinary.h
File metadata and controls
57 lines (44 loc) · 1.89 KB
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
#ifndef MAZES_FOR_PROGRAMMERS_MAZEBINARY_H
#define MAZES_FOR_PROGRAMMERS_MAZEBINARY_H
#include "maze.h"
class MazeBinary : public Maze {
public:
std::string getName() {
return "Binary";
}
private:
/**
* A dimensionally agnostic binary maze algorithm with a bias towards the positive axis
*/
void generateAlgorithm() {
std::vector<std::string> axis = this->getAllAxis();
while (this->getUnvisitedNodeCount() > 0) {
Node *workingNode = this->getRandomUnvisitedNode();
Point workingPoint = workingNode->getPoint();
std::vector<Node *> potentialNodes;
std::vector<Node *> neighbourNodes = this->getNeighbourNodes(workingNode);
for (auto neighbourNode : neighbourNodes) {
for (auto axisIdentifier : axis) {
Point neighbour = neighbourNode->getPoint();
int axisValue = neighbour.getPositionOnAxis(axisIdentifier);
int workingNodeAxisValue = workingPoint.getPositionOnAxis(axisIdentifier);
//This greater than or less than size will define the bias of the maze
//> == to the top right
//< == to the bottom left
if (axisValue > workingNodeAxisValue) {
if (this->nodeExistsAtPoint(neighbour)) {
potentialNodes.push_back(neighbourNode);
}
}
}
}
if (potentialNodes.size() >= 1) {
unsigned long r = (unsigned long) this->getRandomNumber(0, (int) potentialNodes.size() - 1);
Node *chosenNode = potentialNodes.at(r);
this->linkNodes(workingNode, chosenNode);
}
this->markNodeAsVisited(workingNode);
}
}
};
#endif //MAZES_FOR_PROGRAMMERS_MAZEBINARY_H