-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGreedyBestFirst_Solver.h
More file actions
39 lines (30 loc) · 1.03 KB
/
Copy pathGreedyBestFirst_Solver.h
File metadata and controls
39 lines (30 loc) · 1.03 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
#ifndef GREEDY_BEST_FIRST_SOLVER_H
#define GREEDY_BEST_FIRST_SOLVER_H
#include "Solver.h"
#include "Utils.h"
#include <queue>
#include <vector>
#include <utility>
#include <cmath>
#include <SFML/System/Clock.hpp>
// Greedy Best-First Search (GBFS)
// Only follows the heuristic (h-score), ignores path cost (g-score)
// Very fast, but not guaranteed to find the shortest path.
class GreedyBestFirst_Solver : public Solver {
public:
explicit GreedyBestFirst_Solver(const Maze& maze);
void step() override;
private:
using Node = std::pair<int, int>; // Grid coordinate
struct NodeData {
int h; // Heuristic score
Node pos;
bool operator>(const NodeData& other) const { return h > other.h; }
};
std::priority_queue<NodeData, std::vector<NodeData>, std::greater<NodeData>> openSet;
std::vector<std::vector<bool>> visited; // No gScore needed, just visited
int heuristic(int r, int c) const;
// Clock for timing the algorithm
sf::Clock m_clock;
};
#endif // GREEDY_BEST_FIRST_SOLVER_H