Maze Builder Docs 6.0.1
Loading...
Searching...
No Matches
grid.h
Go to the documentation of this file.
1#ifndef GRID_H
2#define GRID_H
3
4#include <functional>
5#include <future>
6#include <mutex>
7#include <memory>
8#include <optional>
9#include <string>
10#include <utility>
11#include <vector>
12#include <unordered_map>
13
15
16namespace mazes {
17
21class grid : public grid_interface {
22protected:
23
26 void build_fut(std::vector<int> const& indices) noexcept;
27
30 void configure_cells(std::vector<std::shared_ptr<cell>>& cells) const noexcept;
31
32 mutable std::promise<bool> m_config_promise;
33 std::mutex m_cells_mutex;
34 std::unordered_map<int, std::shared_ptr<cell>> m_cells;
35
36public:
38 friend class binary_tree;
39 friend class dfs;
40 friend class sidewinder;
41
46 explicit grid(unsigned int rows = 1u, unsigned int columns = 1u, unsigned int height = 1u);
47
50 explicit grid(std::tuple<unsigned int, unsigned int, unsigned int> dimensions);
51
54 grid(const grid& other);
55
59 grid& operator=(const grid& other);
60
63 grid(grid&& other) noexcept;
64
68 grid& operator=(grid&& other) noexcept;
69
71 virtual ~grid();
72
76 virtual std::future<bool> get_future() noexcept;
77
78 // Overrides
79
82 virtual std::tuple<unsigned int, unsigned int, unsigned int> get_dimensions() const noexcept override;
83
86 virtual void to_vec(std::vector<std::shared_ptr<cell>>& cells) const noexcept override;
87
90 virtual void to_vec2(std::vector<std::vector<std::shared_ptr<cell>>>& cells) const noexcept override;
91
95 virtual std::optional<std::string> contents_of(const std::shared_ptr<cell>& c) const noexcept override;
96
100 virtual std::optional<std::uint32_t> background_color_for(const std::shared_ptr<cell>& c) const noexcept override;
101
105 std::shared_ptr<cell> search(int index) const noexcept;
106
109 int count() const noexcept;
110
111private:
112 // Calculate the flat index from row and column
113 std::function<int(unsigned int, unsigned int)> m_calc_index;
114
115 std::tuple<unsigned int, unsigned int, unsigned int> m_dimensions;
116}; // class
117
118} // namespace mazes
119
120#endif // GRID_H
Binary tree algorithm for generating mazes.
Definition binary_tree.h:18
Cell class for maze generation.
Definition cell.h:14
Depth-first search algorithm for generating mazes.
Definition dfs.h:19
Interface for the grid class.
Definition grid_interface.h:26
General purpose grid class for maze generation.
Definition grid.h:21
grid(const grid &other)
Copy constructor.
virtual std::tuple< unsigned int, unsigned int, unsigned int > get_dimensions() const noexcept override
Provides dimensions of grid in no assumed ordering.
virtual void to_vec(std::vector< std::shared_ptr< cell > > &cells) const noexcept override
Convert a 2D grid to a vector of cells (sorted by row then column)
void build_fut(std::vector< int > const &indices) noexcept
Builds a future based on the provided indices.
int count() const noexcept
Get the count of cells in the grid.
virtual std::future< bool > get_future() noexcept
Initialize and configure.
grid & operator=(const grid &other)
Assignment operator.
grid & operator=(grid &&other) noexcept
Move assignment operator.
virtual std::optional< std::string > contents_of(const std::shared_ptr< cell > &c) const noexcept override
Get detailed information of a cell in the grid.
grid(unsigned int rows=1u, unsigned int columns=1u, unsigned int height=1u)
Constructor for grid.
virtual std::optional< std::uint32_t > background_color_for(const std::shared_ptr< cell > &c) const noexcept override
Get the background color for a cell in the grid.
void configure_cells(std::vector< std::shared_ptr< cell > > &cells) const noexcept
Configure cells by neighbors (N, S, E, W)
virtual ~grid()
Destructor.
grid(grid &&other) noexcept
Move constructor.
grid(std::tuple< unsigned int, unsigned int, unsigned int > dimensions)
Constructor for grid.
virtual void to_vec2(std::vector< std::vector< std::shared_ptr< cell > > > &cells) const noexcept override
Convert a 2D grid to a vector of vectors of cells (sorted by row then column)
std::shared_ptr< cell > search(int index) const noexcept
Sidewinder algorithm for generating mazes.
Definition sidewinder.h:17
Namespace for the maze builder.
Definition algo_interface.h:9