Maze Builder Docs 6.0.1
Loading...
Searching...
No Matches
distances.h
Go to the documentation of this file.
1#ifndef DISTANCES_H
2#define DISTANCES_H
3
4#include <unordered_map>
5#include <vector>
6#include <algorithm>
7#include <memory>
8
9namespace mazes {
10
11class cell;
12
17class distances : public std::enable_shared_from_this<distances> {
18public:
21 explicit distances(std::shared_ptr<cell> root);
22
26 int& operator[](const std::shared_ptr<cell>& cell) noexcept {
27 return m_cells[cell];
28 }
29
33 const int& operator[](const std::shared_ptr<cell>& cell) const noexcept {
34 return m_cells.at(cell);
35 }
36
39 void set(std::shared_ptr<cell> cell, int distance) noexcept;
40
43 bool contains(const std::shared_ptr<cell>& cell) const noexcept;
44
46 std::shared_ptr<distances> path_to(std::shared_ptr<cell> goal) const noexcept;
47
49 std::pair<std::shared_ptr<cell>, int> max() const noexcept;
50
53 void collect_keys(std::vector<std::shared_ptr<cell>>& cells) const noexcept;
54
57 std::shared_ptr<distances> dist() const noexcept;
58private:
59 std::shared_ptr<cell> m_root;
60 std::unordered_map<std::shared_ptr<cell>, int> m_cells;
61};
62
63} // namespace mazes
64#endif // DISTANCES_H
Cell class for maze generation.
Definition cell.h:14
Distances utility class for counting paths and nodes.
Definition distances.h:17
std::shared_ptr< distances > dist() const noexcept
Returns a shared pointer to a distances object.
std::shared_ptr< distances > path_to(std::shared_ptr< cell > goal) const noexcept
Computes the shortest path to a goal cell within a distances object.
std::pair< std::shared_ptr< cell >, int > max() const noexcept
Computes the maximum distance and cell in a distances object.
bool contains(const std::shared_ptr< cell > &cell) const noexcept
Checks if a given cell is contained in the distances object.
void collect_keys(std::vector< std::shared_ptr< cell > > &cells) const noexcept
Collects keys from a vector of shared pointers to cell objects.
distances(std::shared_ptr< cell > root)
Constructor that initializes the distances object with a given root cell.
const int & operator[](const std::shared_ptr< cell > &cell) const noexcept
Accesses the value associated with a given cell in a shared pointer.
Definition distances.h:33
void set(std::shared_ptr< cell > cell, int distance) noexcept
Sets the distance of a cell in the distances object.
int & operator[](const std::shared_ptr< cell > &cell) noexcept
Overloaded operator to access the distance of a cell.
Definition distances.h:26
Namespace for the maze builder.
Definition algo_interface.h:9