-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolver.h
More file actions
59 lines (46 loc) · 1.59 KB
/
Copy pathSolver.h
File metadata and controls
59 lines (46 loc) · 1.59 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
58
59
#ifndef SOLVER_H
#define SOLVER_H
#include <vector>
#include <string>
#include <utility>
#include <SFML/System/Time.hpp>
#include "Maze.h"
class Solver {
public:
// This enum is used for all solvers to track their state
enum class State {
SEARCHING,
TRACING_PATH,
DONE
};
Solver(const Maze& maze, char marker);
virtual ~Solver() = default;
// Makes all algorithms use their own step() function
virtual void step() = 0;
bool isFinished() const {
// It's finished when its state is DONE
return currentState == State::DONE;
}
bool wasPathFound() const { return found; }
std::vector<std::string> getGrid() const { return grid; }
int getNodesExplored() const { return m_nodesExplored; }
int getPathLength() const { return m_pathLength; }
sf::Time getTimeTaken() const { return m_timeTaken; }
bool isPathFound() const { return found; }
protected:
char symbol; // The character to draw
State currentState; // The current state of the solver
bool found; // Did we find the exit?
// Maze grid and path data
std::vector<std::string> grid;
std::pair<int, int> start;
std::pair<int, int> goal;
std::pair<int, int> tracePos; // For tracing the path back
// Path reconstruction
std::vector<std::vector<std::pair<int, int>>> parent;
// All algorithms (BFS, A*, etc.) must update these
int m_nodesExplored = 0;
int m_pathLength = 0;
sf::Time m_timeTaken = sf::Time::Zero;
};
#endif // SOLVER_H