INF2004-Project v0.1
 
Loading...
Searching...
No Matches
maze.h
Go to the documentation of this file.
1
12#ifndef MAZE_H // Include guard.
13#define MAZE_H
14#include <stdint.h>
15#include <stdbool.h>
16
17// Definitions.
18// ----------------------------------------------------------------------------
19//
20
26#define MAZE_INVERT_BITMASK(x) ((0xFu - x) & 0xFu)
27
28// Type definitions.
29// ----------------------------------------------------------------------------
30//
31
36typedef struct maze_point
37{
38 uint16_t x;
39 uint16_t y;
41
46typedef enum
47{
52 MAZE_NONE = 255
54
62typedef enum
63{
70
76typedef enum
77{
83
90typedef struct maze_grid_cell
91{
93 uint32_t f;
94 uint32_t g;
96 uint32_t h;
101 struct maze_grid_cell
106
112typedef struct maze_grid
113{
116 uint16_t rows;
117 uint16_t columns;
119
124{
132
136typedef struct maze_gap_bitmask
137{
138 uint16_t *p_bitmask;
140 uint16_t rows;
141 uint16_t columns;
143
148{
149 struct
150 {
151 uint8_t cell_b : 4;
152 uint8_t cell_a : 4;
154 uint8_t bits;
156
157// Public Functions.
158// ----------------------------------------------------------------------------
159//
160
161maze_grid_t maze_create(uint16_t rows, uint16_t columns);
162
164
166
167void maze_destroy(maze_grid_t *p_grid);
168
169int8_t maze_get_nav_dir_offset(const maze_navigator_state_t *p_navigator);
170
172 maze_navigator_state_t *p_navigator,
173 uint8_t aligned_wall_bitmask,
174 bool is_set,
175 bool is_unset);
176
177char *maze_get_string(maze_grid_t *p_grid);
178
179void maze_insert_nav_str(const maze_grid_t *p_grid,
180 const maze_navigator_state_t *p_navigator,
181 char *maze_str);
182
184 const maze_point_t *p_point_b);
185
186int16_t maze_deserialise(maze_grid_t *p_grid,
187 maze_gap_bitmask_t *p_no_walls_array);
188
190
192 const maze_point_t *p_coordinates);
193
195 maze_grid_cell_t *p_from,
196 maze_cardinal_direction_t direction);
197
198uint32_t maze_manhattan_dist(const maze_point_t *p_point_a,
199 const maze_point_t *p_point_b);
200
201int16_t maze_serialised_to_buffer(const maze_gap_bitmask_t *p_bitmask,
202 uint8_t *p_buffer,
203 uint16_t buffer_size);
204
205int16_t maze_nav_to_buffer(const maze_navigator_state_t *p_navigator,
206 uint8_t *p_buffer,
207 uint16_t buffer_size);
208
209void maze_uint16_to_uint8_buffer(uint16_t value, uint8_t *p_buffer);
210
212 const maze_cardinal_direction_t direction_from,
213 const maze_cardinal_direction_t direction_to);
214
215#endif // MAZE_H
216
217// End of pathfinding/maze.h
struct maze_navigator_state maze_navigator_state_t
This struct contains the state of a navigator in the maze.
struct maze_grid_cell maze_grid_cell_t
This struct contains the node information.
maze_grid_cell_t * maze_get_cell_at_coords(maze_grid_t *p_grid, const maze_point_t *p_coordinates)
Get the cell at the specified coordinates.
Definition: maze.c:470
int16_t maze_deserialise(maze_grid_t *p_grid, maze_gap_bitmask_t *p_no_walls_array)
Deserialises the maze from a bitmask array. maze_serialise.
Definition: maze.c:361
struct maze_grid maze_grid_t
This struct contains the maze grid information.
maze_grid_cell_t * maze_get_cell_in_dir(maze_grid_t *p_grid, maze_grid_cell_t *p_from, maze_cardinal_direction_t direction)
Get the cell in the specified direction from a specific cell.
Definition: maze.c:501
maze_gap_bitmask_t maze_serialise(maze_grid_t *p_grid)
Serialises the maze into a bitmask array. maze_deserialise.
Definition: maze.c:422
int16_t maze_nav_to_buffer(const maze_navigator_state_t *p_navigator, uint8_t *p_buffer, uint16_t buffer_size)
Serialises the navigator state into a uint8_t buffer. The buffer is set with the navigator's coordina...
Definition: maze.c:674
union maze_bitmask_compressed maze_bitmask_compressed_t
Used for sending the maze over serial or WiFi.
void maze_uint16_to_uint8_buffer(uint16_t value, uint8_t *p_buffer)
Helper function to convert a uint16_t to a uint8_t buffer.
Definition: maze.c:721
maze_relative_direction_t maze_get_relative_dir(const maze_cardinal_direction_t direction_from, const maze_cardinal_direction_t direction_to)
Gets the relative direction from the current direction to the desired cardinal direction.
Definition: maze.c:549
struct maze_gap_bitmask maze_gap_bitmask_t
This struct contains the maze gap bitmasks for serialisation.
uint32_t maze_manhattan_dist(const maze_point_t *p_point_a, const maze_point_t *p_point_b)
Calculates the manhattan distance between two points.
Definition: maze.c:532
int16_t maze_serialised_to_buffer(const maze_gap_bitmask_t *p_bitmask, uint8_t *p_buffer, uint16_t buffer_size)
Serialises the maze into a uint8_t buffer.
Definition: maze.c:621
maze_grid_t maze_create(uint16_t rows, uint16_t columns)
Create a maze with the specified number of rows and columns.
Definition: maze.c:56
maze_cardinal_direction_t maze_get_dir_from_to(const maze_point_t *p_point_a, const maze_point_t *p_point_b)
Get the direction from p_point_a to p_point_b if they are adjacent.
Definition: maze.c:316
void maze_nav_modify_walls(maze_grid_t *p_grid, maze_navigator_state_t *p_navigator, uint8_t aligned_wall_bitmask, bool is_set, bool is_unset)
Modifies the walls of the navigator's current node.
Definition: maze.c:168
maze_cardinal_direction_t
This enum contains the possible directions.
Definition: maze.h:47
@ MAZE_SOUTH
South is the bottom of the maze.
Definition: maze.h:50
@ MAZE_EAST
East is the right of the maze.
Definition: maze.h:49
@ MAZE_WEST
West is the left of the maze.
Definition: maze.h:51
@ MAZE_NORTH
North is the top of the maze.
Definition: maze.h:48
@ MAZE_NONE
None is used for errors.
Definition: maze.h:52
void maze_insert_nav_str(const maze_grid_t *p_grid, const maze_navigator_state_t *p_navigator, char *maze_str)
Inserts the navigator character into the maze string for pretty printing.
Definition: maze.c:273
int8_t maze_get_nav_dir_offset(const maze_navigator_state_t *p_navigator)
Get the offset from the navigator's current direction to any other possible direction.
Definition: maze.c:148
void maze_destroy(maze_grid_t *p_grid)
Destroys the maze by freeing the memory allocated to the grid array.
Definition: maze.c:125
void maze_clear_heuristics(maze_grid_t *p_grid)
Clears the maze heuristics. This sets the F, G, and H values of each node to UINT32_MAX for the A* an...
Definition: maze.c:103
maze_wall_direction_t
This enum contains bitmasks for the walls. Useful when updating more than one wall at a time.
Definition: maze.h:63
@ MAZE_NO_WALLS
No walls.
Definition: maze.h:64
@ MAZE_BACK_WALL
Back wall.
Definition: maze.h:67
@ MAZE_RIGHT_WALL
Right wall.
Definition: maze.h:66
@ MAZE_LEFT_WALL
Left wall.
Definition: maze.h:68
@ MAZE_FRONT_WALL
Front wall.
Definition: maze.h:65
struct maze_point maze_point_t
This struct contains the coordinates of a point.
void maze_initialise_empty_walled(maze_grid_t *p_grid)
Initialises an empty maze. This sets the coordinates of each node, all heuristic values to 0,...
Definition: maze.c:74
char * maze_get_string(maze_grid_t *p_grid)
Get the string representation of the maze for pretty printing.
Definition: maze.c:213
maze_relative_direction_t
This enum contains the relative directions of instructions from the navigator's perspective.
Definition: maze.h:77
@ MAZE_LEFT
Left of the navigator.
Definition: maze.h:81
@ MAZE_BACK
Back of the navigator.
Definition: maze.h:80
@ MAZE_RIGHT
Right of the navigator.
Definition: maze.h:79
@ MAZE_FRONT
Front is the direction the navigator is facing.
Definition: maze.h:78
This struct contains the maze gap bitmasks for serialisation.
Definition: maze.h:137
uint16_t * p_bitmask
Definition: maze.h:138
uint16_t rows
Number of rows.
Definition: maze.h:140
uint16_t columns
Number of columns.
Definition: maze.h:141
This struct contains the node information.
Definition: maze.h:91
maze_point_t coordinates
X and Y coordinates of the node.
Definition: maze.h:92
uint32_t g
Definition: maze.h:94
struct maze_grid_cell * p_next[4]
Definition: maze.h:99
uint32_t h
Definition: maze.h:96
struct maze_grid_cell * p_came_from
Definition: maze.h:101
bool is_visited
Indicates if the node has been visited before.
Definition: maze.h:104
uint32_t f
F-value of the node. F = G + H.
Definition: maze.h:93
This struct contains the maze grid information.
Definition: maze.h:113
maze_grid_cell_t * p_grid_array
Definition: maze.h:114
uint16_t rows
Number of rows in the grid.
Definition: maze.h:116
uint16_t columns
Number of columns in the grid.
Definition: maze.h:117
This struct contains the state of a navigator in the maze.
Definition: maze.h:124
maze_grid_cell_t * p_start_node
Pointer to the start node of the maze.
Definition: maze.h:127
maze_grid_cell_t * p_current_node
Definition: maze.h:125
maze_grid_cell_t * p_end_node
Pointer to the end node of the maze.
Definition: maze.h:128
maze_cardinal_direction_t orientation
Definition: maze.h:129
This struct contains the coordinates of a point.
Definition: maze.h:37
uint16_t x
X-coordinate or column.
Definition: maze.h:38
uint16_t y
Y-coordinate or row.
Definition: maze.h:39
Used for sending the maze over serial or WiFi.
Definition: maze.h:148
uint8_t bits
Combined bitmasks.
Definition: maze.h:154
uint8_t cell_b
Cell B bitmask (LSB).
Definition: maze.h:151
struct maze_bitmask_compressed::@0 fields
Bit masks for each cell.
uint8_t cell_a
Cell A bitmask (MSB).
Definition: maze.h:152